Update index.js
Browse files
index.js
CHANGED
|
@@ -9,27 +9,31 @@ app.use(express.json())
|
|
| 9 |
app.use(express.urlencoded({ extended: true }))
|
| 10 |
|
| 11 |
app.get('*', async (req, res) => {
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
})
|
| 34 |
|
| 35 |
app.listen(port, async () => {
|
|
|
|
| 9 |
app.use(express.urlencoded({ extended: true }))
|
| 10 |
|
| 11 |
app.get('*', async (req, res) => {
|
| 12 |
+
try {
|
| 13 |
+
const file_url = req.path.replace(/^\//, '')
|
| 14 |
+
const file = await http({
|
| 15 |
+
method: 'GET',
|
| 16 |
+
url: file_url,
|
| 17 |
+
responseType: 'arraybuffer'
|
| 18 |
+
})
|
| 19 |
+
const hash = crc32(file.data)
|
| 20 |
+
const upload_info = await http({
|
| 21 |
+
method: 'GET',
|
| 22 |
+
url: 'https://api.xs.cx/upload/sg'
|
| 23 |
+
})
|
| 24 |
+
const upload_result = await http({
|
| 25 |
+
method: 'POST',
|
| 26 |
+
url: upload_info.url,
|
| 27 |
+
headers: {
|
| 28 |
+
'content-crc32': hash,
|
| 29 |
+
'authorization': upload_info.authorization
|
| 30 |
+
},
|
| 31 |
+
data: file.data
|
| 32 |
+
})
|
| 33 |
+
res.send(upload_result.data)
|
| 34 |
+
} catch (e) {
|
| 35 |
+
res.send(e.toString())
|
| 36 |
+
}
|
| 37 |
})
|
| 38 |
|
| 39 |
app.listen(port, async () => {
|