@adobe/helix-google-support 1.2.2 → 1.3.2
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 +21 -0
- package/package.json +3 -3
- package/src/GoogleClient.js +50 -9
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
1
|
+
## [1.3.2](https://github.com/adobe/helix-google-support/compare/v1.3.1...v1.3.2) (2022-04-30)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **deps:** update dependency lru-cache to v7.9.0 ([de4e8e3](https://github.com/adobe/helix-google-support/commit/de4e8e3918a04dbb646c33946791168f434b872d))
|
|
7
|
+
|
|
8
|
+
## [1.3.1](https://github.com/adobe/helix-google-support/compare/v1.3.0...v1.3.1) (2022-04-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* more fixes ([#14](https://github.com/adobe/helix-google-support/issues/14)) ([f52b01d](https://github.com/adobe/helix-google-support/commit/f52b01d575fb17602ea57b35f0e4c93dbbd41dd1))
|
|
14
|
+
|
|
15
|
+
# [1.3.0](https://github.com/adobe/helix-google-support/compare/v1.2.2...v1.3.0) (2022-04-28)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* handle getItemForPath() with no path ([#12](https://github.com/adobe/helix-google-support/issues/12)) ([0e1b60d](https://github.com/adobe/helix-google-support/commit/0e1b60d6612b3628193b9188eadc230de2894aff))
|
|
21
|
+
|
|
1
22
|
## [1.2.2](https://github.com/adobe/helix-google-support/compare/v1.2.1...v1.2.2) (2022-04-28)
|
|
2
23
|
|
|
3
24
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@adobe/helix-google-support",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"description": "Helix Google Support",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@adobe/helix-onedrive-support": "https://github.com/adobe/helix-onedrive-support.git#d279dda0abdc05df14628d45a7c716042d94ec45",
|
|
35
35
|
"googleapis": "100.0.0",
|
|
36
|
-
"lru-cache": "7.
|
|
36
|
+
"lru-cache": "7.9.0"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@adobe/eslint-config-helix": "1.3.2",
|
|
@@ -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) {
|
|
@@ -312,6 +317,7 @@ export class GoogleClient {
|
|
|
312
317
|
fields: [
|
|
313
318
|
'name',
|
|
314
319
|
'parents',
|
|
320
|
+
'mimeType',
|
|
315
321
|
'modifiedTime',
|
|
316
322
|
].join(','),
|
|
317
323
|
}));
|
|
@@ -319,7 +325,7 @@ export class GoogleClient {
|
|
|
319
325
|
const root = roots[fileId];
|
|
320
326
|
if (root) {
|
|
321
327
|
// stop at mount root
|
|
322
|
-
return [
|
|
328
|
+
return [addFields({
|
|
323
329
|
id: fileId,
|
|
324
330
|
name: '',
|
|
325
331
|
path: root,
|
|
@@ -329,7 +335,7 @@ export class GoogleClient {
|
|
|
329
335
|
const parentId = data.parents ? data.parents[0] : '';
|
|
330
336
|
if (!parentId) {
|
|
331
337
|
// outside mountpoint
|
|
332
|
-
return [
|
|
338
|
+
return [addFields({
|
|
333
339
|
id: fileId,
|
|
334
340
|
name: data.name,
|
|
335
341
|
path: `/root:/${data.name}`,
|
|
@@ -338,7 +344,7 @@ export class GoogleClient {
|
|
|
338
344
|
|
|
339
345
|
const ancestors = await this.getItems(data.parents[0], roots);
|
|
340
346
|
const parentPath = ancestors[0].path.replace(/\/+$/, '');
|
|
341
|
-
ancestors.unshift(
|
|
347
|
+
ancestors.unshift(addFields({
|
|
342
348
|
id: fileId,
|
|
343
349
|
name: data.name,
|
|
344
350
|
path: `${parentPath}/${data.name}`,
|
|
@@ -369,11 +375,46 @@ export class GoogleClient {
|
|
|
369
375
|
* Returns the (cached) item for the given path or {@code null} if the item cannot be found.
|
|
370
376
|
* The item will contains a `invalidate()` method which can be used to remove it from the cache.
|
|
371
377
|
*
|
|
372
|
-
* @param {string} parentId
|
|
373
|
-
* @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]
|
|
374
380
|
* @returns {Promise<DriveItemInfo>}
|
|
375
381
|
*/
|
|
376
382
|
async getItemFromPath(parentId, path) {
|
|
383
|
+
if (!path) {
|
|
384
|
+
try {
|
|
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;
|
|
410
|
+
} catch (e) {
|
|
411
|
+
if (e.response && e.response.status === 404) {
|
|
412
|
+
return null;
|
|
413
|
+
}
|
|
414
|
+
throw e;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
|
|
377
418
|
const segs = createPathSegments(path);
|
|
378
419
|
const items = await this.getDriveItemsFromSegments(parentId, segs, '');
|
|
379
420
|
const item = items?.[0];
|