mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-07-29 18:25:47 +02:00
Refactor: split main.js into app/ modules
This commit is contained in:
32
app/pathValidator.js
Normal file
32
app/pathValidator.js
Normal file
@@ -0,0 +1,32 @@
|
||||
const fs = require("fs");
|
||||
const path = require("path");
|
||||
const { logger } = require("../server/logger");
|
||||
|
||||
let _defaultPath = null;
|
||||
|
||||
function getDefaultDownloadPath() {
|
||||
if (!_defaultPath) {
|
||||
const { defaultDownloadFolder } = require("../server/helpers/path.helpers");
|
||||
_defaultPath = defaultDownloadFolder;
|
||||
}
|
||||
return _defaultPath;
|
||||
}
|
||||
|
||||
function validateDownloadPath(userPath) {
|
||||
const { isSafePath } = require("../server/helpers/validation.helpers");
|
||||
|
||||
if (!userPath) return getDefaultDownloadPath();
|
||||
|
||||
try {
|
||||
const resolved = fs.realpathSync(path.resolve(userPath));
|
||||
if (!isSafePath(resolved)) {
|
||||
throw new Error("Path not allowed: system folders are blocked!");
|
||||
}
|
||||
return resolved;
|
||||
} catch (err) {
|
||||
logger.error(`Invalid download path: ${userPath} — ${err.message}`);
|
||||
throw new Error(`Invalid or inaccessible path: ${err.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = { validateDownloadPath, getDefaultDownloadPath };
|
||||
Reference in New Issue
Block a user