aboutsummaryrefslogtreecommitdiff
path: root/apps/cdn
diff options
context:
space:
mode:
authorFuwn <[email protected]>2026-03-27 09:47:55 +0000
committerFuwn <[email protected]>2026-03-27 09:47:55 +0000
commit9af58779cf104b8f5552bac81fe8b5f8eee2330d (patch)
treed07e3ef4a3c3b1d0947e6c9121567ee1dcf8fd4f /apps/cdn
parentfix(api): keep preferences publicly readable (diff)
downloaddue.moe-9af58779cf104b8f5552bac81fe8b5f8eee2330d.tar.xz
due.moe-9af58779cf104b8f5552bac81fe8b5f8eee2330d.zip
style(ci): format and tidy proxy files
Diffstat (limited to 'apps/cdn')
-rw-r--r--apps/cdn/index.ts192
-rw-r--r--apps/cdn/package.json10
2 files changed, 101 insertions, 101 deletions
diff --git a/apps/cdn/index.ts b/apps/cdn/index.ts
index 55c51256..e0d63db5 100644
--- a/apps/cdn/index.ts
+++ b/apps/cdn/index.ts
@@ -1,112 +1,112 @@
// <https://github.com/soruly/trace.moe-www/blob/master/image-proxy.js>
addEventListener("fetch", async (event) => {
- event.respondWith(handleRequest(event.request));
+ event.respondWith(handleRequest(event.request));
});
const errorResponse = (errorMessage) =>
- new Response(errorMessage, {
- status: 400,
- statusText: "Bad Request",
- });
+ new Response(errorMessage, {
+ status: 400,
+ statusText: "Bad Request",
+ });
const handleRequest = async (originalRequest) => {
- let originalURL = new URL(originalRequest.url);
- if (!originalURL.searchParams.get("url")) {
- return errorResponse("Error: Cannot get url from param");
- }
+ const originalURL = new URL(originalRequest.url);
+ if (!originalURL.searchParams.get("url")) {
+ return errorResponse("Error: Cannot get url from param");
+ }
- let imageURL = null;
- try {
- imageURL = new URL(originalURL.searchParams.get("url"));
- } catch (e) {}
- if (!imageURL) {
- return errorResponse("Error: Invalid URL string");
- }
+ let imageURL = null;
+ try {
+ imageURL = new URL(originalURL.searchParams.get("url"));
+ } catch {}
+ if (!imageURL) {
+ return errorResponse("Error: Invalid URL string");
+ }
- let imageRequest = new Request(imageURL, {
- redirect: "follow",
- headers: {
- referer: imageURL.origin,
- },
- });
+ const imageRequest = new Request(imageURL, {
+ redirect: "follow",
+ headers: {
+ referer: imageURL.origin,
+ },
+ });
- let response = await fetch(imageRequest, {
- cf: {
- polish: "lossy",
- cacheEverything: true,
- },
- });
+ const response = await fetch(imageRequest, {
+ cf: {
+ polish: "lossy",
+ cacheEverything: true,
+ },
+ });
- if (response.status >= 400) {
- return new Response(response.body, {
- status: response.status,
- statusText: response.statusText,
- headers: response.headers,
- });
- }
+ if (response.status >= 400) {
+ return new Response(response.body, {
+ status: response.status,
+ statusText: response.statusText,
+ headers: response.headers,
+ });
+ }
- // if (
- // response.headers.get("Content-Type").toLowerCase() !==
- // "application/octet-stream" &&
- // !["image", "video"].includes(
- // response.headers.get("Content-Type").split("/")[0].toLowerCase()
- // )
- // ) {
- // // retry as bot to get og:image
- // let webResponse = await fetch(
- // new Request(imageURL, {
- // redirect: "follow",
- // headers: {
- // referer: imageURL.origin,
- // "User-Agent": "googlebot",
- // },
- // })
- // );
- // if (response.status === 200) {
- // const ogImageURL = (await webResponse.text())
- // ?.match(/<[^<]+?"og:image".*?>/, "$1")?.[0]
- // ?.match(/content="(.*?)"/, "$1")?.[1];
+ // if (
+ // response.headers.get("Content-Type").toLowerCase() !==
+ // "application/octet-stream" &&
+ // !["image", "video"].includes(
+ // response.headers.get("Content-Type").split("/")[0].toLowerCase()
+ // )
+ // ) {
+ // // retry as bot to get og:image
+ // let webResponse = await fetch(
+ // new Request(imageURL, {
+ // redirect: "follow",
+ // headers: {
+ // referer: imageURL.origin,
+ // "User-Agent": "googlebot",
+ // },
+ // })
+ // );
+ // if (response.status === 200) {
+ // const ogImageURL = (await webResponse.text())
+ // ?.match(/<[^<]+?"og:image".*?>/, "$1")?.[0]
+ // ?.match(/content="(.*?)"/, "$1")?.[1];
- // if (ogImageURL && ogImageURL.match(/^https?:\/\//)) {
- // response = await fetch(
- // new Request(ogImageURL, {
- // redirect: "follow",
- // headers: {
- // referer: imageURL.origin,
- // },
- // })
- // );
- // if (response.status >= 400) {
- // return new Response(response.body, {
- // status: response.status,
- // statusText: response.statusText,
- // headers: response.headers,
- // });
- // }
- // }
- // }
- // }
- // if (
- // response.headers.get("Content-Type").toLowerCase() !==
- // "application/octet-stream" &&
- // !["image", "video"].includes(
- // response.headers.get("Content-Type").split("/")[0].toLowerCase()
- // )
- // ) {
- // return errorResponse(
- // "Error: Content-Type is not image or video or application/octet-stream"
- // );
- // }
+ // if (ogImageURL && ogImageURL.match(/^https?:\/\//)) {
+ // response = await fetch(
+ // new Request(ogImageURL, {
+ // redirect: "follow",
+ // headers: {
+ // referer: imageURL.origin,
+ // },
+ // })
+ // );
+ // if (response.status >= 400) {
+ // return new Response(response.body, {
+ // status: response.status,
+ // statusText: response.statusText,
+ // headers: response.headers,
+ // });
+ // }
+ // }
+ // }
+ // }
+ // if (
+ // response.headers.get("Content-Type").toLowerCase() !==
+ // "application/octet-stream" &&
+ // !["image", "video"].includes(
+ // response.headers.get("Content-Type").split("/")[0].toLowerCase()
+ // )
+ // ) {
+ // return errorResponse(
+ // "Error: Content-Type is not image or video or application/octet-stream"
+ // );
+ // }
- return new Response(response.body, {
- status: response.status,
- statusText: response.statusText,
- headers: {
- "Cache-Control":
- "public, immutable, s-maxage=31536000, max-age=31536000, stale-while-revalidate=60",
- "Access-Control-Allow-Origin": "https://due.moe",
- ...response.headers,
- },
- });
+ return new Response(response.body, {
+ status: response.status,
+ statusText: response.statusText,
+ headers: {
+ "Cache-Control":
+ "public, immutable, s-maxage=31536000, max-age=31536000, stale-while-revalidate=60",
+ "Access-Control-Allow-Origin": "https://due.moe",
+ ...response.headers,
+ },
+ });
};
diff --git a/apps/cdn/package.json b/apps/cdn/package.json
index 33970b95..cc85f6cb 100644
--- a/apps/cdn/package.json
+++ b/apps/cdn/package.json
@@ -1,7 +1,7 @@
{
- "private": true,
- "devDependencies": {
- "@types/node": "^17.0.42",
- "typescript": "^4.7.3"
- }
+ "private": true,
+ "devDependencies": {
+ "@types/node": "^17.0.42",
+ "typescript": "^4.7.3"
+ }
}