-
Notifications
You must be signed in to change notification settings - Fork 1
/
discovery.js
106 lines (96 loc) · 2.97 KB
/
discovery.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
const { fileToJSON, logTree } = require("./utils");
async function exportFile(authClient) {
const fs = require("fs");
const drive = google.drive({ version: "v3", auth: authClient });
let res = await drive.files.export(
{
fileId: "1iIRtBHvpJbGgls8-jPNCViy-9USneCoDFt63yBogmVo",
mimeType:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
},
{
responseType: "stream",
},
);
let streamToSave = fs.createWriteStream("./sample.docx");
res.data.pipe(streamToSave);
streamToSave.on("finish", function () {
console.log("Proccess FInished");
streamToSave.close();
});
streamToSave.on("close", function () {
console.log("Stream closed");
});
streamToSave.on("error", function (error) {
console.log("ErrorStream:", error);
});
}
function findMaxSize(currentNode, maxSize) {
if (currentNode.mimeType !== "application/vnd.google-apps.folder") {
if ("size" in currentNode) return parseFloat(currentNode.size);
else return 0;
} else {
if (currentNode.children) {
let localMax = -1;
for (const child of currentNode.children) {
localMax = Math.max(findMaxSize(child, maxSize), localMax);
}
return Math.max(localMax, maxSize);
}
}
}
function findExceedingCount(path, currentNode, count) {
if (currentNode.mimeType !== "application/vnd.google-apps.folder") {
if ("size" in currentNode && parseFloat(currentNode.size) > 5) {
console.log(currentNode.size, path + currentNode.name);
return 1;
} else return 0;
} else {
if (currentNode.children) {
let localCount = 0;
for (const child of currentNode.children) {
localCount += findExceedingCount(
path + currentNode.name + "/",
child,
count,
);
}
return localCount + count;
}
}
}
async function importFile(authClient) {
const fs = require("fs");
const drive = google.drive({ version: "v3", auth: authClient });
const file = await drive.files.create({
requestBody: {
name: "LOM - Frankfurt UAS - High Integrity Systems",
parents: ["1DwT0gTNM3kOOptsbgT-WObMeVvK_cSQc"],
mimeType: "application/vnd.google-apps.document",
},
media: {
mimeType:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
body: fs.createReadStream(
"./LOM - Frankfurt UAS - High Integrity Systems.docx",
),
},
});
console.log("File Id:", file.data.id);
return file.data.id;
}
function findAllMIMETypes(currentNode, set) {
if (!set.includes(currentNode.mimeType)) set.push(currentNode.mimeType);
if (currentNode.children) {
let localSet = [];
for (const child of currentNode.children)
localSet = findAllMIMETypes(child, set);
for (const item of localSet) if (!set.includes(item)) set.push(item);
}
return set;
}
async function main() {
const tree = await fileToJSON("./truth-tree.json");
console.log(findAllMIMETypes(tree, []));
}
main();