mirror of
https://github.com/kmc7468/arkvault.git
synced 2025-12-16 06:58:46 +00:00
/api/directory/[id], /api/directory/create Endpoint 구현
This commit is contained in:
58
src/lib/server/db/schema/file.ts
Normal file
58
src/lib/server/db/schema/file.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import { sqliteTable, text, integer, foreignKey } from "drizzle-orm/sqlite-core";
|
||||
import { mek } from "./mek";
|
||||
import { user } from "./user";
|
||||
|
||||
const ciphertext = (name: string) =>
|
||||
text(name, { mode: "json" }).$type<{
|
||||
ciphertext: string;
|
||||
iv: string;
|
||||
}>();
|
||||
|
||||
export const directory = sqliteTable(
|
||||
"directory",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
|
||||
parentId: integer("parent_id"),
|
||||
userId: integer("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
mekVersion: integer("master_encryption_key_version").notNull(),
|
||||
encDek: ciphertext("encrypted_data_encryption_key").notNull().unique(),
|
||||
encryptedAt: integer("encrypted_at", { mode: "timestamp_ms" }).notNull(),
|
||||
encName: ciphertext("encrypted_name").notNull(),
|
||||
},
|
||||
(t) => ({
|
||||
ref1: foreignKey({
|
||||
columns: [t.parentId],
|
||||
foreignColumns: [t.id],
|
||||
}),
|
||||
ref2: foreignKey({
|
||||
columns: [t.userId, t.mekVersion],
|
||||
foreignColumns: [mek.userId, mek.version],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
|
||||
export const file = sqliteTable(
|
||||
"file",
|
||||
{
|
||||
id: integer("id").primaryKey({ autoIncrement: true }),
|
||||
path: text("path").notNull().unique(),
|
||||
parentId: integer("parent_id").references(() => directory.id),
|
||||
createdAt: integer("created_at", { mode: "timestamp_ms" }).notNull(),
|
||||
userId: integer("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id),
|
||||
mekVersion: integer("master_encryption_key_version").notNull(),
|
||||
encDek: ciphertext("encrypted_data_encryption_key").notNull().unique(),
|
||||
encryptedAt: integer("encrypted_at", { mode: "timestamp_ms" }).notNull(),
|
||||
encName: ciphertext("encrypted_name").notNull(),
|
||||
},
|
||||
(t) => ({
|
||||
ref: foreignKey({
|
||||
columns: [t.userId, t.mekVersion],
|
||||
foreignColumns: [mek.userId, mek.version],
|
||||
}),
|
||||
}),
|
||||
);
|
||||
Reference in New Issue
Block a user