Skip to content
GitLab
Explorer
Connexion
Navigation principale
Rechercher ou aller à…
Projet
M
matrix-appservice-discord
Gestion
Activité
Membres
Labels
Programmation
Tickets
Tableaux des tickets
Jalons
Wiki
Wiki externe
Code
Requêtes de fusion
Dépôt
Branches
Validations
Étiquettes
Graphe du dépôt
Comparer les révisions
Extraits de code
Compilation
Pipelines
Jobs
Planifications de pipeline
Artéfacts
Déploiement
Releases
Registre de paquets
Registre de conteneur
Registre de modèles
Opération
Environnements
Modules Terraform
Surveillance
Incidents
Analyse
Données d'analyse des chaînes de valeur
Analyse des contributeurs
Données d'analyse CI/CD
Données d'analyse du dépôt
Expériences du modèle
Aide
Aide
Support
Documentation de GitLab
Comparer les forfaits GitLab
Forum de la communauté
Contribuer à GitLab
Donner votre avis
Raccourcis clavier
?
Extraits de code
Groupes
Projets
Afficher davantage de fils d'Ariane
salixor
matrix-appservice-discord
Validations
7eb377d5
Valider
7eb377d5
rédigé
6 years ago
par
Will Hunt
Parcourir les fichiers
Options
Téléchargements
Correctifs
Plain Diff
Address feedback
parent
883c17b2
Aucune branche associée trouvée
Branches contenant la validation
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Modifications
4
Masquer les modifications d'espaces
En ligne
Côte à côte
Affichage de
4 fichiers modifiés
package.json
+1
-2
1 ajout, 2 suppressions
package.json
src/bot.ts
+3
-0
3 ajouts, 0 suppression
src/bot.ts
src/db/roomstore.ts
+51
-25
51 ajouts, 25 suppressions
src/db/roomstore.ts
src/provisioner.ts
+1
-1
1 ajout, 1 suppression
src/provisioner.ts
avec
56 ajouts
et
28 suppressions
package.json
+
1
−
2
Voir le fichier @
7eb377d5
...
...
@@ -14,8 +14,7 @@
"usertool"
:
"node ./build/tools/userClientTools.js"
,
"directoryfix"
:
"node ./build/tools/addRoomsToDirectory.js"
,
"ghostfix"
:
"node ./build/tools/ghostfix.js"
,
"chanfix"
:
"node ./build/tools/chanfix.js"
,
"moveRoomStore"
:
"node ./build/tools/moveRoomStoreToDb.js"
"chanfix"
:
"node ./build/tools/chanfix.js"
},
"repository"
:
{
"type"
:
"git"
,
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/bot.ts
+
3
−
0
Voir le fichier @
7eb377d5
...
...
@@ -500,6 +500,9 @@ export class DiscordBot {
throw
Error
(
"
Room(s) not found.
"
);
}
const
entry
=
entries
[
0
];
if
(
!
entry
.
remote
)
{
throw
Error
(
"
Room had no remote component
"
);
}
const
guild
=
client
.
guilds
.
get
(
entry
.
remote
!
.
get
(
"
discord_guild
"
)
as
string
);
if
(
guild
)
{
const
channel
=
client
.
channels
.
get
(
entry
.
remote
!
.
get
(
"
discord_channel
"
)
as
string
);
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/db/roomstore.ts
+
51
−
25
Voir le fichier @
7eb377d5
...
...
@@ -19,6 +19,7 @@ import { IDatabaseConnector } from "./connector";
import
*
as
uuid
from
"
uuid/v4
"
;
const
log
=
new
Log
(
"
DbRoomStore
"
);
const
ROOM_ID_REGEX
=
/!
([
A-z
]
|_
)
+:
(\d
|
[
A-z
]
|-|
\.
|
\:)
+/
;
/**
* A RoomStore compatible with
...
...
@@ -122,7 +123,7 @@ export class DbRoomStore {
const
mxIdDifferent
=
matrixId
!==
row
.
matrix_id
;
const
rmIdDifferent
=
remoteId
!==
row
.
remote_id
;
// Did the room ids change?
if
(
row
.
id
&&
(
mxIdDifferent
||
rmIdDifferent
)
)
{
if
(
mxIdDifferent
||
rmIdDifferent
)
{
if
(
matrixId
)
{
this
.
entriesMatrixIdCache
.
delete
(
matrixId
);
}
...
...
@@ -161,18 +162,23 @@ export class DbRoomStore {
);
const
res
:
IRoomStoreEntry
[]
=
[];
for
(
const
entry
of
entries
)
{
const
remoteId
=
entry
.
remote_id
as
string
||
""
;
const
row
=
await
this
.
db
.
Get
(
"
SELECT * FROM remote_room_data WHERE room_id = $rid
"
,
{
rid
:
remoteId
},
);
if
(
!
row
)
{
continue
;
}
let
remote
:
RemoteStoreRoom
|
null
=
null
;
if
(
entry
.
remote_id
)
{
const
remoteId
=
entry
.
remote_id
as
string
;
const
row
=
await
this
.
db
.
Get
(
"
SELECT * FROM remote_room_data WHERE room_id = $remoteId
"
,
{
remoteId
},
);
if
(
row
)
{
// tslint:disable-next-line no-any
remote
=
new
RemoteStoreRoom
(
remoteId
,
row
as
any
);
}
}
res
.
push
({
id
:
(
entry
.
id
as
string
),
matrix
:
matrixId
?
new
MatrixStoreRoom
(
matrixId
)
:
null
,
// tslint:disable-next-line no-any
remote
:
remoteId
?
new
RemoteStoreRoom
(
remoteId
,
row
as
any
)
:
null
,
matrix
:
new
MatrixStoreRoom
(
matrixId
),
remote
,
});
}
if
(
res
.
length
>
0
)
{
...
...
@@ -182,24 +188,38 @@ export class DbRoomStore {
}
public
async
getEntriesByMatrixIds
(
matrixIds
:
string
[]):
Promise
<
IRoomStoreEntry
[]
>
{
// Validate matrixIds to prevent injections.
matrixIds
=
matrixIds
.
filter
((
id
)
=>
{
if
(
!
ROOM_ID_REGEX
.
exec
(
id
))
{
log
.
warn
(
`
${
id
}
was excluded for not looking like a real roomID`
);
return
false
;
}
return
true
;
});
const
entries
=
await
this
.
db
.
All
(
`SELECT * FROM room_entries WHERE matrix_id IN ('
${
matrixIds
.
join
(
"
','
"
)}
')`
,
);
const
res
:
IRoomStoreEntry
[]
=
[];
for
(
const
entry
of
entries
)
{
let
remote
:
RemoteStoreRoom
|
null
=
null
;
const
matrixId
=
entry
.
matrix_id
as
string
||
""
;
const
remoteId
=
entry
.
remote_id
as
string
||
""
;
const
row
=
await
this
.
db
.
Get
(
"
SELECT * FROM remote_room_data WHERE room_id = $rid
"
,
{
rid
:
remoteId
},
);
if
(
!
row
)
{
continue
;
}
const
remoteId
=
entry
.
remote_id
as
string
;
if
(
remoteId
)
{
const
row
=
await
this
.
db
.
Get
(
"
SELECT * FROM remote_room_data WHERE room_id = $rid
"
,
{
rid
:
remoteId
},
);
if
(
row
)
{
// tslint:disable-next-line no-any
remote
=
new
RemoteStoreRoom
(
remoteId
,
row
as
any
);
}
}
res
.
push
({
id
:
(
entry
.
id
as
string
),
matrix
:
matrixId
?
new
MatrixStoreRoom
(
matrixId
)
:
null
,
// tslint:disable-next-line no-any
remote
:
remoteId
?
new
RemoteStoreRoom
(
remoteId
,
row
as
any
)
:
null
,
remote
,
});
}
return
res
;
...
...
@@ -255,20 +275,26 @@ export class DbRoomStore {
}
public
async
removeEntriesByMatrixRoomId
(
matrixId
:
string
)
{
await
this
.
db
.
Run
(
`DELETE FROM room_entries WHERE matrix_id = $matrixId`
,
{
matrixId
});
await
this
.
db
.
Run
(
`DELETE FROM remote_room_data WHERE room_id = $matrixId`
,
{
matrixId
});
const
entries
=
(
await
this
.
db
.
All
(
`SELECT * room_entries WHERE matrix_id = $matrixId`
,
{
matrixId
}))
||
[];
entries
.
map
((
entry
)
=>
{
if
(
entry
.
remote_id
)
{
return
this
.
removeEntriesByRemoteRoomId
(
entry
.
remote_id
as
string
);
}
else
if
(
entry
.
matrix_id
)
{
return
this
.
db
.
Run
(
`DELETE FROM room_entries WHERE matrix_id = $matrixId`
,
{
matrixId
:
entry
.
matrix_id
});
}
});
}
private
async
upsertRoom
(
room
:
RemoteStoreRoom
)
{
if
(
!
room
.
data
)
{
throw
new
Error
(
"
Tried to upsert a room with undefined data
"
);
}
const
existingRow
=
await
this
.
db
.
Get
(
"
SELECT * FROM remote_room_data WHERE room_id = $id
"
,
{
id
:
room
.
roomId
},
);
if
(
!
room
.
data
)
{
throw
new
Error
(
"
Tried to upsert a room with undefined data
"
);
}
const
data
=
{
discord_channel
:
room
.
data
.
discord_channel
,
discord_guild
:
room
.
data
.
discord_guild
,
...
...
@@ -309,7 +335,7 @@ export class DbRoomStore {
return
;
}
const
keysToUpdate
=
{
};
const
keysToUpdate
=
{
}
as
IRemoteRoomDataLazy
;
// New keys
Object
.
keys
(
room
.
data
).
filter
(
...
...
@@ -336,7 +362,7 @@ export class DbRoomStore {
{
id
:
room
.
roomId
,
// tslint:disable-next-line no-any
...
keysToUpdate
,
...
keysToUpdate
as
any
,
});
log
.
verbose
(
"
Upserted room
"
+
room
.
roomId
);
}
catch
(
ex
)
{
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
src/provisioner.ts
+
1
−
1
Voir le fichier @
7eb377d5
...
...
@@ -29,7 +29,7 @@ export class Provisioner {
private
pendingRequests
:
Map
<
string
,
(
approved
:
boolean
)
=>
void
>
=
new
Map
();
// [channelId]: resolver fn
private
roomStore
:
DbRoomStore
;
public
setS
tor
e
(
roomStore
:
DbRoomStore
)
{
construc
tor
(
roomStore
:
DbRoomStore
)
{
this
.
roomStore
=
roomStore
;
}
...
...
Ce diff est replié.
Cliquez pour l'agrandir.
Aperçu
0%
Chargement en cours
Veuillez réessayer
ou
joindre un nouveau fichier
.
Annuler
You are about to add
0
people
to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Enregistrer le commentaire
Annuler
Veuillez vous
inscrire
ou vous
se connecter
pour commenter