fix(update): 修复云端安装交接并完善发布验收
修复隐藏缓存目录下载和响应收尾,使用原生助手校验安装包并确认交接。 补齐真实静默升级、便携版及中文路径验收,并按现行设备和科目授权契约更新回归。 服务端安装时生成独立密钥,覆盖升级保留既有配置;补齐安装包副本验证说明。
This commit is contained in:
1 parent
66be3a63b1
commit
71cc8eb605
19 files changed
+1424
-91
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { assertClassDevice, assertPermission, classIdsFor } from '../../lib/authz/index.js';
|
||||
import { getReleaseProgress, setReleaseProgress } from './release-progress.js';
|
||||
import { Router } from 'express';
|
||||
import path from 'node:path';
|
||||
import { sendCreated, sendOk, ApiError } from '../../lib/http.js';
|
||||
import {
|
||||
authenticate,
|
||||
@@ -132,7 +133,7 @@ router.delete(
|
||||
router.get(
|
||||
'/client/download/:version',
|
||||
validate({ params: clientReleaseVersionParamSchema }),
|
||||
async (req, res) => {
|
||||
async (req, res, next) => {
|
||||
const user = getAuthUser(req);
|
||||
if (user.role === 'CLASS_DEVICE') assertClassDevice(user, user.classId ?? user.sub);
|
||||
else {
|
||||
@@ -143,12 +144,25 @@ router.get(
|
||||
const { version } = validatedParams<{ version: string }>(req);
|
||||
const found = await clientReleases.resolveReleaseFile(version);
|
||||
if (!found) throw ApiError.notFound('服务端没有缓存这个版本的安装包');
|
||||
res.download(found.file, found.fileName, (error) => {
|
||||
if (error) {
|
||||
// 客户端中途取消下载也会走到这里,只记日志,不要往已发出的响应里再写东西
|
||||
res.locals.downloadError = error instanceof Error ? error.message : String(error);
|
||||
}
|
||||
});
|
||||
res.download(
|
||||
path.basename(found.file),
|
||||
found.fileName,
|
||||
{ root: path.dirname(found.file), dotfiles: 'allow' },
|
||||
(error) => {
|
||||
if (!error || res.destroyed) return;
|
||||
if (res.headersSent) {
|
||||
res.destroy(error);
|
||||
return;
|
||||
}
|
||||
// 文件可能在解析元数据后被移除;尚未发送响应时必须结束请求,不能让客户端一直等待。
|
||||
const code = (error as NodeJS.ErrnoException).code;
|
||||
next(
|
||||
code === 'ENOENT' || code === 'ENOTDIR' || code === 'EISDIR'
|
||||
? ApiError.notFound('安装包文件不存在或无法读取,请重新缓存')
|
||||
: error,
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in new issue
Block a user