feat: add download micro-app for cli

This commit is contained in:
2025-03-11 11:04:10 +08:00
parent 7b25dbdf08
commit 1c820c3083
8 changed files with 186 additions and 155 deletions

View File

@@ -129,18 +129,27 @@ router.get('/api/micro-app/download/:id', async (req, res) => {
res.end(error('Key parameter is required'));
return;
}
const query = new URL(req.url || '', 'http://localhost');
const notNeedToken = query.searchParams.get('notNeedToken') || '';
const fileTitle = query.searchParams.get('title') || '';
if (res.headersSent) return; // 如果响应已发送,不再处理
let tokenUser;
if (!DEV_SERVER) {
if (!DEV_SERVER && !notNeedToken) {
const auth = await checkAuth(req, res);
tokenUser = auth.tokenUser;
if (!tokenUser) return;
}
const file = await MicroAppUploadModel.findByPk(id);
let file: MicroAppUploadModel | null = null;
if (!DEV_SERVER) {
file.uid !== tokenUser.id && res.end(error('No permission', 403));
return;
// file.uid !== tokenUser.id && res.end(error('No permission', 403));
// return;
}
if (fileTitle) {
file = await MicroAppUploadModel.findOne({
where: { title: fileTitle },
});
} else if (id) {
file = await MicroAppUploadModel.findByPk(id);
}
if (!file) {