mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-09 18:44:16 +00:00
use express static to server /storage
This commit is contained in:
parent
9fd287bc48
commit
d4812d44cc
@ -1,7 +1,7 @@
|
||||
import { Controller } from "linebridge/dist/server"
|
||||
import path from "path"
|
||||
import fs from "fs"
|
||||
import stream from "stream"
|
||||
//import stream from "stream"
|
||||
import pmap from "../../utils/pMap"
|
||||
|
||||
const formidable = require("formidable")
|
||||
@ -9,7 +9,7 @@ const formidable = require("formidable")
|
||||
function resolveToUrl(filepath, req) {
|
||||
const host = req ? (req.protocol + "://" + req.get("host")) : global.globalPublicURI
|
||||
|
||||
return `${host}/upload/${filepath}`
|
||||
return `${host}/storage/${filepath}`
|
||||
}
|
||||
|
||||
// TODO: Get maximunFileSize by type of user subscription (free, premium, etc) when `PermissionsAPI` is ready
|
||||
@ -64,31 +64,31 @@ function videoTranscode(originalFilePath, outputPath, options = {}) {
|
||||
}
|
||||
|
||||
export default class FilesController extends Controller {
|
||||
get = {
|
||||
"/upload/:id": {
|
||||
fn: (req, res) => {
|
||||
const filePath = path.join(global.uploadPath, req.params?.id)
|
||||
// get = {
|
||||
// "/upload/:id": {
|
||||
// fn: (req, res) => {
|
||||
// const filePath = path.join(global.uploadPath, req.params?.id)
|
||||
|
||||
const readStream = fs.createReadStream(filePath)
|
||||
const passTrough = new stream.PassThrough()
|
||||
// const readStream = fs.createReadStream(filePath)
|
||||
// const passTrough = new stream.PassThrough()
|
||||
|
||||
stream.pipeline(readStream, passTrough, (err) => {
|
||||
if (err) {
|
||||
return res.status(400)
|
||||
}
|
||||
})
|
||||
// stream.pipeline(readStream, passTrough, (err) => {
|
||||
// if (err) {
|
||||
// return res.status(400)
|
||||
// }
|
||||
// })
|
||||
|
||||
return passTrough.pipe(res)
|
||||
},
|
||||
}
|
||||
}
|
||||
// return passTrough.pipe(res)
|
||||
// },
|
||||
// }
|
||||
// }
|
||||
|
||||
post = {
|
||||
"/upload": {
|
||||
middlewares: ["withAuthentication"],
|
||||
fn: async (req, res) => {
|
||||
let failed = []
|
||||
|
||||
|
||||
// check directories exist
|
||||
if (!fs.existsSync(global.uploadCachePath)) {
|
||||
await fs.promises.mkdir(global.uploadCachePath, { recursive: true })
|
||||
|
@ -70,6 +70,8 @@ class Server {
|
||||
this.httpInstance.httpInterface.use(express.json())
|
||||
this.httpInstance.httpInterface.use(express.urlencoded({ extended: true }))
|
||||
|
||||
this.httpInstance.httpInterface.use("/storage", express.static(path.join(__dirname, "../uploads")))
|
||||
|
||||
this.httpInstance.wsInterface["clients"] = []
|
||||
this.httpInstance.wsInterface["findUserIdFromClientID"] = (searchClientId) => {
|
||||
return this.httpInstance.wsInterface.clients.find(client => client.id === searchClientId)?.userId ?? false
|
||||
|
Loading…
x
Reference in New Issue
Block a user