-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsrc.ts
70 lines (64 loc) · 2.16 KB
/
src.ts
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
68
69
70
addEventListener("fetch", (event) => {
event.respondWith(
handleRequest(event.request).catch(
(err) => new Response(err.stack, { status: 500 })
)
);
});
let manifest = `<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>items</key>
<array>
<dict>
<key>assets</key>
<array>
<dict>
<key>kind</key>
<string>software-package</string>
<key>url</key>
<string>{{.DownloadUrl}}</string>
</dict>
</array>
<key>metadata</key>
<dict>
<key>bundle-identifier</key>
<string>{{.BundleId}}</string>
<key>bundle-version</key>
<string>2.0</string>
<key>kind</key>
<string>software</string>
<key>title</key>
<string>{{.Title}}</string>
</dict>
</dict>
</array>
</dict>
</plist>`
function escapeXml(unsafe) {
return unsafe.replace(/[<>&'"]/g, function (c) {
switch (c) {
case '<': return '<';
case '>': return '>';
case '&': return '&';
case '\'': return ''';
case '"': return '"';
}
});
}
async function handleRequest(request) {
const { searchParams } = new URL(request.url);
let ipa = searchParams.get("ipa");
let title = searchParams.get("title");
let id = searchParams.get("id");
if (ipa === null || title === null || id == null) {
return new Response(null, { status: 400 });
}
manifest = manifest.replace("{{.Title}}", escapeXml(title));
manifest = manifest.replace("{{.DownloadUrl}}", escapeXml(ipa));
manifest = manifest.replace("{{.BundleId}}", escapeXml(id));
return new Response(manifest, {
headers: { "Content-Type": "text/plain" },
});
}