mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
프론트엔드에서의 파일 업로드 전 중복 검사 구현
This commit is contained in:
@@ -220,6 +220,23 @@ export const getAllFilesByParent = async (userId: number, parentId: DirectoryId)
|
||||
);
|
||||
};
|
||||
|
||||
export const getAllFileIdsByContentHmac = async (
|
||||
userId: number,
|
||||
hskVersion: number,
|
||||
contentHmac: string,
|
||||
) => {
|
||||
return await db
|
||||
.select({ id: file.id })
|
||||
.from(file)
|
||||
.where(
|
||||
and(
|
||||
eq(file.userId, userId),
|
||||
eq(file.hskVersion, hskVersion),
|
||||
eq(file.contentHmac, contentHmac),
|
||||
),
|
||||
);
|
||||
};
|
||||
|
||||
export const getFile = async (userId: number, fileId: number) => {
|
||||
const res = await db
|
||||
.select()
|
||||
|
||||
@@ -22,6 +22,17 @@ export const fileRenameRequest = z.object({
|
||||
});
|
||||
export type FileRenameRequest = z.infer<typeof fileRenameRequest>;
|
||||
|
||||
export const duplicateFileScanRequest = z.object({
|
||||
hskVersion: z.number().int().positive(),
|
||||
contentHmac: z.string().base64().nonempty(),
|
||||
});
|
||||
export type DuplicateFileScanRequest = z.infer<typeof duplicateFileScanRequest>;
|
||||
|
||||
export const duplicateFileScanResponse = z.object({
|
||||
files: z.number().int().positive().array(),
|
||||
});
|
||||
export type DuplicateFileScanResponse = z.infer<typeof duplicateFileScanResponse>;
|
||||
|
||||
export const fileUploadRequest = z.object({
|
||||
parentId: z.union([z.enum(["root"]), z.number().int().positive()]),
|
||||
mekVersion: z.number().int().positive(),
|
||||
|
||||
@@ -7,6 +7,7 @@ import { v4 as uuidv4 } from "uuid";
|
||||
import { IntegrityError } from "$lib/server/db/error";
|
||||
import {
|
||||
registerFile,
|
||||
getAllFileIdsByContentHmac,
|
||||
getFile,
|
||||
setFileEncName,
|
||||
unregisterFile,
|
||||
@@ -76,6 +77,15 @@ export const renameFile = async (
|
||||
}
|
||||
};
|
||||
|
||||
export const scanDuplicateFiles = async (
|
||||
userId: number,
|
||||
hskVersion: number,
|
||||
contentHmac: string,
|
||||
) => {
|
||||
const fileIds = await getAllFileIdsByContentHmac(userId, hskVersion, contentHmac);
|
||||
return { files: fileIds.map(({ id }) => id) };
|
||||
};
|
||||
|
||||
const safeUnlink = async (path: string) => {
|
||||
await unlink(path).catch(console.error);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user