server-ts: Port bbranch (with some build errors)

This commit is contained in:
Elian Doran
2024-02-17 02:02:08 +02:00
parent cf18e61a33
commit f51f070b2f
5 changed files with 64 additions and 40 deletions

View File

@@ -1,12 +1,20 @@
"use strict";
const ws = require('./ws.js');
import ws = require('./ws.js');
// taskId => TaskContext
const taskContexts = {};
const taskContexts: Record<string, TaskContext> = {};
class TaskContext {
constructor(taskId, taskType = null, data = {}) {
private taskId: string;
private taskType: string | null;
private data: {} | null;
private noteDeletionHandlerTriggered: boolean;
private progressCount: number;
private lastSentCountTs: number;
constructor(taskId: string, taskType: string | null = null, data: {} | null = {}) {
this.taskId = taskId;
this.taskType = taskType;
this.data = data;
@@ -23,8 +31,7 @@ class TaskContext {
this.increaseProgressCount();
}
/** @returns {TaskContext} */
static getInstance(taskId, taskType, data = null) {
static getInstance(taskId: string, taskType: string, data: {} | null = null): TaskContext {
if (!taskContexts[taskId]) {
taskContexts[taskId] = new TaskContext(taskId, taskType, data);
}
@@ -42,31 +49,31 @@ class TaskContext {
type: 'taskProgressCount',
taskId: this.taskId,
taskType: this.taskType,
data: this.data,
data: this.data || undefined,
progressCount: this.progressCount
});
}
}
reportError(message) {
reportError(message: string) {
ws.sendMessageToAllClients({
type: 'taskError',
taskId: this.taskId,
taskType: this.taskType,
data: this.data,
data: this.data || undefined,
message: message
});
}
taskSucceeded(result) {
taskSucceeded(result: string) {
ws.sendMessageToAllClients({
type: 'taskSucceeded',
taskId: this.taskId,
taskType: this.taskType,
data: this.data,
data: this.data || undefined,
result: result
});
}
}
module.exports = TaskContext;
export = TaskContext;

View File

@@ -28,12 +28,18 @@ let lastSyncedPush: number | null = null;
interface Message {
type: string;
reason?: string;
data?: {
lastSyncedPush?: number,
entityChanges?: any[]
},
lastSyncedPush?: number
lastSyncedPush?: number,
progressCount?: number;
taskId?: string;
taskType?: string | null;
message?: string;
reason?: string;
result?: string;
}
type SessionParser = (req: IncomingMessage, params: {}, cb: () => void) => void;
@@ -252,7 +258,7 @@ function setLastSyncedPush(entityChangeId: number) {
lastSyncedPush = entityChangeId;
}
module.exports = {
export = {
init,
sendMessageToAllClients,
syncPushInProgress,