aboutsummaryrefslogtreecommitdiffstats
path: root/apps/web/app
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/app')
-rw-r--r--apps/web/app/api/assets/[assetId]/route.ts32
1 files changed, 26 insertions, 6 deletions
diff --git a/apps/web/app/api/assets/[assetId]/route.ts b/apps/web/app/api/assets/[assetId]/route.ts
index 73237d8d..3bff79ba 100644
--- a/apps/web/app/api/assets/[assetId]/route.ts
+++ b/apps/web/app/api/assets/[assetId]/route.ts
@@ -27,10 +27,30 @@ export async function GET(
assetId: params.assetId,
});
- return new Response(asset, {
- status: 200,
- headers: {
- "Content-type": metadata.contentType,
- },
- });
+ const range = request.headers.get("Range");
+ if (range) {
+ const parts = range.replace(/bytes=/, "").split("-");
+ const start = parseInt(parts[0], 10);
+ const end = parts[1] ? parseInt(parts[1], 10) : asset.length - 1;
+
+ // TODO: Don't read the whole asset into memory in the first place
+ const chunk = asset.subarray(start, end + 1);
+ return new Response(chunk, {
+ status: 206, // Partial Content
+ headers: {
+ "Content-Range": `bytes ${start}-${end}/${asset.length}`,
+ "Accept-Ranges": "bytes",
+ "Content-Length": chunk.length.toString(),
+ "Content-type": metadata.contentType,
+ },
+ });
+ } else {
+ return new Response(asset, {
+ status: 200,
+ headers: {
+ "Content-Length": asset.length.toString(),
+ "Content-type": metadata.contentType,
+ },
+ });
+ }
}