mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-08-15 00:10:44 +02:00
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:
@@ -271,7 +271,16 @@ export default class AnonymizedFile {
|
|||||||
} else if (isTextFile(this.anonymizedPath)) {
|
} else if (isTextFile(this.anonymizedPath)) {
|
||||||
res.contentType("text/plain");
|
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) => {
|
anonymizer.once("transform", (data) => {
|
||||||
if (!mime && data.isText) {
|
if (!mime && data.isText) {
|
||||||
res.contentType("text/plain");
|
res.contentType("text/plain");
|
||||||
|
|||||||
@@ -66,7 +66,13 @@ router.post("/", async (req: express.Request, res: express.Response) => {
|
|||||||
} else if (isTextFile(filePath)) {
|
} else if (isTextFile(filePath)) {
|
||||||
res.contentType("text/plain");
|
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) => {
|
anonymizer.once("transform", (data) => {
|
||||||
if (!mime && data.isText) {
|
if (!mime && data.isText) {
|
||||||
res.contentType("text/plain");
|
res.contentType("text/plain");
|
||||||
|
|||||||
Reference in New Issue
Block a user