forked from iSegaro/Subscription
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorkers.js
31 lines (26 loc) · 801 Bytes
/
Workers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
async function handleRequest(request) {
// How to create a subscribe link and give it to the family with iSegaro
const url = new URL(request.url);
const provider = url.searchParams.get("subs");
let links = [];
if (provider === "IRC") {
links = [
'xxxxxx',
'xxxxxx',
'xxxxxx'
];
} else if (provider === "MCI") {
links = [
'xxxxxx'
];
}
const responseText = links.join('\n').replace(/,(?=\n|$)/g, '');
// Encoding the response text in base64
const encodedResponse = btoa(responseText);
return new Response(encodedResponse, {
headers: { 'Content-Type': 'text/plain' },
});
}
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request));
});