mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
Merge branch 'dev' into add-file-category
This commit is contained in:
@@ -27,6 +27,7 @@ export interface NewFileParams {
|
||||
contentHmac: string | null;
|
||||
contentType: string;
|
||||
encContentIv: string;
|
||||
encContentHash: string;
|
||||
encName: string;
|
||||
encNameIv: string;
|
||||
encCreatedAt: string | null;
|
||||
@@ -130,14 +131,15 @@ export const unregisterDirectory = async (userId: number, directoryId: number) =
|
||||
return await db.transaction(
|
||||
async (tx) => {
|
||||
const unregisterFiles = async (parentId: number) => {
|
||||
const files = await tx
|
||||
return await tx
|
||||
.delete(file)
|
||||
.where(and(eq(file.userId, userId), eq(file.parentId, parentId)))
|
||||
.returning({ path: file.path });
|
||||
return files.map(({ path }) => path);
|
||||
.returning({ id: file.id, path: file.path });
|
||||
};
|
||||
const unregisterDirectoryRecursively = async (directoryId: number): Promise<string[]> => {
|
||||
const filePaths = await unregisterFiles(directoryId);
|
||||
const unregisterDirectoryRecursively = async (
|
||||
directoryId: number,
|
||||
): Promise<{ id: number; path: string }[]> => {
|
||||
const files = await unregisterFiles(directoryId);
|
||||
const subDirectories = await tx
|
||||
.select({ id: directory.id })
|
||||
.from(directory)
|
||||
@@ -150,7 +152,7 @@ export const unregisterDirectory = async (userId: number, directoryId: number) =
|
||||
if (deleteRes.changes === 0) {
|
||||
throw new IntegrityError("Directory not found");
|
||||
}
|
||||
return filePaths.concat(...subDirectoryFilePaths);
|
||||
return files.concat(...subDirectoryFilePaths);
|
||||
};
|
||||
return await unregisterDirectoryRecursively(directoryId);
|
||||
},
|
||||
@@ -198,11 +200,12 @@ export const registerFile = async (params: NewFileParams) => {
|
||||
userId: params.userId,
|
||||
mekVersion: params.mekVersion,
|
||||
hskVersion: params.hskVersion,
|
||||
contentHmac: params.contentHmac,
|
||||
contentType: params.contentType,
|
||||
encDek: params.encDek,
|
||||
dekVersion: params.dekVersion,
|
||||
contentHmac: params.contentHmac,
|
||||
contentType: params.contentType,
|
||||
encContentIv: params.encContentIv,
|
||||
encContentHash: params.encContentHash,
|
||||
encName: { ciphertext: params.encName, iv: params.encNameIv },
|
||||
encCreatedAt:
|
||||
params.encCreatedAt && params.encCreatedAtIv
|
||||
|
||||
Reference in New Issue
Block a user