2023-02-27 16:23:25 +00:00
|
|
|
var express = require('express');
|
|
|
|
var router = express.Router();
|
|
|
|
var ntr = require("../neutral-functions.js")
|
|
|
|
var fs = require("fs")
|
|
|
|
var path = require("path")
|
2023-03-22 16:25:24 +00:00
|
|
|
var mime = require('mime-types');
|
|
|
|
const { compileString } = require('sass');
|
2023-02-27 16:23:25 +00:00
|
|
|
|
|
|
|
/* GET home page. */
|
|
|
|
router.get('/', function(req, res, next) {
|
|
|
|
|
|
|
|
|
|
|
|
var check = ntr.checkToken(req, res)
|
|
|
|
|
|
|
|
if(check.name != false) {
|
|
|
|
|
|
|
|
res.redirect(302, "/")
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
res.render('login', {error: ""});
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
router.post("/", function(req, res, next) {
|
|
|
|
|
|
|
|
var check = ntr.checkToken(req, res)
|
|
|
|
|
|
|
|
if(check.name == false) {
|
|
|
|
|
|
|
|
res.send({"result":"failed", "content":"ERROR_TOKEN_NOT_VALID"})
|
|
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if(check.permLevel >= 3) {
|
|
|
|
|
|
|
|
const bod = req.body
|
|
|
|
|
|
|
|
if(bod.request == "add") {
|
|
|
|
|
|
|
|
res.send({"result":"failed", "content":"ERROR_NOT_MAKE"})
|
|
|
|
|
|
|
|
} else if(bod.request == "get") {
|
|
|
|
|
|
|
|
var files = new Array()
|
|
|
|
const directory = req.body.value
|
|
|
|
fs.readdir(directory.replace("/", path.sep.replace("\\", path.sep)), (err, data) => {
|
|
|
|
|
|
|
|
if(err) {
|
|
|
|
res.send({"result":"success", "content": "ERROR_NOT_EXIST"})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
for(var file of data) {
|
|
|
|
|
|
|
|
|
|
|
|
const stat = fs.statSync(directory.replace("/", path.sep.replace("\\", path.sep)) + path.sep + file)
|
|
|
|
|
2023-03-22 16:25:24 +00:00
|
|
|
files.push({"name":file, "fileDirectory" :directory.replace("/", path.sep.replace("\\", path.sep)) + path.sep + file , "type":mime.lookup(file), "size":stat.size, "lastedition":stat.mtimeMs, "directory":stat.isDirectory()})
|
2023-02-27 16:23:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
res.send({"result":"success", "content": files})
|
|
|
|
|
|
|
|
|
|
|
|
} catch(err) {
|
|
|
|
|
|
|
|
res.send({"result":"success", "content": "ERROR_NOT_PERMITTED"})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else if(bod.request == "del") {
|
2023-03-22 16:25:24 +00:00
|
|
|
|
2023-03-22 19:41:41 +00:00
|
|
|
const file = bod.value
|
|
|
|
|
2023-03-22 16:25:24 +00:00
|
|
|
if(fs.existsSync(bod.value.fileDirectory) == false) {
|
|
|
|
res.send({"result":"success", "content":"ERROR_NOT_EXIST"})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if(file.directory == true) {
|
2023-03-23 17:24:43 +00:00
|
|
|
fs.rmdirSync(file.fileDirectory , { recursive: true, force: true })
|
2023-03-22 16:25:24 +00:00
|
|
|
|
|
|
|
} else {
|
|
|
|
fs.rmSync(file.fileDirectory)
|
2023-03-22 19:41:41 +00:00
|
|
|
|
2023-03-22 16:25:24 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
console.log("DELETED")
|
|
|
|
res.send({"result":"success", "content":"DELETED"})
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
|
|
|
|
console.log(error)
|
|
|
|
console.log("NOT DELETED")
|
|
|
|
res.send({"result":"success", "content":"ERROR_NOT_MAKEABLE"})
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log("NOT DELETED")
|
|
|
|
|
|
|
|
}
|
2023-02-27 16:23:25 +00:00
|
|
|
|
|
|
|
} else if(bod.request == "rename") {
|
|
|
|
|
2023-03-22 19:41:41 +00:00
|
|
|
if(fs.existsSync(bod.value) == true) {
|
|
|
|
res.send({"result":"success", "content":"ERROR_ALREADY_EXIST"})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
fs.renameSync(bod.currentDir, bod.value)
|
|
|
|
res.send({"result":"success", "content":"RENAMED"})
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
console.log(error)
|
|
|
|
res.send({"result":"success", "content":"ERROR_NOT_MAKEABLE"})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2023-02-27 16:23:25 +00:00
|
|
|
|
2023-03-22 16:25:24 +00:00
|
|
|
} else if(bod.request == "addfolder") {
|
|
|
|
|
|
|
|
|
|
|
|
if(fs.existsSync(bod.currentDir + path.sep + bod.value) == true) {
|
|
|
|
res.send({"result":"success", "content":"ERROR_ALREADY_EXIST"})
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
try {
|
|
|
|
fs.mkdirSync(bod.currentDir + path.sep + bod.value)
|
|
|
|
res.send({"result":"success", "content":"CREATED"})
|
|
|
|
|
|
|
|
} catch(error) {
|
|
|
|
console.log(error)
|
|
|
|
res.send({"result":"success", "content":"ERROR_NOT_MAKEABLE"})
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-02-27 16:23:25 +00:00
|
|
|
} else {
|
|
|
|
res.send({"result":"failed", "content":"ERROR_REQUEST_MISSING_FIELDS", "additional": "REQUEST_MISSING"})
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
res.send({"result":"failed", "content":"ERROR_USER_PERMISSION_TOO_LOW"})
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
module.exports = router;
|