feat: impl multi file/dir moving

Co-authored-by: Ona <no-reply@ona.com>
This commit is contained in:
2025-09-21 17:03:50 +00:00
parent a331276c43
commit 29eab87c71
10 changed files with 147 additions and 53 deletions

View File

@@ -4,7 +4,7 @@ import type {
AuthenticatedQueryCtx,
} from "../functions"
import * as Err from "./error"
import type { FilePath, ReverseFilePath } from "./filesystem"
import type { DirectoryHandle, FilePath, ReverseFilePath } from "./filesystem"
import { newDirectoryHandle } from "./filesystem"
type Directory = {
@@ -31,6 +31,20 @@ export async function fetchRoot(ctx: AuthenticatedQueryCtx) {
.first()
}
export async function fetchHandle(
ctx: AuthenticatedQueryCtx,
handle: DirectoryHandle,
): Promise<Doc<"directories">> {
const directory = await ctx.db.get(handle.id)
if (!directory || directory.userId !== ctx.user._id) {
throw Err.create(
Err.Code.DirectoryNotFound,
`Directory ${handle.id} not found`,
)
}
return directory
}
export async function fetch(
ctx: AuthenticatedQueryCtx,
{ directoryId }: { directoryId: Id<"directories"> },
@@ -147,6 +161,23 @@ export async function create(
})
}
export async function move(
ctx: AuthenticatedMutationCtx,
{
targetDirectory,
sourceDirectories,
}: {
targetDirectory: DirectoryHandle
sourceDirectories: DirectoryHandle[]
},
): Promise<void> {
await Promise.all(
sourceDirectories.map((directory) =>
ctx.db.patch(directory.id, { parentId: targetDirectory.id }),
),
)
}
export async function moveToTrashRecursive(
ctx: AuthenticatedMutationCtx,
directoryId: Id<"directories">,