-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathworker.js
More file actions
100 lines (77 loc) · 2.45 KB
/
worker.js
File metadata and controls
100 lines (77 loc) · 2.45 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
import { serve } from "https://deno.land/std@0.140.0/http/server.ts"
async function handleXingtie(req) {
const { search } = new URL(req.url)
const api = 'https://api-takumi.mihoyo.com/common/gacha_record/api/getGachaLog' + search
const data = await fetch(api, {
headers: {
"Host": "api-takumi.mihoyo.com",
"User-Agent":
"Mozilla/ 5.0(Windows NT 10.0; Win64; x64) AppleWebKit / 537.36(KHTML, like Gecko) Chrome / 114.0.0.0 Safari / 537.36"
}
}).then(res => res.json())
return new Response(JSON.stringify(data), {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
})
}
async function getJs(url) {
const data = await fetch(url, {
}).then(res => res.text())
return new Response(data, {
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*"
}
})
}
async function handler(req) {
const { pathname } = new URL(req.url)
if (pathname.includes('xingtie_chouka')) {
return handleXingtie(req)
}
const entries = []
if (pathname === '/slave.js' || pathname === '/master.js') {
return getJs("https://npm.elemecdn.com/smallapp@latest/runtime/dist/" + pathname)
}
for await (const entry of Deno.readDir(`./dist`)) {
entries.push(entry)
}
const file2 = entries.find(i => {
console.log(pathname, i.name)
return pathname.slice(1) === i.name
})
if (file2 && file2.name) {
const str = await Deno.readFile(`./dist/${file2.name}`)
return new Response(str, {
headers: {
"content-type": file2.name.includes('json') ? 'application/json' : file2.name.includes('css') ? "text/css" : "application/javascript"
}
})
}
const str = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fre miniapp</title>
<link rel="stylesheet" href="https://miniapp.deno.dev/default.css">
</head>
<body>
<script src="/slave.js"></script>
<script>
const worker = new Worker('/master.js')
fakedom({ worker })
</script>
</body>
</html>`
return new Response(str, {
headers: {
"content-type": "text/html",
}
})
}
serve(handler)