@adobe/helix-google-support 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/package.json +2 -2
- package/src/GoogleClient.js +39 -23
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.3.1](https://github.com/adobe/helix-google-support/compare/v1.3.0...v1.3.1) (2022-04-28)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* more fixes ([#14](https://github.com/adobe/helix-google-support/issues/14)) ([f52b01d](https://github.com/adobe/helix-google-support/commit/f52b01d575fb17602ea57b35f0e4c93dbbd41dd1))
|
|
7
|
+
|
|
1
8
|
# [1.3.0](https://github.com/adobe/helix-google-support/compare/v1.2.2...v1.3.0) (2022-04-28)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-google-support",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Helix Google Support",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"eslint-plugin-import": "2.26.0",
|
|
48
48
|
"husky": "7.0.4",
|
|
49
49
|
"junit-report-builder": "3.0.0",
|
|
50
|
-
"lint-staged": "12.4.
|
|
50
|
+
"lint-staged": "12.4.1",
|
|
51
51
|
"mocha": "9.2.2",
|
|
52
52
|
"mocha-multi-reporters": "1.5.1",
|
|
53
53
|
"nock": "13.2.4",
|
package/src/GoogleClient.js
CHANGED
|
@@ -25,19 +25,25 @@ let lru = new LRU({ max: 1000, ttl: 60000 });
|
|
|
25
25
|
* @property {string} name
|
|
26
26
|
* @property {string} url
|
|
27
27
|
* @property {string} path
|
|
28
|
+
* @property {string} mimeType
|
|
29
|
+
* @property {number} lastModified
|
|
28
30
|
*/
|
|
29
31
|
|
|
30
32
|
/**
|
|
31
|
-
* Adds the last modified property if defined in item
|
|
33
|
+
* Adds the last modified property and mimeType if defined in item
|
|
32
34
|
* @param {DriveItemInfo} itemInfo
|
|
33
35
|
* @param item
|
|
34
36
|
* @returns {DriveItemInfo}
|
|
35
37
|
*/
|
|
36
|
-
function
|
|
38
|
+
function addFields(itemInfo, item) {
|
|
37
39
|
if (item.modifiedTime) {
|
|
38
40
|
// eslint-disable-next-line no-param-reassign
|
|
39
41
|
itemInfo.lastModified = Date.parse(item.modifiedTime);
|
|
40
42
|
}
|
|
43
|
+
if (item.mimeType) {
|
|
44
|
+
// eslint-disable-next-line no-param-reassign
|
|
45
|
+
itemInfo.mimeType = item.mimeType;
|
|
46
|
+
}
|
|
41
47
|
return itemInfo;
|
|
42
48
|
}
|
|
43
49
|
|
|
@@ -232,11 +238,10 @@ export class GoogleClient {
|
|
|
232
238
|
if (!children) {
|
|
233
239
|
return null;
|
|
234
240
|
}
|
|
235
|
-
const pathItem =
|
|
241
|
+
const pathItem = addFields({
|
|
236
242
|
name,
|
|
237
243
|
path: itemPath,
|
|
238
244
|
id: item.id,
|
|
239
|
-
mimeType: item.mimeType,
|
|
240
245
|
}, item);
|
|
241
246
|
|
|
242
247
|
if (children.length) {
|
|
@@ -320,7 +325,7 @@ export class GoogleClient {
|
|
|
320
325
|
const root = roots[fileId];
|
|
321
326
|
if (root) {
|
|
322
327
|
// stop at mount root
|
|
323
|
-
return [
|
|
328
|
+
return [addFields({
|
|
324
329
|
id: fileId,
|
|
325
330
|
name: '',
|
|
326
331
|
path: root,
|
|
@@ -330,7 +335,7 @@ export class GoogleClient {
|
|
|
330
335
|
const parentId = data.parents ? data.parents[0] : '';
|
|
331
336
|
if (!parentId) {
|
|
332
337
|
// outside mountpoint
|
|
333
|
-
return [
|
|
338
|
+
return [addFields({
|
|
334
339
|
id: fileId,
|
|
335
340
|
name: data.name,
|
|
336
341
|
path: `/root:/${data.name}`,
|
|
@@ -339,7 +344,7 @@ export class GoogleClient {
|
|
|
339
344
|
|
|
340
345
|
const ancestors = await this.getItems(data.parents[0], roots);
|
|
341
346
|
const parentPath = ancestors[0].path.replace(/\/+$/, '');
|
|
342
|
-
ancestors.unshift(
|
|
347
|
+
ancestors.unshift(addFields({
|
|
343
348
|
id: fileId,
|
|
344
349
|
name: data.name,
|
|
345
350
|
path: `${parentPath}/${data.name}`,
|
|
@@ -370,27 +375,38 @@ export class GoogleClient {
|
|
|
370
375
|
* Returns the (cached) item for the given path or {@code null} if the item cannot be found.
|
|
371
376
|
* The item will contains a `invalidate()` method which can be used to remove it from the cache.
|
|
372
377
|
*
|
|
373
|
-
* @param {string} parentId
|
|
374
|
-
* @param {string} path
|
|
378
|
+
* @param {string} parentId the parent id or the id of the item itself, if the path is missing
|
|
379
|
+
* @param {string} [path]
|
|
375
380
|
* @returns {Promise<DriveItemInfo>}
|
|
376
381
|
*/
|
|
377
382
|
async getItemFromPath(parentId, path) {
|
|
378
383
|
if (!path) {
|
|
379
384
|
try {
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
385
|
+
let item = lru.get(parentId);
|
|
386
|
+
if (!item) {
|
|
387
|
+
const { data } = (await this.drive.files.get({
|
|
388
|
+
fileId: parentId,
|
|
389
|
+
fields: [
|
|
390
|
+
'name',
|
|
391
|
+
'parents',
|
|
392
|
+
'mimeType',
|
|
393
|
+
'modifiedTime',
|
|
394
|
+
].join(','),
|
|
395
|
+
}));
|
|
396
|
+
item = addFields({
|
|
397
|
+
id: parentId,
|
|
398
|
+
path: `/${data.name}`,
|
|
399
|
+
}, data);
|
|
400
|
+
// todo: extend caching to all items ?
|
|
401
|
+
Object.defineProperty(item, 'invalidate', {
|
|
402
|
+
enumerable: false,
|
|
403
|
+
value() {
|
|
404
|
+
lru.delete(parentId);
|
|
405
|
+
},
|
|
406
|
+
});
|
|
407
|
+
lru.set(parentId, item);
|
|
408
|
+
}
|
|
409
|
+
return item;
|
|
394
410
|
} catch (e) {
|
|
395
411
|
if (e.response && e.response.status === 404) {
|
|
396
412
|
return null;
|