mirror of
https://github.com/kmc7468/arkvault.git
synced 2026-11-04 08:10:28 +09:00
서버 코드를 Router, Service, Repository 계층으로 분리하고 오류 처리 및 파일 삭제 로직 개선
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ed732be999
commit
6a6aa1765b
72 files changed
+1928
-1509
No files matched your search
@@ -0,0 +1,58 @@
|
||||
import { DirectoryRepo, FileRepo } from "#lib/server/db/index.js";
|
||||
import type { Ciphertext } from "#lib/server/db/schema/index.js";
|
||||
import { AppError } from "#lib/server/errors.js";
|
||||
import { ensureFreshDekVersion } from "./common";
|
||||
import { schedulePendingFileDeletions } from "./fileDeletion";
|
||||
|
||||
export const getDirectory = async (userId: number, directoryId: DirectoryId) => {
|
||||
const directory =
|
||||
directoryId !== "root" ? await DirectoryRepo.getDirectory(userId, directoryId) : undefined;
|
||||
if (directory === null) {
|
||||
throw new AppError("NOT_FOUND", "Directory not found");
|
||||
}
|
||||
|
||||
const [subDirectories, files] = await Promise.all([
|
||||
DirectoryRepo.getAllDirectoriesByParent(userId, directoryId),
|
||||
FileRepo.getAllFilesByParent(userId, directoryId),
|
||||
]);
|
||||
return { directory, subDirectories, files };
|
||||
};
|
||||
|
||||
export const createDirectory = async (params: {
|
||||
userId: number;
|
||||
parentId: DirectoryId;
|
||||
mekVersion: number;
|
||||
encDek: string;
|
||||
dekVersion: Date;
|
||||
encName: Ciphertext;
|
||||
}) => {
|
||||
ensureFreshDekVersion(params.dekVersion);
|
||||
await DirectoryRepo.registerDirectory(params);
|
||||
};
|
||||
|
||||
export const renameDirectory = async (
|
||||
userId: number,
|
||||
directoryId: number,
|
||||
dekVersion: Date,
|
||||
encName: Ciphertext,
|
||||
) => {
|
||||
await DirectoryRepo.setDirectoryEncName(userId, directoryId, dekVersion, encName);
|
||||
};
|
||||
|
||||
export const deleteDirectory = async (userId: number, directoryId: number) => {
|
||||
const { deletedFileIds } = await DirectoryRepo.unregisterDirectory(userId, directoryId);
|
||||
schedulePendingFileDeletions();
|
||||
return { deletedFileIds };
|
||||
};
|
||||
|
||||
export const getFavoriteDirectories = async (userId: number) => {
|
||||
return await DirectoryRepo.getAllFavoriteDirectories(userId);
|
||||
};
|
||||
|
||||
export const setDirectoryFavorite = async (
|
||||
userId: number,
|
||||
directoryId: number,
|
||||
isFavorite: boolean,
|
||||
) => {
|
||||
await DirectoryRepo.setDirectoryFavorite(userId, directoryId, isFavorite);
|
||||
};
|
||||
Reference in new issue
Block a user