forked from WildH0g/Medium-GAS-bypassing-max-exec-time
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile-structure.js
68 lines (58 loc) · 1.6 KB
/
file-structure.js
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// jshint esversion: 9
// jshint laxbreak: true
class Folder {
constructor(options) {
let { id, isRoot = false } = options;
const folder = DriveApp.getFolderById(id);
const subfolders = [];
const files = [];
const parent = isRoot ? null : folder.getParents().next().getId();
const name = folder.getName();
const _subfolders = folder.getFolders();
const _files = folder.getFiles();
while (_subfolders.hasNext()) {
subfolders.push(_subfolders.next().getId());
}
while (_files.hasNext()) {
const _id = _files.next().getId();
const _file = new File(_id);
files.push(_file.options);
}
return { id, name, parent, subfolders, files };
}
}
class File {
constructor(id) {
const file = DriveApp.getFileById(id);
const name = file.getName();
const mimeType = file.getMimeType();
const size = file.getSize();
this.options = { name, mimeType, id, size };
return this;
}
}
class FileStructure {
constructor(rootId) {
if (FileStructure.instance) return FileStructure.instance;
const root = !!rootId ? new Folder({ id: rootId, isRoot: true }) : null;
this.tree = {
root,
};
this.timer = new Timer();
this.timer.start();
// this.threshold = 5 * 60 * 1000;
this.threshold = 2 * 60 * 1000;
FileStructure.instance = this;
return FileStructure.instance;
}
addFolder(folderObj) {
if (this.tree && this.tree.root && this.tree.root.id === folderObj.id)
return;
this.tree[folderObj.id] = folderObj;
return this;
}
import(fs) {
this.tree = fs.tree;
return this;
}
}