-
Notifications
You must be signed in to change notification settings - Fork 1
/
trash.js
106 lines (83 loc) · 2.18 KB
/
trash.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
//take folderID
//get folder's childrens ids
async function getfolder(folderID) {
// folderChildren contains the ID of each file inside it
const folderChildren = await gapi.client.request(
`https://www.googleapis.com/drive/v2/files/${folderID}/children`
);
batching(folderChildren);
}
function batching(folderChildren) {
let batch = gapi.client.newBatch();
folderChildren.result.items.map((e, n) => {
batch.add(
gapi.client.drive.files.get(
{
fileId: e.id
},
{ id: n }
)
);
});
batch.then(e => console.log(e.result));
}
function withoutbatch(f) {
f.map((e, n) => {
console.log(`request id is ${e.id}`);
gapi.client.drive.files
.get({
fileId: e.id
})
.then(j => console.log(`${j.result.id} is response id `));
});
}
async function getfile(id, n) {
const file = await gapi.client.drive.files.get({
fileId: id
});
console.log(`file NO ${n} is : ${file.result.name}`, file);
}
function listfiles() {
gapi.client.drive.files
.list({
pageSize: 50,
fields: "nextPageToken, files(id, name)"
})
.then(response => {
console.log("list files : ", response.result);
});
}
gapi.client.drive.files
.list({
corpora: "drive",
supportsAllDrives: true,
includeItemsFromAllDrives: true
})
.then((e, f) => {
if (f) {
console.log("failed !!!", f);
} else {
console.log("done !!!", e);
}
});
/*
gapi.clent.Batch
it's a collectins of requestes combined in one http request
gapi.client.request.add(reqest)
1- var batch = gapi.client.newBatch();
2- batch.add(request)
execution :
gapi.client.batch.then
*/
// var metadata = {
// 'name': 'sampleName', // Filename at Google Drive
// 'mimeType': 'text/plain', // mimeType at Google Drive
// 'parents': ['### folder ID ###'], // Folder ID at Google Drive
// };
async function generateID() {
const ID = await gapi.client.request(
"https://www.googleapis.com/drive/v3/files/generateIds"
);
const uniqeID = ID.result.ids[0];
return uniqeID;
}