mirror of
https://github.com/get-drexa/drive.git
synced 2025-11-30 21:41:39 +00:00
feat: initial impl of file proxy
This commit is contained in:
36
packages/convex/model/filepreview.ts
Normal file
36
packages/convex/model/filepreview.ts
Normal 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),
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user