asdass1 commited on
Commit
508c141
·
verified ·
1 Parent(s): 482498d

Create index.js

Browse files
Files changed (1) hide show
  1. index.js +33 -0
index.js ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import crc32 from './crc32.js'
2
+ import http from 'axios'
3
+ import koa from 'koa'
4
+
5
+ const app = new koa
6
+
7
+ app.use(async ctx => {
8
+ const file_url = ctx.path.replace(/^\//, '')
9
+ const file = await http({
10
+ method: 'GET',
11
+ url: file_url,
12
+ responseType: 'arraybuffer'
13
+ })
14
+ const hash = crc32(file.data)
15
+ const upload_info = await http({
16
+ method: 'GET',
17
+ url: 'https://api.xs.cx/upload/sg'
18
+ })
19
+ const upload_result = await http({
20
+ method: 'POST',
21
+ url: upload_info.url,
22
+ headers: {
23
+ 'content-crc32': hash,
24
+ 'authorization': upload_info.authorization
25
+ },
26
+ data: file.data
27
+ })
28
+ ctx.body = upload_result.data
29
+ })
30
+
31
+ app.listen(3000, () => {
32
+ console.log('3000')
33
+ })