feat: access uploaded files through http
This commit is contained in:
@@ -10,6 +10,8 @@ import readline from 'node:readline'
|
|||||||
import process from "node:process"
|
import process from "node:process"
|
||||||
import chalk from "chalk"
|
import chalk from "chalk"
|
||||||
import child_process from "node:child_process"
|
import child_process from "node:child_process"
|
||||||
|
import FileManager from "./data/FileManager.ts"
|
||||||
|
import path from "node:path"
|
||||||
|
|
||||||
const app = express()
|
const app = express()
|
||||||
app.use((req, res, next) => {
|
app.use((req, res, next) => {
|
||||||
@@ -19,6 +21,23 @@ app.use((req, res, next) => {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
app.use('/', express.static(config.data_path + '/page_compiled'))
|
app.use('/', express.static(config.data_path + '/page_compiled'))
|
||||||
|
app.use('/uploaded_files/:hash', (req, res) => {
|
||||||
|
const hash = req.params.hash as string
|
||||||
|
if (hash == null) {
|
||||||
|
res.sendStatus(404)
|
||||||
|
res.send("404 Not Found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const file = FileManager.findByHash(hash)
|
||||||
|
if (file == null) {
|
||||||
|
res.sendStatus(404)
|
||||||
|
res.send("404 Not Found")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
res.setHeader('Content-Type', file!.getMime())
|
||||||
|
res.sendFile(path.resolve(file!.getFilePath()))
|
||||||
|
})
|
||||||
|
|
||||||
const httpServer: HttpServerLike = (
|
const httpServer: HttpServerLike = (
|
||||||
((config.server.use == 'http') && http.createServer(app)) ||
|
((config.server.use == 'http') && http.createServer(app)) ||
|
||||||
|
|||||||
Reference in New Issue
Block a user