Files
drive/apps/file-proxy/files.ts

40 lines
913 B
TypeScript
Raw Normal View History

2025-10-21 23:45:04 +00:00
import { api } from "@fileone/convex/api"
import { newRouter } from "./router"
2025-10-21 23:45:04 +00:00
const r = newRouter().basePath("/files")
2025-10-21 23:45:04 +00:00
r.get(":shareToken", async (c) => {
const shareToken = c.req.param("shareToken")
if (!shareToken) {
return c.json({ error: "not found" }, 404)
}
2025-10-21 23:45:04 +00:00
const fileShare = await c.var.convex.query(api.fileshare.findFileShare, {
apiKey: c.var.apiKey,
shareToken,
})
if (!fileShare) {
return c.json({ error: "not found" }, 404)
}
const fileUrl = await c.var.convex.query(api.filesystem.getStorageUrl, {
apiKey: c.var.apiKey,
storageId: fileShare.storageId,
})
if (!fileUrl) {
return c.json({ error: "not found" }, 404)
}
const fileResponse = await fetch(fileUrl)
if (!fileResponse.ok) {
return c.json({ error: "not found" }, 404)
}
return new Response(fileResponse.body, {
status: fileResponse.status,
headers: fileResponse.headers,
})
})
2025-10-21 23:45:04 +00:00
export { r as files }