From a94b464615bd45e697f3ffbd146e996eb48cc5f8 Mon Sep 17 00:00:00 2001 From: Tracker-Friendly Date: Mon, 7 Aug 2023 00:24:59 +0100 Subject: [PATCH] Added richard stallman protector --- worker.js | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 worker.js diff --git a/worker.js b/worker.js new file mode 100644 index 0000000..6070b29 --- /dev/null +++ b/worker.js @@ -0,0 +1,48 @@ +addEventListener('fetch', event => { + event.respondWith(handleRequest(event.request)); +}); + +async function handleRequest(request) { + const url = new URL(request.url); + + // Define the base hostname and path for the mappings + const baseHostname = 'YOURWORKER.YOURUSER.workers.dev'; + const baseMappingPath = '/examplebase/'; + const testFilesPath = '/testfiles/'; + + // Check if the path matches the desired format + // Add ifs as needed + if (url.hostname === baseHostname && (url.pathname.startsWith(baseMappingPath) || url.pathname.startsWith(testFilesPath))) { + const subpath = url.pathname.startsWith(baseMappingPath) + ? url.pathname.substring(baseMappingPath.length) // Extract the subpath for mappings + : url.pathname.substring(testFilesPath.length); // Extract the subpath for test files + + // Define the mapping of subpaths to redirect URLs + const baseTargetUrls = { + 'x86_64.iso': 'https://example.com/x86_64.iso', + 'i686.iso': 'https://example.com/i686.iso', + // Add more mappings here if needed + }; + + // Check if the subpath exists in the mapping + if (baseTargetUrls[subpath]) { + const targetUrl = baseTargetUrls[subpath]; + return fetch(targetUrl, request); + } + + // Check if the subpath exists in test files + const testFileUrls = { + 'example': 'https://example.com' + // Add more test file mappings here if needed + }; + + if (testFileUrls[subpath]) { + const testFileUrl = testFileUrls[subpath]; + return fetch(testFileUrl, request); + } + } + + // Return a 404 response for other requests + return new Response('Not Found', { status: 404 }); +} +