@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/package.json
CHANGED
|
@@ -215,6 +215,42 @@ function resolveSafePath(requestedPath: string): string {
|
|
|
215
215
|
return resolved;
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
+
function listDirectoryEntriesSafe(dirPath: string): Array<{ name: string; type: 'directory' | 'file'; size?: number }> {
|
|
219
|
+
const entries = fs.readdirSync(dirPath, { withFileTypes: true });
|
|
220
|
+
const files: Array<{ name: string; type: 'directory' | 'file'; size?: number }> = [];
|
|
221
|
+
|
|
222
|
+
for (const entry of entries) {
|
|
223
|
+
const entryPath = path.join(dirPath, entry.name);
|
|
224
|
+
try {
|
|
225
|
+
if (entry.isDirectory()) {
|
|
226
|
+
files.push({ name: entry.name, type: 'directory' });
|
|
227
|
+
continue;
|
|
228
|
+
}
|
|
229
|
+
if (entry.isFile()) {
|
|
230
|
+
let size: number | undefined;
|
|
231
|
+
try {
|
|
232
|
+
size = fs.statSync(entryPath).size;
|
|
233
|
+
} catch {
|
|
234
|
+
size = undefined;
|
|
235
|
+
}
|
|
236
|
+
files.push({ name: entry.name, type: 'file', size });
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
const stat = fs.statSync(entryPath);
|
|
241
|
+
files.push({
|
|
242
|
+
name: entry.name,
|
|
243
|
+
type: stat.isDirectory() ? 'directory' : 'file',
|
|
244
|
+
size: stat.isFile() ? stat.size : undefined,
|
|
245
|
+
});
|
|
246
|
+
} catch {
|
|
247
|
+
// Skip inaccessible entries such as protected Windows root files.
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return files;
|
|
252
|
+
}
|
|
253
|
+
|
|
218
254
|
export async function handleFileRead(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
219
255
|
try {
|
|
220
256
|
const filePath = resolveSafePath(args?.path);
|
|
@@ -239,12 +275,7 @@ export async function handleFileWrite(h: CommandHelpers, args: any): Promise<Com
|
|
|
239
275
|
export async function handleFileList(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
240
276
|
try {
|
|
241
277
|
const dirPath = resolveSafePath(args?.path || '.');
|
|
242
|
-
const
|
|
243
|
-
const files = entries.map(e => ({
|
|
244
|
-
name: e.name,
|
|
245
|
-
type: e.isDirectory() ? 'directory' : 'file',
|
|
246
|
-
size: e.isFile() ? fs.statSync(path.join(dirPath, e.name)).size : undefined,
|
|
247
|
-
}));
|
|
278
|
+
const files = listDirectoryEntriesSafe(dirPath);
|
|
248
279
|
return { success: true, files, path: dirPath };
|
|
249
280
|
} catch (e: any) {
|
|
250
281
|
return { success: false, error: e.message };
|
|
@@ -252,5 +283,13 @@ export async function handleFileList(h: CommandHelpers, args: any): Promise<Comm
|
|
|
252
283
|
}
|
|
253
284
|
|
|
254
285
|
export async function handleFileListBrowse(h: CommandHelpers, args: any): Promise<CommandResult> {
|
|
255
|
-
|
|
286
|
+
try {
|
|
287
|
+
const dirPath = resolveSafePath(args?.path || '.');
|
|
288
|
+
const files = listDirectoryEntriesSafe(dirPath)
|
|
289
|
+
.filter(entry => entry.type === 'directory')
|
|
290
|
+
.sort((a, b) => a.name.localeCompare(b.name));
|
|
291
|
+
return { success: true, files, path: dirPath };
|
|
292
|
+
} catch (e: any) {
|
|
293
|
+
return { success: false, error: e.message };
|
|
294
|
+
}
|
|
256
295
|
}
|