mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-11-04 08:10:28 +09:00
리다이렉트 경로 처리, 파일 정보 변환, 상태 표시 UI 등 중복된 코드를 통합하고 모듈 간 순환 의존성 및 계층 위반 해소
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9119c21881
commit
5b8621e524
96 files changed
+452
-548
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import { authorize } from "#lib/server/auth.ts";
|
||||
import { handleAppErrors } from "#lib/server/http.ts";
|
||||
import { FileService } from "#lib/server/services/index.ts";
|
||||
import { parseRangeHeader, getContentRangeHeader } from "#lib/shared/http.ts";
|
||||
import type { RequestEvent, RequestHandler } from "./$types";
|
||||
|
||||
const downloadHandler = async ({ locals, params, request }: RequestEvent) => {
|
||||
const { userId } = await authorize(locals, "activeClient");
|
||||
const { id } = params;
|
||||
|
||||
const getStream = params.thumbnail
|
||||
? FileService.getFileThumbnailStream
|
||||
: FileService.getFileStream;
|
||||
const { encContentStream, range, isRangeRequest } = await getStream(
|
||||
userId,
|
||||
id,
|
||||
parseRangeHeader(request.headers.get("Range")),
|
||||
);
|
||||
return {
|
||||
stream: encContentStream,
|
||||
status: isRangeRequest ? 206 : 200,
|
||||
headers: {
|
||||
"Accept-Ranges": "bytes",
|
||||
"Content-Length": String(range.end - range.start + 1),
|
||||
"Content-Type": "application/octet-stream",
|
||||
...(isRangeRequest ? getContentRangeHeader(range) : {}),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export const GET: RequestHandler = handleAppErrors(async (event) => {
|
||||
const { stream, ...init } = await downloadHandler(event);
|
||||
return new Response(stream as ReadableStream, init);
|
||||
});
|
||||
|
||||
export const HEAD: RequestHandler = handleAppErrors(async (event) => {
|
||||
const { stream, ...init } = await downloadHandler(event);
|
||||
await stream.cancel();
|
||||
return new Response(null, init);
|
||||
});
|
||||
Reference in new issue
Block a user