mirror of
https://github.com/versia-pub/server.git
synced 2025-12-06 16:38:19 +01:00
fix(api): 🐛 Fix proxy returning incorrect media due to compression
This commit is contained in:
parent
8557867ad8
commit
ad4466a260
|
|
@ -39,7 +39,11 @@ export default (app: Hono) =>
|
||||||
400,
|
400,
|
||||||
);
|
);
|
||||||
|
|
||||||
return fetch(id).then((res) => {
|
return fetch(id, {
|
||||||
|
headers: {
|
||||||
|
"Accept-Encoding": "identity",
|
||||||
|
},
|
||||||
|
}).then((res) => {
|
||||||
return response(res.body, res.status, res.headers.toJSON());
|
return response(res.body, res.status, res.headers.toJSON());
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,46 +0,0 @@
|
||||||
import { applyConfig, handleZodError } from "@api";
|
|
||||||
import { zValidator } from "@hono/zod-validator";
|
|
||||||
import { errorResponse, response } from "@response";
|
|
||||||
import type { Hono } from "hono";
|
|
||||||
import { z } from "zod";
|
|
||||||
|
|
||||||
export const meta = applyConfig({
|
|
||||||
allowedMethods: ["GET"],
|
|
||||||
route: "/media/proxy",
|
|
||||||
ratelimits: {
|
|
||||||
max: 100,
|
|
||||||
duration: 60,
|
|
||||||
},
|
|
||||||
auth: {
|
|
||||||
required: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
export const schemas = {
|
|
||||||
query: z.object({
|
|
||||||
url: z
|
|
||||||
.string()
|
|
||||||
.transform((val) => Buffer.from(val, "base64url").toString()),
|
|
||||||
}),
|
|
||||||
};
|
|
||||||
|
|
||||||
export default (app: Hono) =>
|
|
||||||
app.on(
|
|
||||||
meta.allowedMethods,
|
|
||||||
meta.route,
|
|
||||||
zValidator("query", schemas.query, handleZodError),
|
|
||||||
async (context) => {
|
|
||||||
const { url } = context.req.valid("query");
|
|
||||||
|
|
||||||
// Check if URL is valid
|
|
||||||
if (!URL.canParse(url))
|
|
||||||
return errorResponse(
|
|
||||||
"Invalid URL (it should be encoded as base64url",
|
|
||||||
400,
|
|
||||||
);
|
|
||||||
|
|
||||||
return fetch(url).then((res) => {
|
|
||||||
return response(res.body, res.status, res.headers.toJSON());
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
@ -112,7 +112,7 @@ describe("POST /api/auth/login/", () => {
|
||||||
describe("GET /oauth/authorize/", () => {
|
describe("GET /oauth/authorize/", () => {
|
||||||
test("should get a code", async () => {
|
test("should get a code", async () => {
|
||||||
const response = await sendTestRequest(
|
const response = await sendTestRequest(
|
||||||
new Request(new URL(`/oauth/authorize`, base_url), {
|
new Request(new URL("/oauth/authorize", base_url), {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
Cookie: `jwt=${jwt}`,
|
Cookie: `jwt=${jwt}`,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue