mirror of
https://github.com/mudabbir-ahmad/Media-Aggregation-and-Sorting-System.git
synced 2026-10-07 19:40:20 +00:00
feat: update NAS configuration and enhance UI components for better user experience
This commit is contained in:
1 parent
8e6fa5270b
commit
6167418074
23 files changed
+2147
-702
No files matched your search
@@ -0,0 +1,56 @@
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
|
||||
const CONFIG_DIR = path.join(__dirname, '.config');
|
||||
const PHOTOS_PATH_FILE = path.join(__dirname, 'nas_config.txt');
|
||||
const DB_PATH = path.join(CONFIG_DIR, 'nas.db');
|
||||
const PASSWORD_FILE = path.join(CONFIG_DIR, '.credentials');
|
||||
const DEFAULT_PORT = 9500;
|
||||
|
||||
function ensureConfigDir() {
|
||||
if (!fs.existsSync(CONFIG_DIR)) {
|
||||
fs.mkdirSync(CONFIG_DIR, { recursive: true });
|
||||
}
|
||||
}
|
||||
|
||||
function getPhotosPath() {
|
||||
if (!fs.existsSync(PHOTOS_PATH_FILE)) return null;
|
||||
|
||||
let raw = fs.readFileSync(PHOTOS_PATH_FILE, 'utf-8');
|
||||
|
||||
// Strip UTF-8 BOM
|
||||
raw = raw.replace(/^\uFEFF/, '');
|
||||
// Strip ALL control characters (CR, LF, null, tabs, zero-width spaces, etc.)
|
||||
// except forward-slash and backslash which are path separators
|
||||
raw = raw.replace(/[\x00-\x09\x0B\x0C\x0E-\x1F\x7F\r\n]/g, '');
|
||||
// Strip zero-width / non-breaking unicode junk that can sneak in from copy-paste
|
||||
raw = raw.replace(/[\u200B\u200C\u200D\uFEFF\u00A0]/g, '');
|
||||
raw = raw.trim();
|
||||
|
||||
// Take only the first line in case there are multiple lines
|
||||
raw = raw.split('\n')[0].trim();
|
||||
|
||||
if (!raw) return null;
|
||||
|
||||
// Return the path exactly as written — do NOT use path.resolve()
|
||||
// because it mangles Linux paths on Windows and vice versa
|
||||
return raw;
|
||||
}
|
||||
|
||||
function setPhotosPath(p) {
|
||||
// Clean and write as plain UTF-8 with unix line ending, no BOM
|
||||
const clean = p.replace(/[\r\n\x00]/g, '').trim();
|
||||
fs.writeFileSync(PHOTOS_PATH_FILE, clean, 'utf-8');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
CONFIG_DIR,
|
||||
PHOTOS_PATH_FILE,
|
||||
DB_PATH,
|
||||
PASSWORD_FILE,
|
||||
DEFAULT_PORT,
|
||||
ensureConfigDir,
|
||||
getPhotosPath,
|
||||
setPhotosPath,
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user