feat: 添加download路由用于展示文档信息
All checks were successful
deploy to server / build-and-deploy (push) Successful in 5m4s

- 添加/download/documentID路由用于文档下载
- server端添加文档元数据获取与下载API
- 将app中的types移至shared,与server共享
This commit is contained in:
2025-10-27 17:16:51 +08:00
parent 5ab72111ca
commit 4e7131b291
18 changed files with 276 additions and 0 deletions

View File

@ -0,0 +1,22 @@
import { getFileMeta } from '../../utils/file';
export default defineEventHandler(async (event) => {
const id = getRouterParam(event, 'id');
if (!id) {
throw createError({ statusCode: 400, message: '缺少文件ID' });
}
const file = await getFileMeta(id);
if (!file) {
throw createError({ statusCode: 404, message: '文件不存在' });
}
const res = await $fetch<ArrayBuffer>(file.url, {
responseType: 'arrayBuffer',
});
return new Response(res, {
headers: {
'Content-Disposition': `attachment; filename="${encodeURIComponent(file.filename_download)}"`,
'Content-Type': file.type,
},
});
});