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

@@ -1,12 +1,39 @@
import { Hono } from "hono"
import { api } from "@fileone/convex/api"
import { newRouter } from "./router"
const h = new Hono().basePath("/files")
const r = newRouter().basePath("/files")
h.get("/:fileId", async (c) => {
const fileId = c.req.param("fileId")
if (!fileId) {
return c.json({ error: "File ID is required" }, 400)
r.get(":shareToken", async (c) => {
const shareToken = c.req.param("shareToken")
if (!shareToken) {
return c.json({ error: "not found" }, 404)
}
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,
})
})
export { h as files }
export { r as files }