fix: don't declare Accept-Ranges: none for binary files

The server set Accept-Ranges: none on every file response. For text we
anonymize on the fly so byte ranges aren't meaningful, but binary
entries pass through unchanged — and the explicit "none" header makes
some browsers refuse to play <video>/<audio> elements that would
otherwise fall back to a full download. Newly uploaded MP4s under the
inline-preview threshold rendered as a blank progress bar (#538).

Only set Accept-Ranges: none for text entries; let binary entries omit
it so the standard fallback kicks in.

Fixes #538.
This commit is contained in:
tdurieux
2026-05-03 21:23:59 +02:00
parent 88fe8570fd
commit a30ab7fb96
2 changed files with 17 additions and 2 deletions
+10 -1
View File
@@ -271,7 +271,16 @@ export default class AnonymizedFile {
} else if (isTextFile(this.anonymizedPath)) {
res.contentType("text/plain");
}
res.header("Accept-Ranges", "none");
// For text files we anonymize on the fly and the output length can
// differ from the upstream, so byte ranges aren't meaningful — keep
// Accept-Ranges: none. For binary files (images, video, archives)
// the transformer is a passthrough, so omitting the explicit "none"
// lets <video>/<audio> elements use the standard fallback to a full
// download instead of refusing to play (#538).
const isTextEntry = isTextFile(this.anonymizedPath) === true;
if (isTextEntry) {
res.header("Accept-Ranges", "none");
}
anonymizer.once("transform", (data) => {
if (!mime && data.isText) {
res.contentType("text/plain");
+7 -1
View File
@@ -66,7 +66,13 @@ router.post("/", async (req: express.Request, res: express.Response) => {
} else if (isTextFile(filePath)) {
res.contentType("text/plain");
}
res.header("Accept-Ranges", "none");
// Only declare Accept-Ranges: none for text files — they get rewritten on
// the fly so byte ranges aren't meaningful. For binary entries the
// transformer is a passthrough; let <video>/<audio> fall back to a full
// download instead of refusing to play (#538).
if (isTextFile(filePath)) {
res.header("Accept-Ranges", "none");
}
anonymizer.once("transform", (data) => {
if (!mime && data.isText) {
res.contentType("text/plain");