[infra] Add data-puller CF worker (#3927)
This commit is contained in:
5
infra/workers/data-puller/package.json
Normal file
5
infra/workers/data-puller/package.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "data-puller",
|
||||
"version": "0.0.0",
|
||||
"private": true
|
||||
}
|
||||
30
infra/workers/data-puller/src/index.ts
Normal file
30
infra/workers/data-puller/src/index.ts
Normal 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);
|
||||
};
|
||||
1
infra/workers/data-puller/tsconfig.json
Normal file
1
infra/workers/data-puller/tsconfig.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "../tsconfig.base.json", "include": ["src"] }
|
||||
5
infra/workers/data-puller/wrangler.toml
Normal file
5
infra/workers/data-puller/wrangler.toml
Normal file
@@ -0,0 +1,5 @@
|
||||
name = "data-puller"
|
||||
main = "src/index.ts"
|
||||
compatibility_date = "2024-06-14"
|
||||
|
||||
tail_consumers = [{ service = "tail" }]
|
||||
Reference in New Issue
Block a user