mirror of
https://github.com/ragestudio/linebridge.git
synced 2025-06-09 18:44:17 +00:00
added example servers
This commit is contained in:
parent
9c2ac1fea1
commit
4e7c3feabb
@ -1,10 +0,0 @@
|
|||||||
|
|
||||||
module.exports = {
|
|
||||||
default: (req, res, next) => {
|
|
||||||
const { files } = req
|
|
||||||
if (typeof files.file !== "undefined") {
|
|
||||||
const { data, name, size, mimetype, md5 } = files.file
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,7 +0,0 @@
|
|||||||
[
|
|
||||||
{
|
|
||||||
"method": "PUT",
|
|
||||||
"route": "/upload",
|
|
||||||
"controller": "upload"
|
|
||||||
}
|
|
||||||
]
|
|
@ -0,0 +1,48 @@
|
|||||||
|
const { Storage } = require('@@classes')
|
||||||
|
const path = require('path')
|
||||||
|
const { performance } = require('perf_hooks')
|
||||||
|
|
||||||
|
// TODO: Access token, permission object type
|
||||||
|
|
||||||
|
const handler = new Storage({ driver: "fs", root: path.resolve(process.cwd(), "uploads") })
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
set: (req, res, next) => {
|
||||||
|
const { files } = req
|
||||||
|
if (typeof files.file !== "undefined") {
|
||||||
|
let file = files.file
|
||||||
|
|
||||||
|
file.name = `${file.md5}_${file.name}`
|
||||||
|
|
||||||
|
const timeBefore = performance.now()
|
||||||
|
handler.setSync(file, undefined)
|
||||||
|
.then((stat) => {
|
||||||
|
const tooks = (performance.now() - timeBefore).toFixed(2)
|
||||||
|
return res.json({
|
||||||
|
tooks: `~${tooks}ms`,
|
||||||
|
filename: file.name,
|
||||||
|
mimetype: file.mimetype,
|
||||||
|
encoding: file.encoding,
|
||||||
|
size: stat.size
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
get: (req, res, next) => {
|
||||||
|
const { query } = req
|
||||||
|
if (typeof query.file === "undefined") {
|
||||||
|
res.status(404)
|
||||||
|
return res.json({ error: "Not provided filename" })
|
||||||
|
}
|
||||||
|
|
||||||
|
handler.getSync(query.file)
|
||||||
|
.then((data) => {
|
||||||
|
res.write(data.buffer, 'binary')
|
||||||
|
res.end(null, 'binary')
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
res.status(404)
|
||||||
|
res.json({ error: error.message })
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
14
packages/server/examples/uploadServer/endpoints.json
Normal file
14
packages/server/examples/uploadServer/endpoints.json
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"method": "PUT",
|
||||||
|
"route": "/upload",
|
||||||
|
"controller": "filecontroller",
|
||||||
|
"fn": "set"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"method": "GET",
|
||||||
|
"route": "/resources",
|
||||||
|
"controller": "filecontroller",
|
||||||
|
"fn": "get"
|
||||||
|
}
|
||||||
|
]
|
10
packages/server/examples/uploadServer/package.json
Normal file
10
packages/server/examples/uploadServer/package.json
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"name": "uploadServer",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"scripts": {
|
||||||
|
"start": "relic-server ."
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@ragestudio/relic-server": "^0.2.2"
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user