test / index.js
asdass1's picture
Update index.js
1caa4a9 verified
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}`)
})