@adobe/helix-google-support 1.2.1 → 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 +21 -0
- package/package.json +2 -2
- package/src/GoogleClient.js +51 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,24 @@
|
|
|
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
|
+
|
|
8
|
+
# [1.3.0](https://github.com/adobe/helix-google-support/compare/v1.2.2...v1.3.0) (2022-04-28)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* 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))
|
|
14
|
+
|
|
15
|
+
## [1.2.2](https://github.com/adobe/helix-google-support/compare/v1.2.1...v1.2.2) (2022-04-28)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Bug Fixes
|
|
19
|
+
|
|
20
|
+
* include mimeType ([#11](https://github.com/adobe/helix-google-support/issues/11)) ([67ab999](https://github.com/adobe/helix-google-support/commit/67ab999a7fee111978a15c4393761e4b614ee2fc))
|
|
21
|
+
|
|
1
22
|
## [1.2.1](https://github.com/adobe/helix-google-support/compare/v1.2.0...v1.2.1) (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.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,7 +238,7 @@ 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,
|
|
@@ -292,6 +298,7 @@ export class GoogleClient {
|
|
|
292
298
|
name: '',
|
|
293
299
|
path: '/',
|
|
294
300
|
id: parentId,
|
|
301
|
+
mimeType: 'application/vnd.google-apps.folder',
|
|
295
302
|
}];
|
|
296
303
|
}
|
|
297
304
|
|
|
@@ -310,6 +317,7 @@ export class GoogleClient {
|
|
|
310
317
|
fields: [
|
|
311
318
|
'name',
|
|
312
319
|
'parents',
|
|
320
|
+
'mimeType',
|
|
313
321
|
'modifiedTime',
|
|
314
322
|
].join(','),
|
|
315
323
|
}));
|
|
@@ -317,7 +325,7 @@ export class GoogleClient {
|
|
|
317
325
|
const root = roots[fileId];
|
|
318
326
|
if (root) {
|
|
319
327
|
// stop at mount root
|
|
320
|
-
return [
|
|
328
|
+
return [addFields({
|
|
321
329
|
id: fileId,
|
|
322
330
|
name: '',
|
|
323
331
|
path: root,
|
|
@@ -327,7 +335,7 @@ export class GoogleClient {
|
|
|
327
335
|
const parentId = data.parents ? data.parents[0] : '';
|
|
328
336
|
if (!parentId) {
|
|
329
337
|
// outside mountpoint
|
|
330
|
-
return [
|
|
338
|
+
return [addFields({
|
|
331
339
|
id: fileId,
|
|
332
340
|
name: data.name,
|
|
333
341
|
path: `/root:/${data.name}`,
|
|
@@ -336,7 +344,7 @@ export class GoogleClient {
|
|
|
336
344
|
|
|
337
345
|
const ancestors = await this.getItems(data.parents[0], roots);
|
|
338
346
|
const parentPath = ancestors[0].path.replace(/\/+$/, '');
|
|
339
|
-
ancestors.unshift(
|
|
347
|
+
ancestors.unshift(addFields({
|
|
340
348
|
id: fileId,
|
|
341
349
|
name: data.name,
|
|
342
350
|
path: `${parentPath}/${data.name}`,
|
|
@@ -367,11 +375,46 @@ export class GoogleClient {
|
|
|
367
375
|
* Returns the (cached) item for the given path or {@code null} if the item cannot be found.
|
|
368
376
|
* The item will contains a `invalidate()` method which can be used to remove it from the cache.
|
|
369
377
|
*
|
|
370
|
-
* @param {string} parentId
|
|
371
|
-
* @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]
|
|
372
380
|
* @returns {Promise<DriveItemInfo>}
|
|
373
381
|
*/
|
|
374
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
|
+
|
|
375
418
|
const segs = createPathSegments(path);
|
|
376
419
|
const items = await this.getDriveItemsFromSegments(parentId, segs, '');
|
|
377
420
|
const item = items?.[0];
|