mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-02-04 08:06:56 +00:00
업로드된 청크 목록을 비트맵을 활용해 효율적으로 저장하도록 개선
This commit is contained in:
@@ -8,6 +8,12 @@ import { safeRecursiveRm, safeUnlink } from "$lib/server/modules/filesystem";
|
||||
|
||||
const chunkLocks = new Set<string>();
|
||||
|
||||
const isChunkUploaded = (bitmap: Buffer, chunkIndex: number) => {
|
||||
chunkIndex -= 1;
|
||||
const byte = bitmap[Math.floor(chunkIndex / 8)];
|
||||
return !!byte && (byte & (1 << (chunkIndex % 8))) !== 0; // Postgres sucks
|
||||
};
|
||||
|
||||
export const uploadChunk = async (
|
||||
userId: number,
|
||||
sessionId: string,
|
||||
@@ -28,13 +34,13 @@ export const uploadChunk = async (
|
||||
const session = await UploadRepo.getUploadSession(sessionId, userId);
|
||||
if (!session) {
|
||||
error(404, "Invalid upload id");
|
||||
} else if (chunkIndex >= session.totalChunks) {
|
||||
} else if (chunkIndex > session.totalChunks) {
|
||||
error(400, "Invalid chunk index");
|
||||
} else if (session.uploadedChunks.includes(chunkIndex)) {
|
||||
} else if (isChunkUploaded(session.bitmap, chunkIndex)) {
|
||||
error(409, "Chunk already uploaded");
|
||||
}
|
||||
|
||||
const isLastChunk = chunkIndex === session.totalChunks - 1;
|
||||
const isLastChunk = chunkIndex === session.totalChunks;
|
||||
filePath = `${session.path}/${chunkIndex}`;
|
||||
|
||||
const hashStream = createHash("sha256");
|
||||
|
||||
Reference in New Issue
Block a user