初始化提交
This commit is contained in:
47
common/modules/mixly-modules/web/file-tree.js
Normal file
47
common/modules/mixly-modules/web/file-tree.js
Normal file
@@ -0,0 +1,47 @@
|
||||
goog.loadJs('web', () => {
|
||||
|
||||
goog.require('path');
|
||||
goog.require('Mixly.FileTree');
|
||||
goog.require('Mixly.Web.FS');
|
||||
goog.provide('Mixly.Web.FileTree');
|
||||
|
||||
const { FileTree, Web } = Mixly;
|
||||
const { FS } = Web;
|
||||
|
||||
class FileTreeExt extends FileTree {
|
||||
constructor(element, mprogress) {
|
||||
super(element, mprogress, FS);
|
||||
}
|
||||
|
||||
async readFolder(inPath) {
|
||||
const fs = this.getFS();
|
||||
const status = await fs.isDirectory(inPath);
|
||||
let output = [];
|
||||
if (!status) {
|
||||
return output;
|
||||
}
|
||||
const children = await fs.readDirectory(inPath);
|
||||
for (let data of children) {
|
||||
const dataPath = path.join(inPath, data);
|
||||
if (await fs.isDirectory(dataPath)) {
|
||||
const isDirEmpty = await fs.isDirectoryEmpty(dataPath);
|
||||
output.push({
|
||||
type: 'folder',
|
||||
id: dataPath,
|
||||
children: !isDirEmpty
|
||||
});
|
||||
} else {
|
||||
output.push({
|
||||
type: 'file',
|
||||
id: dataPath,
|
||||
children: false
|
||||
});
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
Web.FileTree = FileTreeExt;
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user