refactor: top level dir + moved route

create a root directory entry in table for each user and move file browser under /directories/$id
This commit is contained in:
2025-09-19 23:01:44 +00:00
parent 9fdcd4d293
commit e72de0676e
16 changed files with 1047 additions and 25 deletions

View File

@@ -19,6 +19,22 @@ type File = {
export type DirectoryItem = Directory | File
export type DirectoryItemKind = DirectoryItem["kind"]
export async function fetchRoot(ctx: AuthenticatedQueryCtx) {
return await ctx.db
.query("directories")
.withIndex("byParentId", (q) =>
q.eq("userId", ctx.user._id).eq("parentId", undefined),
)
.first()
}
export async function fetch(
ctx: AuthenticatedQueryCtx,
{ directoryId }: { directoryId: Id<"directories"> },
) {
return await ctx.db.get(directoryId)
}
export async function fetchContent(
ctx: AuthenticatedQueryCtx,
{
@@ -76,17 +92,14 @@ export async function fetchContent(
export async function create(
ctx: AuthenticatedMutationCtx,
{ name, parentId }: { name: string; parentId?: Id<"directories"> },
{ name, parentId }: { name: string; parentId: Id<"directories"> },
): Promise<Id<"directories">> {
let parentDir: Doc<"directories"> | null = null
if (parentId) {
parentDir = await ctx.db.get(parentId)
if (!parentDir) {
throw Err.create(
Err.Code.DirectoryNotFound,
`Parent directory ${parentId} not found`,
)
}
const parentDir = await ctx.db.get(parentId)
if (!parentDir) {
throw Err.create(
Err.Code.DirectoryNotFound,
`Parent directory ${parentId} not found`,
)
}
const existing = await ctx.db