feat: initial impl of file proxy

This commit is contained in:
2025-10-21 23:45:04 +00:00
parent 6eded27121
commit 6234c5efd3
24 changed files with 420 additions and 125 deletions

View File

@@ -0,0 +1,36 @@
import type { Doc, Id } from "../_generated/dataModel"
import type {
AuthenticatedMutationCtx,
AuthenticatedQueryCtx,
} from "../functions"
import * as FileShare from "./fileshare"
const PREVIEW_FILE_SHARE_VALID_FOR_MS = 1000 * 60 * 10 // 10 minutes
export async function find(
ctx: AuthenticatedMutationCtx | AuthenticatedQueryCtx,
{ storageId }: { storageId: Id<"_storage"> },
) {
return await FileShare.findByStorageId(ctx, { storageId })
}
export async function create(
ctx: AuthenticatedMutationCtx,
{ storageId }: { storageId: Id<"_storage"> },
) {
return await FileShare.create(ctx, {
shareToken: crypto.randomUUID(),
storageId,
expiresAt: new Date(Date.now() + PREVIEW_FILE_SHARE_VALID_FOR_MS),
})
}
export async function extend(
ctx: AuthenticatedMutationCtx,
{ doc }: { doc: Doc<"fileShares"> },
) {
return await FileShare.updateExpiry(ctx, {
doc,
expiresAt: new Date(Date.now() + PREVIEW_FILE_SHARE_VALID_FOR_MS),
})
}