mirror of
https://git.zhongyuan.online/ytke/tap.git
synced 2026-11-24 22:15:18 -08:00
支持自部署需求管理、交付流程与飞书集成
This commit is contained in:
1 parent
4556a5b483
commit
e22b66d9dd
148 files changed
+8300
-6393
No files matched your search
@@ -0,0 +1,32 @@
|
||||
import { assertSameOrigin, jsonResponse, requireApiUser } from '@/lib/server/auth';
|
||||
import { deleteStagedAttachment, downloadAttachment, attachmentFailure } from '@/lib/server/attachments';
|
||||
|
||||
export const runtime = 'nodejs';
|
||||
export const dynamic = 'force-dynamic';
|
||||
type Context = { params: Promise<{ id: string }> };
|
||||
|
||||
export async function GET(_request: Request, { params }: Context) {
|
||||
try {
|
||||
const user = await requireApiUser();
|
||||
const { id } = await params;
|
||||
const { file, bytes } = downloadAttachment(id, user);
|
||||
const filename = encodeURIComponent(file.name).replace(/[!'()*]/g, char => `%${char.charCodeAt(0).toString(16).toUpperCase()}`);
|
||||
return new Response(new Uint8Array(bytes), { headers: {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
'Content-Disposition': `attachment; filename="attachment"; filename*=UTF-8''${filename}`,
|
||||
'Content-Length': String(file.size),
|
||||
'Cache-Control': 'private, no-store',
|
||||
'X-Content-Type-Options': 'nosniff',
|
||||
'Content-Security-Policy': "sandbox; default-src 'none'",
|
||||
} });
|
||||
} catch (error) { return attachmentFailure(error); }
|
||||
}
|
||||
|
||||
export async function DELETE(request: Request, { params }: Context) {
|
||||
try {
|
||||
const user = await requireApiUser();
|
||||
assertSameOrigin(request);
|
||||
deleteStagedAttachment((await params).id, user.userId);
|
||||
return jsonResponse({ deleted: true });
|
||||
} catch (error) { return attachmentFailure(error); }
|
||||
}
|
||||
Reference in new issue
Block a user