-
Notifications
You must be signed in to change notification settings - Fork 17
[Feature Request] Implement Range Requests for <video> / <audio> #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Is this Elysia or Bun bug? |
I've just found a walkaround: async getDownload(req) {
if (!req.params.hash || !req.params.name) return this.getIndex(req);
const file = Bun.file(path.join(Common.settings.storage.download, req.params.hash));
if (!await file.exists()) return this.getIndex(req);
if (req.headers.range) {
const chunk = Common.settings.storage.chunk_download;
let [start = 0, end = Infinity] = req.headers.range.split('=').at(-1).split('-').map(Number);
if (end == 0) end = start + chunk < file.size ? start + chunk : file.size;
return new Response(file.slice(start, start + chunk), {
status: 206,
headers: { 'Content-Range': 'bytes ' + start + '-' + end + '/' + file.size }
});
} else {
return new Response(file, {
headers: {
'Content-Type': 'application/octet-stream',
'Content-Disposition': 'attachment; filename="' + req.params.name + '"'
}
});
} |
Hmm, this walkaround seems to be working in Firefox only, not in Chrome. The problem is that the header range is present twice :( |
blocked by oven-sh/bun#7051 |
oven-sh/bun#7051 is closed |
Should have been fixed by 4ba3e85 published under 0.8.0. Feel free to reopen the issue if the problem still persists. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Due to the current implementation, the frontend must download the entire file, which in turn prevents buffering ("the frontend has to download the whole file first") in the video / audio control:
elysia-static/src/index.ts
Line 160 in 4032231
Bun supports Streaming files:
However this behavior doesn't allow seeking ("jumping to a timestamp") because the actual size is not set in the
Content-Range
header:bytes 0-10/*
bytes 0-10/20
The text was updated successfully, but these errors were encountered: