asdass1 commited on
Commit
3b83dec
·
verified ·
1 Parent(s): 9ea17d6

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +25 -21
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
- const file_url = req.path.replace(/^\//, '')
13
- const file = await http({
14
- method: 'GET',
15
- url: file_url,
16
- responseType: 'arraybuffer'
17
- })
18
- const hash = crc32(file.data)
19
- const upload_info = await http({
20
- method: 'GET',
21
- url: 'https://api.xs.cx/upload/sg'
22
- })
23
- const upload_result = await http({
24
- method: 'POST',
25
- url: upload_info.url,
26
- headers: {
27
- 'content-crc32': hash,
28
- 'authorization': upload_info.authorization
29
- },
30
- data: file.data
31
- })
32
- res.send(upload_result.data)
 
 
 
 
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 () => {