[infra] Add data-puller CF worker (#3927)

This commit is contained in:
Manav Rathi
2024-11-04 13:43:59 +05:30
committed by GitHub
4 changed files with 41 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
{
"name": "data-puller",
"version": "0.0.0",
"private": true
}

View File

@@ -0,0 +1,30 @@
/**
* Proxy requests for downloading files from object storage.
*
* Used by museum when replicating.
*/
export default {
async fetch(request: Request) {
switch (request.method) {
case "GET":
return handleGET(request);
default:
console.log(`Unsupported HTTP method ${request.method}`);
return new Response(null, { status: 405 });
}
},
} satisfies ExportedHandler;
const handleGET = async (request: Request) => {
const url = new URL(request.url);
// Random bots keep trying to pentest causing noise in the logs. If the
// request doesn't have a src, we can just safely ignore it.
const src = url.searchParams.get("src");
if (!src) return new Response(null, { status: 400 });
const source = atob(src);
return fetch(source);
};

View File

@@ -0,0 +1 @@
{ "extends": "../tsconfig.base.json", "include": ["src"] }

View File

@@ -0,0 +1,5 @@
name = "data-puller"
main = "src/index.ts"
compatibility_date = "2024-06-14"
tail_consumers = [{ service = "tail" }]