mirror of
https://github.com/tdurieux/anonymous_github.git
synced 2026-12-02 17:13:33 +01:00
merge: reconcile paid hosting with shared cache and main
This commit is contained in:
commit
e71e6b6389
39 files changed
+2313
-56
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { notifyOwnerAccessProblem } from "./owner-notifications";
|
||||
import { sendSharedContent } from "./cached-response";
|
||||
import { streamResponse } from "./response-stream";
|
||||
import { join, basename, dirname } from "path";
|
||||
import { Response } from "express";
|
||||
@@ -455,7 +456,8 @@ export default class AnonymizedFile {
|
||||
const resStream = got
|
||||
.stream(join(config.STREAMER_ENTRYPOINT, "api"), {
|
||||
method: "POST",
|
||||
headers: requestHeaders(),
|
||||
headers: { ...requestHeaders(), "accept-encoding": res.req?.get?.("accept-encoding") || "identity" },
|
||||
decompress: false,
|
||||
json: {
|
||||
sha,
|
||||
size,
|
||||
@@ -478,6 +480,10 @@ export default class AnonymizedFile {
|
||||
resStream.on("response", (upstream: { headers: Record<string, string | string[] | undefined> }) => {
|
||||
headersDone();
|
||||
if (res.headersSent) return;
|
||||
for (const header of ["content-encoding", "content-length", "vary", "accept-ranges"]) {
|
||||
const value = upstream.headers[header];
|
||||
if (typeof value === "string") res.setHeader(header, value);
|
||||
}
|
||||
const ct = upstream.headers["content-type"];
|
||||
if (typeof ct === "string") {
|
||||
res.contentType(ct);
|
||||
@@ -531,6 +537,7 @@ export default class AnonymizedFile {
|
||||
});
|
||||
const content = await this.content();
|
||||
if (res.destroyed || res.writableEnded) { content.destroy(); anonymizer.destroy(); resolve(); return; }
|
||||
if (await sendSharedContent(content, res, anonymizer.opt)) { anonymizer.destroy(); resolve(); return; }
|
||||
function handleStreamError(error: Error) {
|
||||
if (!content.closed && !content.destroyed) {
|
||||
content.destroy();
|
||||
|
||||
Reference in new issue
Block a user