-
Notifications
You must be signed in to change notification settings - Fork 8
/
filesystem.ts
33 lines (30 loc) · 900 Bytes
/
filesystem.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// @ts-ignore
import fs from "fs";
// @ts-ignore
import path from "path";
import mime from "mime";
export type typeFile = {
name: string,
mime: string,
isDir: boolean,
sub?: Array<typeFile>
}
function recursiveReadDir(dirs: Array<string>, array: Array<typeFile>){
// @ts-ignore
for (const dirent of fs.readdirSync(path.resolve(__dirname, ...['public'].concat(dirs)), {withFileTypes: true})){
const isDir = dirent.isDirectory();
const file: typeFile = {
name: dirent.name,
mime: isDir?'folder':mime.getType(dirent.name),
isDir,
}
array.push(file);
if (file.isDir){
file.sub = [];
recursiveReadDir(dirs.slice().concat(dirent.name), file.sub);
}
}
}
const dolphinFiles: Array<typeFile> = [];
recursiveReadDir(['dolphin-files'], dolphinFiles);
export {dolphinFiles}