mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-14 22:08:45 +00:00
Date 관련 Zod 스키마 수정
z.coerce.date()가 아닌 z.string().datetime()을 사용하도록 변경하여, 번거롭더라도 버그를 줄일 수 있는 방향으로 수정하였습니다.
This commit is contained in:
@@ -26,7 +26,7 @@ const fetchDirectoryInfo = async (directoryId: "root" | number, masterKey: Crypt
|
|||||||
newInfo = {
|
newInfo = {
|
||||||
id: directoryId,
|
id: directoryId,
|
||||||
dataKey,
|
dataKey,
|
||||||
dataKeyVersion: metadata!.dekVersion,
|
dataKeyVersion: new Date(metadata!.dekVersion),
|
||||||
name: await decryptString(metadata!.name, metadata!.nameIv, dataKey),
|
name: await decryptString(metadata!.name, metadata!.nameIv, dataKey),
|
||||||
subDirectoryIds: subDirectories,
|
subDirectoryIds: subDirectories,
|
||||||
fileIds: files,
|
fileIds: files,
|
||||||
@@ -63,7 +63,7 @@ const fetchFileInfo = async (fileId: number, masterKey: CryptoKey) => {
|
|||||||
const newInfo: FileInfo = {
|
const newInfo: FileInfo = {
|
||||||
id: fileId,
|
id: fileId,
|
||||||
dataKey,
|
dataKey,
|
||||||
dataKeyVersion: metadata.dekVersion,
|
dataKeyVersion: new Date(metadata.dekVersion),
|
||||||
contentType: metadata.contentType,
|
contentType: metadata.contentType,
|
||||||
contentIv: metadata.contentIv,
|
contentIv: metadata.contentIv,
|
||||||
name: await decryptString(metadata.name, metadata.nameIv, dataKey),
|
name: await decryptString(metadata.name, metadata.nameIv, dataKey),
|
||||||
|
|||||||
@@ -1,19 +1,12 @@
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const directoryRenameRequest = z.object({
|
|
||||||
dekVersion: z.coerce.date(),
|
|
||||||
name: z.string().base64().nonempty(),
|
|
||||||
nameIv: z.string().base64().nonempty(),
|
|
||||||
});
|
|
||||||
export type DirectoryRenameRequest = z.infer<typeof directoryRenameRequest>;
|
|
||||||
|
|
||||||
export const directoryInfoResponse = z.object({
|
export const directoryInfoResponse = z.object({
|
||||||
metadata: z
|
metadata: z
|
||||||
.object({
|
.object({
|
||||||
createdAt: z.date(),
|
createdAt: z.string().datetime(),
|
||||||
mekVersion: z.number().int().positive(),
|
mekVersion: z.number().int().positive(),
|
||||||
dek: z.string().base64().nonempty(),
|
dek: z.string().base64().nonempty(),
|
||||||
dekVersion: z.date(),
|
dekVersion: z.string().datetime(),
|
||||||
name: z.string().base64().nonempty(),
|
name: z.string().base64().nonempty(),
|
||||||
nameIv: z.string().base64().nonempty(),
|
nameIv: z.string().base64().nonempty(),
|
||||||
})
|
})
|
||||||
@@ -23,11 +16,18 @@ export const directoryInfoResponse = z.object({
|
|||||||
});
|
});
|
||||||
export type DirectoryInfoResponse = z.infer<typeof directoryInfoResponse>;
|
export type DirectoryInfoResponse = z.infer<typeof directoryInfoResponse>;
|
||||||
|
|
||||||
|
export const directoryRenameRequest = z.object({
|
||||||
|
dekVersion: z.string().datetime(),
|
||||||
|
name: z.string().base64().nonempty(),
|
||||||
|
nameIv: z.string().base64().nonempty(),
|
||||||
|
});
|
||||||
|
export type DirectoryRenameRequest = z.infer<typeof directoryRenameRequest>;
|
||||||
|
|
||||||
export const directoryCreateRequest = z.object({
|
export const directoryCreateRequest = z.object({
|
||||||
parentId: z.union([z.enum(["root"]), z.number().int().positive()]),
|
parentId: z.union([z.enum(["root"]), z.number().int().positive()]),
|
||||||
mekVersion: z.number().int().positive(),
|
mekVersion: z.number().int().positive(),
|
||||||
dek: z.string().base64().nonempty(),
|
dek: z.string().base64().nonempty(),
|
||||||
dekVersion: z.coerce.date(),
|
dekVersion: z.string().datetime(),
|
||||||
name: z.string().base64().nonempty(),
|
name: z.string().base64().nonempty(),
|
||||||
nameIv: z.string().base64().nonempty(),
|
nameIv: z.string().base64().nonempty(),
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +1,11 @@
|
|||||||
import mime from "mime";
|
import mime from "mime";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
|
|
||||||
export const fileRenameRequest = z.object({
|
|
||||||
dekVersion: z.coerce.date(),
|
|
||||||
name: z.string().base64().nonempty(),
|
|
||||||
nameIv: z.string().base64().nonempty(),
|
|
||||||
});
|
|
||||||
export type FileRenameRequest = z.infer<typeof fileRenameRequest>;
|
|
||||||
|
|
||||||
export const fileInfoResponse = z.object({
|
export const fileInfoResponse = z.object({
|
||||||
createdAt: z.date(),
|
createdAt: z.string().datetime(),
|
||||||
mekVersion: z.number().int().positive(),
|
mekVersion: z.number().int().positive(),
|
||||||
dek: z.string().base64().nonempty(),
|
dek: z.string().base64().nonempty(),
|
||||||
dekVersion: z.date(),
|
dekVersion: z.string().datetime(),
|
||||||
contentType: z
|
contentType: z
|
||||||
.string()
|
.string()
|
||||||
.nonempty()
|
.nonempty()
|
||||||
@@ -23,11 +16,18 @@ export const fileInfoResponse = z.object({
|
|||||||
});
|
});
|
||||||
export type FileInfoResponse = z.infer<typeof fileInfoResponse>;
|
export type FileInfoResponse = z.infer<typeof fileInfoResponse>;
|
||||||
|
|
||||||
|
export const fileRenameRequest = z.object({
|
||||||
|
dekVersion: z.string().datetime(),
|
||||||
|
name: z.string().base64().nonempty(),
|
||||||
|
nameIv: z.string().base64().nonempty(),
|
||||||
|
});
|
||||||
|
export type FileRenameRequest = z.infer<typeof fileRenameRequest>;
|
||||||
|
|
||||||
export const fileUploadRequest = z.object({
|
export const fileUploadRequest = z.object({
|
||||||
parentId: z.union([z.enum(["root"]), z.number().int().positive()]),
|
parentId: z.union([z.enum(["root"]), z.number().int().positive()]),
|
||||||
mekVersion: z.number().int().positive(),
|
mekVersion: z.number().int().positive(),
|
||||||
dek: z.string().base64().nonempty(),
|
dek: z.string().base64().nonempty(),
|
||||||
dekVersion: z.coerce.date(),
|
dekVersion: z.string().datetime(),
|
||||||
contentType: z
|
contentType: z
|
||||||
.string()
|
.string()
|
||||||
.nonempty()
|
.nonempty()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export const requestDirectoryCreation = async (
|
|||||||
parentId,
|
parentId,
|
||||||
mekVersion: masterKey.version,
|
mekVersion: masterKey.version,
|
||||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||||
dekVersion: dataKeyVersion,
|
dekVersion: dataKeyVersion.toISOString(),
|
||||||
name: encodeToBase64(nameEncrypted.ciphertext),
|
name: encodeToBase64(nameEncrypted.ciphertext),
|
||||||
nameIv: nameEncrypted.iv,
|
nameIv: nameEncrypted.iv,
|
||||||
});
|
});
|
||||||
@@ -52,7 +52,7 @@ export const requestFileUpload = (file: File, parentId: "root" | number, masterK
|
|||||||
parentId,
|
parentId,
|
||||||
mekVersion: masterKey.version,
|
mekVersion: masterKey.version,
|
||||||
dek: await wrapDataKey(dataKey, masterKey.key),
|
dek: await wrapDataKey(dataKey, masterKey.key),
|
||||||
dekVersion: dataKeyVersion,
|
dekVersion: dataKeyVersion.toISOString(),
|
||||||
contentType: file.type,
|
contentType: file.type,
|
||||||
contentIv: fileEncrypted.iv,
|
contentIv: fileEncrypted.iv,
|
||||||
name: nameEncrypted.ciphertext,
|
name: nameEncrypted.ciphertext,
|
||||||
@@ -85,13 +85,13 @@ export const requestDirectoryEntryRename = async (
|
|||||||
|
|
||||||
if (entry.type === "directory") {
|
if (entry.type === "directory") {
|
||||||
await callPostApi<DirectoryRenameRequest>(`/api/directory/${entry.id}/rename`, {
|
await callPostApi<DirectoryRenameRequest>(`/api/directory/${entry.id}/rename`, {
|
||||||
dekVersion: entry.dataKeyVersion,
|
dekVersion: entry.dataKeyVersion.toISOString(),
|
||||||
name: newNameEncrypted.ciphertext,
|
name: newNameEncrypted.ciphertext,
|
||||||
nameIv: newNameEncrypted.iv,
|
nameIv: newNameEncrypted.iv,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
await callPostApi<FileRenameRequest>(`/api/file/${entry.id}/rename`, {
|
await callPostApi<FileRenameRequest>(`/api/file/${entry.id}/rename`, {
|
||||||
dekVersion: entry.dataKeyVersion,
|
dekVersion: entry.dataKeyVersion.toISOString(),
|
||||||
name: newNameEncrypted.ciphertext,
|
name: newNameEncrypted.ciphertext,
|
||||||
nameIv: newNameEncrypted.iv,
|
nameIv: newNameEncrypted.iv,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ export const GET: RequestHandler = async ({ cookies, params }) => {
|
|||||||
return json(
|
return json(
|
||||||
directoryInfoResponse.parse({
|
directoryInfoResponse.parse({
|
||||||
metadata: metadata && {
|
metadata: metadata && {
|
||||||
createdAt: metadata.createdAt,
|
createdAt: metadata.createdAt.toISOString(),
|
||||||
mekVersion: metadata.mekVersion,
|
mekVersion: metadata.mekVersion,
|
||||||
dek: metadata.encDek,
|
dek: metadata.encDek,
|
||||||
dekVersion: metadata.dekVersion,
|
dekVersion: metadata.dekVersion.toISOString(),
|
||||||
name: metadata.encName.ciphertext,
|
name: metadata.encName.ciphertext,
|
||||||
nameIv: metadata.encName.iv,
|
nameIv: metadata.encName.iv,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ export const POST: RequestHandler = async ({ request, cookies, params }) => {
|
|||||||
if (!bodyZodRes.success) error(400, "Invalid request body");
|
if (!bodyZodRes.success) error(400, "Invalid request body");
|
||||||
const { dekVersion, name, nameIv } = bodyZodRes.data;
|
const { dekVersion, name, nameIv } = bodyZodRes.data;
|
||||||
|
|
||||||
await renameDirectory(userId, id, dekVersion, name, nameIv);
|
await renameDirectory(userId, id, new Date(dekVersion), name, nameIv);
|
||||||
return text("Directory renamed", { headers: { "Content-Type": "text/plain" } });
|
return text("Directory renamed", { headers: { "Content-Type": "text/plain" } });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
|
|||||||
parentId,
|
parentId,
|
||||||
mekVersion,
|
mekVersion,
|
||||||
encDek: dek,
|
encDek: dek,
|
||||||
dekVersion,
|
dekVersion: new Date(dekVersion),
|
||||||
encName: name,
|
encName: name,
|
||||||
encNameIv: nameIv,
|
encNameIv: nameIv,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ export const GET: RequestHandler = async ({ cookies, params }) => {
|
|||||||
await getFileInformation(userId, id);
|
await getFileInformation(userId, id);
|
||||||
return json(
|
return json(
|
||||||
fileInfoResponse.parse({
|
fileInfoResponse.parse({
|
||||||
createdAt,
|
createdAt: createdAt.toISOString(),
|
||||||
mekVersion,
|
mekVersion,
|
||||||
dek: encDek,
|
dek: encDek,
|
||||||
dekVersion,
|
dekVersion: dekVersion.toISOString(),
|
||||||
contentType: contentType,
|
contentType: contentType,
|
||||||
contentIv: encContentIv,
|
contentIv: encContentIv,
|
||||||
name: encName.ciphertext,
|
name: encName.ciphertext,
|
||||||
|
|||||||
@@ -20,6 +20,6 @@ export const POST: RequestHandler = async ({ request, cookies, params }) => {
|
|||||||
if (!bodyZodRes.success) error(400, "Invalid request body");
|
if (!bodyZodRes.success) error(400, "Invalid request body");
|
||||||
const { dekVersion, name, nameIv } = bodyZodRes.data;
|
const { dekVersion, name, nameIv } = bodyZodRes.data;
|
||||||
|
|
||||||
await renameFile(userId, id, dekVersion, name, nameIv);
|
await renameFile(userId, id, new Date(dekVersion), name, nameIv);
|
||||||
return text("File renamed", { headers: { "Content-Type": "text/plain" } });
|
return text("File renamed", { headers: { "Content-Type": "text/plain" } });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ export const POST: RequestHandler = async ({ request, cookies }) => {
|
|||||||
parentId,
|
parentId,
|
||||||
mekVersion,
|
mekVersion,
|
||||||
encDek: dek,
|
encDek: dek,
|
||||||
dekVersion,
|
dekVersion: new Date(dekVersion),
|
||||||
contentType,
|
contentType,
|
||||||
encContentIv: contentIv,
|
encContentIv: contentIv,
|
||||||
encName: name,
|
encName: name,
|
||||||
|
|||||||
Reference in New Issue
Block a user