mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
/stuff file browser, minor tweaks
This commit is contained in:
parent
8091c2d4e9
commit
e9c2df8e9b
5 changed files with 81 additions and 11 deletions
75
server.js
75
server.js
|
@ -35,6 +35,7 @@ const utils = require('./utils.js');
|
|||
const actions = require('./actions.js');
|
||||
const stat = require('./stat.js');
|
||||
|
||||
const listedFiles = "./public/files";
|
||||
const recivedFiles = "public/recivedfiles";
|
||||
const uloadFiles = "public/f";
|
||||
const staticFile = "public/data/static";
|
||||
|
@ -84,9 +85,9 @@ app.use(function(req, res, next) {
|
|||
});
|
||||
app.use(express.static('public'));
|
||||
app.use(busboy({
|
||||
limits: {
|
||||
fileSize: 10 * 1024 * 1024
|
||||
}
|
||||
limits: {
|
||||
fileSize: 10000 * 1024 * 1024
|
||||
}
|
||||
}));
|
||||
app.use(bodyParser.json());
|
||||
app.use(bodyParser.urlencoded({
|
||||
|
@ -97,6 +98,8 @@ app.use(bodyParser.json({
|
|||
limit: '5mb'
|
||||
}));
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
app.get('/', function(req, res) {
|
||||
res.render('main', {
|
||||
siteurl: siteUrl,
|
||||
|
@ -225,9 +228,7 @@ function UploadFile(req, res, path, next) {
|
|||
|
||||
utils.CreatePath(path, true);
|
||||
let d = new Date();
|
||||
let fsplit = filename.split('.');
|
||||
let fn = d.getHours() + "" + d.getMinutes() + "" + d.getSeconds() + "." + fsplit[fsplit.length -
|
||||
1];
|
||||
let fn = d.getHours() + "" + d.getMinutes() + "" + d.getSeconds() + "_" + filename;
|
||||
|
||||
fstream = fs.createWriteStream(path + "/" + fn);
|
||||
file.pipe(fstream);
|
||||
|
@ -255,6 +256,68 @@ app.route('/badtestsender').post(function(req, res, next) {
|
|||
logger.LogReq(req);
|
||||
});
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
return;
|
||||
});
|
||||
|
||||
|
||||
// -----------------------------------------------------------------------------------------------
|
||||
|
||||
app.get('*', function(req, res) {
|
||||
res.render('404');
|
||||
res.status(404);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue