mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
Some checks failed
CodeQL Scan / Analyze (javascript-typescript) (push) Failing after 6s
Build Docker Images / lint (push) Failing after 10s
Build Docker Images / check (push) Failing after 11s
Build Docker Images / tests (push) Failing after 27s
Build Docker Images / build (server, Dockerfile, ${{ github.repository_owner }}/server) (push) Has been skipped
Build Docker Images / build (worker, Worker.Dockerfile, ${{ github.repository_owner }}/worker) (push) Has been skipped
Deploy Docs to GitHub Pages / build (push) Failing after 6s
Mirror to Codeberg / Mirror (push) Failing after 0s
Deploy Docs to GitHub Pages / Deploy (push) Has been skipped
Nix Build / check (push) Failing after 5s
26 lines
732 B
TypeScript
26 lines
732 B
TypeScript
import { config } from "~/config.ts";
|
|
|
|
export class ProxiableUrl extends URL {
|
|
private isAllowedOrigin(): boolean {
|
|
const allowedOrigins: URL[] = [config.http.base_url].concat(
|
|
config.s3?.public_url ?? [],
|
|
);
|
|
|
|
return allowedOrigins.some((origin) =>
|
|
this.hostname.endsWith(origin.hostname),
|
|
);
|
|
}
|
|
|
|
public get proxied(): string {
|
|
// Don't proxy from CDN and self, since those sources are trusted
|
|
if (this.isAllowedOrigin()) {
|
|
return this.href;
|
|
}
|
|
|
|
const urlAsBase64Url = Buffer.from(this.href).toString("base64url");
|
|
|
|
return new URL(`/media/proxy/${urlAsBase64Url}`, config.http.base_url)
|
|
.href;
|
|
}
|
|
}
|