사소한 리팩토링

This commit is contained in:
static
2026-01-11 14:35:30 +09:00
parent 57c27b76be
commit 2801eed556
22 changed files with 26 additions and 37 deletions

View File

@@ -1 +1 @@
export const DECRYPTED_FILE_URL_PREFIX = "/_internal/decrypted-file/"; export const DECRYPTED_FILE_URL_PREFIX = "/_internal/decryptedFile/";

View File

@@ -5,7 +5,7 @@ import {
encodeToBase64, encodeToBase64,
decodeFromBase64, decodeFromBase64,
concatenateBuffers, concatenateBuffers,
} from "./util"; } from "./utils";
export const generateMasterKey = async () => { export const generateMasterKey = async () => {
return { return {

View File

@@ -1,4 +1,4 @@
export * from "./aes"; export * from "./aes";
export * from "./rsa"; export * from "./rsa";
export * from "./sha"; export * from "./sha";
export * from "./util"; export * from "./utils";

View File

@@ -1,4 +1,4 @@
import { encodeString, encodeToBase64, decodeFromBase64 } from "./util"; import { encodeString, encodeToBase64, decodeFromBase64 } from "./utils";
export const generateEncryptionKeyPair = async () => { export const generateEncryptionKeyPair = async () => {
const keyPair = await crypto.subtle.generateKey( const keyPair = await crypto.subtle.generateKey(

View File

@@ -2,7 +2,7 @@ import { z } from "zod";
import { storeClientKey } from "$lib/indexedDB"; import { storeClientKey } from "$lib/indexedDB";
import type { ClientKeys } from "$lib/stores"; import type { ClientKeys } from "$lib/stores";
const serializedClientKeysSchema = z.intersection( const SerializedClientKeysSchema = z.intersection(
z.object({ z.object({
generator: z.literal("ArkVault"), generator: z.literal("ArkVault"),
exportedAt: z.iso.datetime(), exportedAt: z.iso.datetime(),
@@ -16,7 +16,7 @@ const serializedClientKeysSchema = z.intersection(
}), }),
); );
type SerializedClientKeys = z.infer<typeof serializedClientKeysSchema>; type SerializedClientKeys = z.infer<typeof SerializedClientKeysSchema>;
type DeserializedClientKeys = { type DeserializedClientKeys = {
encryptKeyBase64: string; encryptKeyBase64: string;
@@ -43,7 +43,7 @@ export const serializeClientKeys = ({
}; };
export const deserializeClientKeys = (serialized: string) => { export const deserializeClientKeys = (serialized: string) => {
const zodRes = serializedClientKeysSchema.safeParse(JSON.parse(serialized)); const zodRes = SerializedClientKeysSchema.safeParse(JSON.parse(serialized));
if (zodRes.success) { if (zodRes.success) {
return { return {
encryptKeyBase64: zodRes.data.encryptKey, encryptKeyBase64: zodRes.data.encryptKey,

View File

@@ -0,0 +1,4 @@
import { z } from "zod";
export const DirectoryIdSchema = z.union([z.literal("root"), z.int().positive()]);
export const CategoryIdSchema = z.union([z.literal("root"), z.int().positive()]);

1
src/lib/schemas/index.ts Normal file
View File

@@ -0,0 +1 @@
export * from "./filesystem";

View File

@@ -1,5 +1,5 @@
import type { Generated } from "kysely"; import type { Generated } from "kysely";
import type { Ciphertext } from "./util"; import type { Ciphertext } from "./utils";
interface CategoryTable { interface CategoryTable {
id: Generated<number>; id: Generated<number>;

View File

@@ -1,5 +1,5 @@
import type { ColumnType, Generated } from "kysely"; import type { ColumnType, Generated } from "kysely";
import type { Ciphertext } from "./util"; import type { Ciphertext } from "./utils";
interface DirectoryTable { interface DirectoryTable {
id: Generated<number>; id: Generated<number>;

View File

@@ -7,7 +7,7 @@ export * from "./mek";
export * from "./session"; export * from "./session";
export * from "./upload"; export * from "./upload";
export * from "./user"; export * from "./user";
export * from "./util"; export * from "./utils";
// eslint-disable-next-line @typescript-eslint/no-empty-object-type // eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface Database {} export interface Database {}

View File

@@ -1,5 +1,5 @@
import type { Generated } from "kysely"; import type { Generated } from "kysely";
import type { Ciphertext } from "./util"; import type { Ciphertext } from "./utils";
interface UploadSessionTable { interface UploadSessionTable {
id: Generated<string>; id: Generated<string>;

View File

@@ -1,3 +0,0 @@
import { z } from "zod";
export const categoryIdSchema = z.union([z.literal("root"), z.int().positive()]);

View File

@@ -1,3 +0,0 @@
import { z } from "zod";
export const directoryIdSchema = z.union([z.literal("root"), z.int().positive()]);

View File

@@ -1,7 +0,0 @@
import { z } from "zod";
export const fileThumbnailUploadRequest = z.object({
dekVersion: z.iso.datetime(),
contentIv: z.base64().nonempty(),
});
export type FileThumbnailUploadRequest = z.input<typeof fileThumbnailUploadRequest>;

View File

@@ -1,3 +0,0 @@
export * from "./category";
export * from "./directory";
export * from "./file";

View File

@@ -1,7 +1,7 @@
import { error } from "@sveltejs/kit"; import { error } from "@sveltejs/kit";
import { z } from "zod"; import { z } from "zod";
import { authorize } from "$lib/server/modules/auth";
import { parseRangeHeader, getContentRangeHeader } from "$lib/modules/http"; import { parseRangeHeader, getContentRangeHeader } from "$lib/modules/http";
import { authorize } from "$lib/server/modules/auth";
import { getFileStream } from "$lib/server/services/file"; import { getFileStream } from "$lib/server/services/file";
import type { RequestHandler } from "./$types"; import type { RequestHandler } from "./$types";

View File

@@ -1,7 +1,7 @@
import { error } from "@sveltejs/kit"; import { error } from "@sveltejs/kit";
import { z } from "zod"; import { z } from "zod";
import { authorize } from "$lib/server/modules/auth";
import { parseRangeHeader, getContentRangeHeader } from "$lib/modules/http"; import { parseRangeHeader, getContentRangeHeader } from "$lib/modules/http";
import { authorize } from "$lib/server/modules/auth";
import { getFileThumbnailStream } from "$lib/server/services/file"; import { getFileThumbnailStream } from "$lib/server/services/file";
import type { RequestHandler } from "./$types"; import type { RequestHandler } from "./$types";

View File

@@ -1,14 +1,14 @@
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { z } from "zod"; import { z } from "zod";
import { CategoryIdSchema } from "$lib/schemas";
import { CategoryRepo, FileRepo, IntegrityError } from "$lib/server/db"; import { CategoryRepo, FileRepo, IntegrityError } from "$lib/server/db";
import { categoryIdSchema } from "$lib/server/schemas";
import { router, roleProcedure } from "../init.server"; import { router, roleProcedure } from "../init.server";
const categoryRouter = router({ const categoryRouter = router({
get: roleProcedure["activeClient"] get: roleProcedure["activeClient"]
.input( .input(
z.object({ z.object({
id: categoryIdSchema, id: CategoryIdSchema,
recurse: z.boolean().default(false), recurse: z.boolean().default(false),
}), }),
) )
@@ -65,7 +65,7 @@ const categoryRouter = router({
create: roleProcedure["activeClient"] create: roleProcedure["activeClient"]
.input( .input(
z.object({ z.object({
parent: categoryIdSchema, parent: CategoryIdSchema,
mekVersion: z.int().positive(), mekVersion: z.int().positive(),
dek: z.base64().nonempty(), dek: z.base64().nonempty(),
dekVersion: z.date(), dekVersion: z.date(),

View File

@@ -1,15 +1,15 @@
import { TRPCError } from "@trpc/server"; import { TRPCError } from "@trpc/server";
import { z } from "zod"; import { z } from "zod";
import { DirectoryIdSchema } from "$lib/schemas";
import { FileRepo, IntegrityError } from "$lib/server/db"; import { FileRepo, IntegrityError } from "$lib/server/db";
import { safeUnlink } from "$lib/server/modules/filesystem"; import { safeUnlink } from "$lib/server/modules/filesystem";
import { directoryIdSchema } from "$lib/server/schemas";
import { router, roleProcedure } from "../init.server"; import { router, roleProcedure } from "../init.server";
const directoryRouter = router({ const directoryRouter = router({
get: roleProcedure["activeClient"] get: roleProcedure["activeClient"]
.input( .input(
z.object({ z.object({
id: directoryIdSchema, id: DirectoryIdSchema,
}), }),
) )
.query(async ({ ctx, input }) => { .query(async ({ ctx, input }) => {
@@ -59,7 +59,7 @@ const directoryRouter = router({
create: roleProcedure["activeClient"] create: roleProcedure["activeClient"]
.input( .input(
z.object({ z.object({
parent: directoryIdSchema, parent: DirectoryIdSchema,
mekVersion: z.int().positive(), mekVersion: z.int().positive(),
dek: z.base64().nonempty(), dek: z.base64().nonempty(),
dekVersion: z.date(), dekVersion: z.date(),

View File

@@ -6,11 +6,11 @@ import mime from "mime";
import { dirname } from "path"; import { dirname } from "path";
import { v4 as uuidv4 } from "uuid"; import { v4 as uuidv4 } from "uuid";
import { z } from "zod"; import { z } from "zod";
import { DirectoryIdSchema } from "$lib/schemas";
import { FileRepo, MediaRepo, UploadRepo, IntegrityError } from "$lib/server/db"; import { FileRepo, MediaRepo, UploadRepo, IntegrityError } from "$lib/server/db";
import db from "$lib/server/db/kysely"; import db from "$lib/server/db/kysely";
import env from "$lib/server/loadenv"; import env from "$lib/server/loadenv";
import { getChunkDirectoryPath, safeUnlink } from "$lib/server/modules/filesystem"; import { getChunkDirectoryPath, safeUnlink } from "$lib/server/modules/filesystem";
import { directoryIdSchema } from "$lib/server/schemas";
import { router, roleProcedure } from "../init.server"; import { router, roleProcedure } from "../init.server";
const uploadLocks = new Set<string>(); const uploadLocks = new Set<string>();
@@ -20,7 +20,7 @@ const uploadRouter = router({
.input( .input(
z.object({ z.object({
chunks: z.int().positive(), chunks: z.int().positive(),
parent: directoryIdSchema, parent: DirectoryIdSchema,
mekVersion: z.int().positive(), mekVersion: z.int().positive(),
dek: z.base64().nonempty(), dek: z.base64().nonempty(),
dekVersion: z.date(), dekVersion: z.date(),