feat(server): 统一课表解析并完善权限范围与年度升级
This commit is contained in:
1 parent
66ef878a71
commit
4dc824c283
54 files changed
+2401
-625
No files matched your search
@@ -0,0 +1,27 @@
|
||||
import { SOCKET_EVENTS, SOCKET_ROOMS, type ReleaseProgressDto } from '@classhelper/shared';
|
||||
import { emitToRooms } from '../../realtime/bus.js';
|
||||
|
||||
// 下载状态只属于本次进程;重启回到 idle,不会残留无法完成的 downloading。
|
||||
let progress: ReleaseProgressDto = {
|
||||
version: '',
|
||||
stage: 'idle',
|
||||
downloadedBytes: 0,
|
||||
totalBytes: 0,
|
||||
percent: null,
|
||||
error: '',
|
||||
};
|
||||
let lastEmit = 0;
|
||||
export function getReleaseProgress() {
|
||||
return { ...progress };
|
||||
}
|
||||
export function setReleaseProgress(patch: Partial<ReleaseProgressDto>) {
|
||||
const stageChanged = patch.stage && patch.stage !== progress.stage;
|
||||
progress = { ...progress, ...patch };
|
||||
progress.percent = progress.totalBytes
|
||||
? Math.min(100, Math.round((progress.downloadedBytes / progress.totalBytes) * 100))
|
||||
: null;
|
||||
if (stageChanged || Date.now() - lastEmit >= 250) {
|
||||
emitToRooms([SOCKET_ROOMS.role('ADMIN')], SOCKET_EVENTS.clientReleaseProgress, getReleaseProgress());
|
||||
lastEmit = Date.now();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user