mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
stuff module
This commit is contained in:
parent
e5fd0aba13
commit
da9c73b5cc
2 changed files with 124 additions and 56 deletions
modules
|
@ -21,7 +21,6 @@
|
|||
const express = require('express')
|
||||
const bodyParser = require('body-parser')
|
||||
const busboy = require('connect-busboy')
|
||||
const fs = require('fs')
|
||||
const app = express()
|
||||
|
||||
const logger = require('../utils/logger.js')
|
||||
|
@ -30,8 +29,6 @@ const logger = require('../utils/logger.js')
|
|||
const stat = require('../utils/stat.js')
|
||||
stat.Load()
|
||||
|
||||
const listedFiles = '../public/files'
|
||||
|
||||
app.set('view engine', 'ejs')
|
||||
app.use(function (req, res, next) {
|
||||
res.on('finish', function () {
|
||||
|
@ -62,59 +59,6 @@ app.get('/', function (req, res) {
|
|||
res.end('henlo')
|
||||
})
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
app.get('/stuff*', function (req, res) {
|
||||
let curr = listedFiles + '/' + req.url.substring('/stuff/'.length, req.url.length).split('?')[0]
|
||||
let relPath = curr.substring('./public/files'.length, curr.length)
|
||||
|
||||
if (relPath[relPath.length - 1] !== '/') { relPath += '/' }
|
||||
|
||||
let t = relPath.split('/')
|
||||
let prevDir = ''
|
||||
for (let i = 0; i < t.length - 2; i++) { prevDir += t[i] + '/' }
|
||||
|
||||
// curr = curr.replace(/\//g, "/");
|
||||
// relPath = relPath.replace(/\//g, "/");
|
||||
|
||||
logger.LogReq(req)
|
||||
|
||||
if (fs.lstatSync(curr).isDirectory()) {
|
||||
if (curr[curr.length - 1] !== '/') { curr += '/' }
|
||||
|
||||
let f = []
|
||||
|
||||
fs.readdirSync(curr).forEach((item) => {
|
||||
if (item[0] !== '.') {
|
||||
let res = { name: item }
|
||||
let stats = fs.statSync(curr + '/' + item)
|
||||
|
||||
let fileSizeInBytes = stats['size']
|
||||
res.size = Math.round(fileSizeInBytes / 1000000)
|
||||
|
||||
res.path = relPath
|
||||
if (res.path[res.path.length - 1] !== '/') { res.path += '/' }
|
||||
res.path += item
|
||||
|
||||
res.mtime = stats['mtime'].toLocaleString()
|
||||
|
||||
f.push(res)
|
||||
}
|
||||
})
|
||||
|
||||
res.render('folders', {
|
||||
folders: f,
|
||||
dirname: relPath,
|
||||
prevDir
|
||||
})
|
||||
} else {
|
||||
let fileStream = fs.createReadStream(curr)
|
||||
fileStream.pipe(res)
|
||||
}
|
||||
})
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
app.get('*', function (req, res) {
|
||||
res.render('404')
|
||||
res.status(404)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue