@adhdev/daemon-core 0.8.4 → 0.8.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs
CHANGED
|
@@ -6833,6 +6833,37 @@ function resolveSafePath(requestedPath) {
|
|
|
6833
6833
|
}
|
|
6834
6834
|
return resolved;
|
|
6835
6835
|
}
|
|
6836
|
+
function listDirectoryEntriesSafe(dirPath) {
|
|
6837
|
+
const entries = fs4.readdirSync(dirPath, { withFileTypes: true });
|
|
6838
|
+
const files = [];
|
|
6839
|
+
for (const entry of entries) {
|
|
6840
|
+
const entryPath = path6.join(dirPath, entry.name);
|
|
6841
|
+
try {
|
|
6842
|
+
if (entry.isDirectory()) {
|
|
6843
|
+
files.push({ name: entry.name, type: "directory" });
|
|
6844
|
+
continue;
|
|
6845
|
+
}
|
|
6846
|
+
if (entry.isFile()) {
|
|
6847
|
+
let size;
|
|
6848
|
+
try {
|
|
6849
|
+
size = fs4.statSync(entryPath).size;
|
|
6850
|
+
} catch {
|
|
6851
|
+
size = void 0;
|
|
6852
|
+
}
|
|
6853
|
+
files.push({ name: entry.name, type: "file", size });
|
|
6854
|
+
continue;
|
|
6855
|
+
}
|
|
6856
|
+
const stat = fs4.statSync(entryPath);
|
|
6857
|
+
files.push({
|
|
6858
|
+
name: entry.name,
|
|
6859
|
+
type: stat.isDirectory() ? "directory" : "file",
|
|
6860
|
+
size: stat.isFile() ? stat.size : void 0
|
|
6861
|
+
});
|
|
6862
|
+
} catch {
|
|
6863
|
+
}
|
|
6864
|
+
}
|
|
6865
|
+
return files;
|
|
6866
|
+
}
|
|
6836
6867
|
async function handleFileRead(h, args) {
|
|
6837
6868
|
try {
|
|
6838
6869
|
const filePath = resolveSafePath(args?.path);
|
|
@@ -6855,19 +6886,20 @@ async function handleFileWrite(h, args) {
|
|
|
6855
6886
|
async function handleFileList(h, args) {
|
|
6856
6887
|
try {
|
|
6857
6888
|
const dirPath = resolveSafePath(args?.path || ".");
|
|
6858
|
-
const
|
|
6859
|
-
const files = entries.map((e) => ({
|
|
6860
|
-
name: e.name,
|
|
6861
|
-
type: e.isDirectory() ? "directory" : "file",
|
|
6862
|
-
size: e.isFile() ? fs4.statSync(path6.join(dirPath, e.name)).size : void 0
|
|
6863
|
-
}));
|
|
6889
|
+
const files = listDirectoryEntriesSafe(dirPath);
|
|
6864
6890
|
return { success: true, files, path: dirPath };
|
|
6865
6891
|
} catch (e) {
|
|
6866
6892
|
return { success: false, error: e.message };
|
|
6867
6893
|
}
|
|
6868
6894
|
}
|
|
6869
6895
|
async function handleFileListBrowse(h, args) {
|
|
6870
|
-
|
|
6896
|
+
try {
|
|
6897
|
+
const dirPath = resolveSafePath(args?.path || ".");
|
|
6898
|
+
const files = listDirectoryEntriesSafe(dirPath).filter((entry) => entry.type === "directory").sort((a, b) => a.name.localeCompare(b.name));
|
|
6899
|
+
return { success: true, files, path: dirPath };
|
|
6900
|
+
} catch (e) {
|
|
6901
|
+
return { success: false, error: e.message };
|
|
6902
|
+
}
|
|
6871
6903
|
}
|
|
6872
6904
|
|
|
6873
6905
|
// src/commands/stream-commands.ts
|