mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-06-22 04:11:32 +10:00
fix: task api and other small issues
This commit is contained in:
@@ -63,7 +63,9 @@ export class ClientHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetchClientMetadataByToken(token: string) {
|
async fetchClientMetadataByToken(token: string) {
|
||||||
return Object.entries(this.temporaryClientTable)
|
return this.temporaryClientTable
|
||||||
|
.entries()
|
||||||
|
.toArray()
|
||||||
.map((e) => Object.assign(e[1], { id: e[0] }))
|
.map((e) => Object.assign(e[1], { id: e[0] }))
|
||||||
.find((e) => e.authToken === token);
|
.find((e) => e.authToken === token);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,8 +57,15 @@ class NotificationSystem {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async push(userId: string, notificationCreateArgs: NotificationCreateArgs) {
|
async push(userId: string, notificationCreateArgs: NotificationCreateArgs) {
|
||||||
const notification = await prisma.notification.create({
|
const notification = await prisma.notification.upsert({
|
||||||
data: {
|
where: {
|
||||||
|
nonce: notificationCreateArgs.nonce!!
|
||||||
|
},
|
||||||
|
update: {
|
||||||
|
userId: userId,
|
||||||
|
...notificationCreateArgs,
|
||||||
|
},
|
||||||
|
create: {
|
||||||
userId: userId,
|
userId: userId,
|
||||||
...notificationCreateArgs,
|
...notificationCreateArgs,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ export class FsObjectBackend extends ObjectBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fetch(id: ObjectReference) {
|
async fetch(id: ObjectReference) {
|
||||||
console.log("ID: " + id);
|
|
||||||
const objectPath = path.join(this.baseObjectPath, id);
|
const objectPath = path.join(this.baseObjectPath, id);
|
||||||
if (!fs.existsSync(objectPath)) return undefined;
|
if (!fs.existsSync(objectPath)) return undefined;
|
||||||
return fs.createReadStream(objectPath);
|
return fs.createReadStream(objectPath);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ class TaskHandler {
|
|||||||
};
|
};
|
||||||
logOffset = taskEntry.log.length;
|
logOffset = taskEntry.log.length;
|
||||||
|
|
||||||
for (const clientId of Object.keys(taskEntry.clients)) {
|
for (const clientId of taskEntry.clients.keys()) {
|
||||||
const client = this.clientRegistry.get(clientId);
|
const client = this.clientRegistry.get(clientId);
|
||||||
if (!client) continue;
|
if (!client) continue;
|
||||||
client.send(JSON.stringify(taskMessage));
|
client.send(JSON.stringify(taskMessage));
|
||||||
@@ -108,7 +108,7 @@ class TaskHandler {
|
|||||||
}
|
}
|
||||||
await updateAllClients();
|
await updateAllClients();
|
||||||
|
|
||||||
for (const clientId of Object.keys(taskEntry.clients)) {
|
for (const clientId of taskEntry.clients.keys()) {
|
||||||
if (!this.clientRegistry.get(clientId)) continue;
|
if (!this.clientRegistry.get(clientId)) continue;
|
||||||
this.disconnect(clientId, task.id);
|
this.disconnect(clientId, task.id);
|
||||||
}
|
}
|
||||||
@@ -160,7 +160,7 @@ class TaskHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
disconnectAll(id: string) {
|
disconnectAll(id: string) {
|
||||||
for (const taskId of Object.keys(this.taskRegistry)) {
|
for (const taskId of this.taskRegistry.keys()) {
|
||||||
this.taskRegistry.get(taskId)?.clients.delete(id);
|
this.taskRegistry.get(taskId)?.clients.delete(id);
|
||||||
this.sendDisconnectEvent(id, taskId);
|
this.sendDisconnectEvent(id, taskId);
|
||||||
}
|
}
|
||||||
@@ -175,8 +175,10 @@ class TaskHandler {
|
|||||||
task.clients.delete(id);
|
task.clients.delete(id);
|
||||||
this.sendDisconnectEvent(id, taskId);
|
this.sendDisconnectEvent(id, taskId);
|
||||||
|
|
||||||
const allClientIds = Object.values(this.taskRegistry)
|
const allClientIds = this.taskRegistry
|
||||||
.map((_) => Object.keys(_.clients))
|
.values()
|
||||||
|
.toArray()
|
||||||
|
.map((e) => e.clients.keys().toArray())
|
||||||
.flat();
|
.flat();
|
||||||
|
|
||||||
if (!allClientIds.includes(id)) {
|
if (!allClientIds.includes(id)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user