mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 15:08:46 +00:00
누락된 썸네일 생성 기능 구현
This commit is contained in:
@@ -89,6 +89,9 @@ const generateThumbnail = async (file: File, fileType: string) => {
|
||||
return await generateVideoThumbnail(url);
|
||||
}
|
||||
return null;
|
||||
} catch {
|
||||
// TODO: Error handling
|
||||
return null;
|
||||
} finally {
|
||||
if (url) {
|
||||
URL.revokeObjectURL(url);
|
||||
@@ -254,7 +257,7 @@ export const uploadFile = async (
|
||||
createdAtIv: createdAtEncrypted?.iv,
|
||||
lastModifiedAt: lastModifiedAtEncrypted.ciphertext,
|
||||
lastModifiedAtIv: lastModifiedAtEncrypted.iv,
|
||||
} as FileUploadRequest),
|
||||
} satisfies FileUploadRequest),
|
||||
);
|
||||
form.set("content", new Blob([fileEncrypted.ciphertext]));
|
||||
form.set("checksum", fileEncryptedHash);
|
||||
@@ -267,7 +270,7 @@ export const uploadFile = async (
|
||||
JSON.stringify({
|
||||
dekVersion: dataKeyVersion.toISOString(),
|
||||
contentIv: thumbnailEncrypted.iv,
|
||||
} as FileThumbnailUploadRequest),
|
||||
} satisfies FileThumbnailUploadRequest),
|
||||
);
|
||||
thumbnailForm.set("content", new Blob([thumbnailEncrypted.ciphertext]));
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ export const getAllFileIdsByContentHmac = async (
|
||||
.where("hmac_secret_key_version", "=", hskVersion)
|
||||
.where("content_hmac", "=", contentHmac)
|
||||
.execute();
|
||||
return files.map(({ id }) => ({ id }));
|
||||
return files.map(({ id }) => id);
|
||||
};
|
||||
|
||||
export const getFile = async (userId: number, fileId: number) => {
|
||||
|
||||
@@ -84,3 +84,27 @@ export const getFileThumbnail = async (userId: number, fileId: number) => {
|
||||
} satisfies FileThumbnail)
|
||||
: null;
|
||||
};
|
||||
|
||||
export const getMissingFileThumbnails = async (userId: number, limit: number = 100) => {
|
||||
const files = await db
|
||||
.selectFrom("file")
|
||||
.select("id")
|
||||
.where("user_id", "=", userId)
|
||||
.where((eb) =>
|
||||
eb.or([eb("content_type", "like", "image/%"), eb("content_type", "like", "video/%")]),
|
||||
)
|
||||
.where((eb) =>
|
||||
eb.not(
|
||||
eb.exists(
|
||||
eb
|
||||
.selectFrom("thumbnail")
|
||||
.select("thumbnail.id")
|
||||
.whereRef("thumbnail.file_id", "=", "file.id")
|
||||
.limit(1),
|
||||
),
|
||||
),
|
||||
)
|
||||
.limit(limit)
|
||||
.execute();
|
||||
return files.map((file) => file.id);
|
||||
};
|
||||
|
||||
@@ -53,6 +53,11 @@ export const duplicateFileScanResponse = z.object({
|
||||
});
|
||||
export type DuplicateFileScanResponse = z.infer<typeof duplicateFileScanResponse>;
|
||||
|
||||
export const missingThumbnailFileScanResponse = z.object({
|
||||
files: z.number().int().positive().array(),
|
||||
});
|
||||
export type MissingThumbnailFileScanResponse = z.infer<typeof missingThumbnailFileScanResponse>;
|
||||
|
||||
export const fileUploadRequest = z.object({
|
||||
parent: directoryIdSchema,
|
||||
mekVersion: z.number().int().positive(),
|
||||
|
||||
@@ -16,7 +16,11 @@ import {
|
||||
getAllFileCategories,
|
||||
type NewFile,
|
||||
} from "$lib/server/db/file";
|
||||
import { getFileThumbnail, updateFileThumbnail } from "$lib/server/db/media";
|
||||
import {
|
||||
updateFileThumbnail,
|
||||
getFileThumbnail,
|
||||
getMissingFileThumbnails,
|
||||
} from "$lib/server/db/media";
|
||||
import type { Ciphertext } from "$lib/server/db/schema";
|
||||
import env from "$lib/server/loadenv";
|
||||
|
||||
@@ -145,7 +149,12 @@ export const scanDuplicateFiles = async (
|
||||
contentHmac: string,
|
||||
) => {
|
||||
const fileIds = await getAllFileIdsByContentHmac(userId, hskVersion, contentHmac);
|
||||
return { files: fileIds.map(({ id }) => id) };
|
||||
return { files: fileIds };
|
||||
};
|
||||
|
||||
export const scanMissingFileThumbnails = async (userId: number) => {
|
||||
const fileIds = await getMissingFileThumbnails(userId);
|
||||
return { files: fileIds };
|
||||
};
|
||||
|
||||
const safeUnlink = async (path: string) => {
|
||||
|
||||
Reference in New Issue
Block a user