-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutilities.js
40 lines (34 loc) · 1023 Bytes
/
utilities.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
const getPersistedHandle = () => {
return idbKeyval.get('directory');
};
const clearHandle = () => {
idbKeyval.clear();
};
const saveDirectoryAsRecent = (dirHandle) => {
idbKeyval.set('directory', dirHandle);
};
const listFiles = async (dirHandle) => {
const files = [];
for await (let [_, handle] of dirHandle) {
if (handle.kind === 'directory') {
files.push(...(await listFiles(handle)));
} else {
files.push({ handle, dirHandle });
}
}
return files;
};
const verifyPermission = async (handle) => {
const opts = { mode: 'readwrite', writeable: true };
console.log('queryPermission');
console.log(await handle.queryPermission(opts));
console.log('requestPermission');
console.log(await handle.requestPermission(opts));
if ((await handle.queryPermission(opts)) === 'granted') {
return true;
}
if ((await handle.requestPermission(opts)) === 'granted') {
return true;
}
return false;
};