2025-03-07 13:14:32 +01:00
|
|
|
import path from "path";
|
|
|
|
|
import fs from "fs";
|
|
|
|
|
import { filesystemSync } from "fs-filesystem";
|
|
|
|
|
|
|
|
|
|
export class FsService {
|
|
|
|
|
getAvailableRoots = () => {
|
|
|
|
|
const devices = filesystemSync();
|
|
|
|
|
var mountPoints = [];
|
|
|
|
|
Object.keys(devices).forEach(function (key) {
|
|
|
|
|
var val = devices[key];
|
|
|
|
|
val.volumes.forEach(function (volume) {
|
|
|
|
|
mountPoints.push(volume.mountPoint);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (mountPoints.length < 1) {
|
|
|
|
|
throw new Error("Failed to detect file system devices.");
|
|
|
|
|
}
|
|
|
|
|
return mountPoints;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
pathJoin = (parts) => {
|
|
|
|
|
return path.join(...parts);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
isDir = (dir) => {
|
|
|
|
|
try {
|
|
|
|
|
return fs.lstatSync(dir).isDirectory();
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-08 15:13:24 +02:00
|
|
|
isFile = (path) => {
|
|
|
|
|
try {
|
|
|
|
|
return fs.lstatSync(path).isFile();
|
|
|
|
|
} catch {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2025-03-07 13:14:32 +01:00
|
|
|
readDir = (dir) => {
|
|
|
|
|
return fs.readdirSync(dir);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
makeDir = (dir) => {
|
|
|
|
|
fs.mkdirSync(dir);
|
|
|
|
|
};
|
2025-04-07 16:01:49 +02:00
|
|
|
|
|
|
|
|
moveDir = (oldPath, newPath) => {
|
|
|
|
|
fs.moveSync(oldPath, newPath);
|
|
|
|
|
};
|
2025-04-09 10:27:00 +02:00
|
|
|
|
|
|
|
|
deleteDir = (dir) => {
|
|
|
|
|
fs.rmSync(dir, { recursive: true, force: true });
|
|
|
|
|
};
|
2025-03-07 13:14:32 +01:00
|
|
|
}
|