-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
67 lines (57 loc) · 1.88 KB
/
worker.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const PROXY = 'multiverproxy.unethical.team';
const YML_URL = 'https://launcherupdates.lunarclientcdn.com/latest.yml';
let ymlContent = '';
let latestVersion = '1.0.0';
addEventListener('fetch', (event) => {
event.respondWith(handleRequest(event.request));
});
async function fetchLatestLauncherVersion() {
if (ymlContent) return latestVersion;
try {
const response = await fetch(YML_URL);
if (response.ok) {
ymlContent = await response.text();
const match = ymlContent.match(/version: (.+)/);
latestVersion = match && match[1] ? match[1] : '1.0.0';
} else {
throw new Error(`Failed to fetch YML content: ${response.status} ${response.statusText}`);
}
return latestVersion;
} catch (error) {
throw new Error(`Failed to fetch latest launcher version: ${error.message}`);
}
}
async function handleRequest(request) {
try {
if (request.headers.get('host') !== PROXY) {
return new Response('Access Denied.', {
status: 403,
});
}
const launcherVersion = await fetchLatestLauncherVersion();
const targetURL = 'https://api.lunarclientprod.com/launcher/launch';
const headers = {
'Content-Type': 'application/json; charset=UTF-8',
'User-Agent': `Lunar Client Launcher v${launcherVersion}`,
};
const response = await fetch(targetURL, {
method: 'POST',
headers: headers,
body: JSON.stringify({
version: '1.8.9',
branch: 'master',
os: 'win32',
arch: 'x64',
launcher_version: launcherVersion,
hwid: '0',
}),
});
if (!response.ok) {
throw new Error(`Request to Lunar Client API failed with status ${response.status}`);
}
return response;
} catch (error) {
console.error('Error in handleRequest:', error);
return new Response('An error occurred while processing the request.', { status: 500 });
}
}