File size: 1,150 Bytes
508c141
 
746b714
508c141
746b714
 
508c141
746b714
 
 
 
3b83dec
 
 
 
 
 
 
 
 
 
1caa4a9
3b83dec
10b728b
 
 
 
 
9936060
10b728b
 
 
9936060
837e8c5
 
 
 
 
39b6fb9
837e8c5
3b83dec
 
 
508c141
 
746b714
 
508c141
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
import crc32 from './crc32.js'
import http from 'axios'
import express from 'express'

const app = express()
const port = 7860

app.use(express.json())
app.use(express.urlencoded({ extended: true }))

app.get('*', async (req, res) => {
  try {
    const file_url = req.path.replace(/^\//, '')
    const file = await http({
      method: 'GET',
      url: file_url,
      responseType: 'arraybuffer'
    })
    const hash = crc32(file.data)
    const upload_info = await http({
      method: 'GET',
      url: 'https://data.emmmm.eu.org/upload/sg'
    })
    const upload_result = await http({
      method: 'POST',
      url: upload_info.data.url,
      headers: {
        'content-crc32': hash,
        'authorization': upload_info.data.authorization
      },
      data: file.data
    })
    if (upload_result.status == 200) {
      res.send(JSON.stringify({
        vid: upload_info.data.vid,
        url: `https://sf16-sg-default.akamaized.net/obj/${upload_info.data.uri}`
      }))
    } else {
      throw Error
    }
  } catch (e) {
    res.send(e.toString())
  }
})

app.listen(port, async () => {
  console.log(`http://localhost:${port}`)
})