@cooperation/vc-storage 1.0.15 → 1.0.17
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.
@@ -22,10 +22,10 @@ export class GoogleDriveStorage {
|
|
22
22
|
try {
|
23
23
|
const res = await fetch(url, {
|
24
24
|
method,
|
25
|
-
headers:
|
25
|
+
headers: {
|
26
26
|
Authorization: `Bearer ${this.accessToken}`,
|
27
27
|
...headers,
|
28
|
-
}
|
28
|
+
},
|
29
29
|
body,
|
30
30
|
});
|
31
31
|
// Check the Content-Type to ensure it's JSON before parsing
|
@@ -426,4 +426,22 @@ export class GoogleDriveStorage {
|
|
426
426
|
return null;
|
427
427
|
}
|
428
428
|
}
|
429
|
+
async update(fileId, data) {
|
430
|
+
const fileMetadata = {
|
431
|
+
name: data.fileName,
|
432
|
+
mimeType: data.mimeType,
|
433
|
+
};
|
434
|
+
let uploadUrl = `https://www.googleapis.com/upload/drive/v3/files/${fileId}?uploadType=multipart`;
|
435
|
+
const formData = new FormData();
|
436
|
+
formData.append('metadata', new Blob([JSON.stringify(fileMetadata)], { type: 'application/json' }));
|
437
|
+
formData.append('file', new Blob([data.body], { type: fileMetadata.mimeType }));
|
438
|
+
const updatedFile = await this.fetcher({
|
439
|
+
method: 'PATCH',
|
440
|
+
headers: {},
|
441
|
+
body: JSON.stringify(formData),
|
442
|
+
url: `${uploadUrl}&fields=id,parents`,
|
443
|
+
});
|
444
|
+
console.log('File updated:', updatedFile);
|
445
|
+
return updatedFile;
|
446
|
+
}
|
429
447
|
}
|
@@ -10,11 +10,7 @@ export declare const getVCWithRecommendations: ({ vcId, storage }: {
|
|
10
10
|
vcId: string;
|
11
11
|
storage: GoogleDriveStorage;
|
12
12
|
}) => Promise<{
|
13
|
-
vc:
|
14
|
-
name: string;
|
15
|
-
data: any;
|
16
|
-
id: string;
|
17
|
-
};
|
13
|
+
vc: any;
|
18
14
|
recommendations: any[];
|
19
15
|
relationsFileId: any;
|
20
16
|
}>;
|
package/dist/utils/google.js
CHANGED
@@ -3,14 +3,15 @@ export const getVCWithRecommendations = async ({ vcId, storage }) => {
|
|
3
3
|
const files = await storage.findFilesUnderFolder(vcFolderId);
|
4
4
|
const relationsFile = files.find((f) => f.name === 'RELATIONS');
|
5
5
|
const relationsContent = await storage.retrieve(relationsFile.id);
|
6
|
-
const relationsData = relationsContent.data;
|
6
|
+
const relationsData = JSON.parse(relationsContent.data.body);
|
7
7
|
const [vcFileId, recommendationIds] = [relationsData.vc_id, relationsData.recommendations];
|
8
8
|
const vc = await storage.retrieve(vcFileId);
|
9
|
+
const vcData = JSON.parse(vc.data.body);
|
9
10
|
const recommendations = await Promise.all(recommendationIds.map(async (rec) => {
|
10
11
|
const recFile = await storage.retrieve(rec);
|
11
12
|
return recFile;
|
12
13
|
}));
|
13
|
-
return { vc:
|
14
|
+
return { vc: vcData, recommendations, relationsFileId: relationsFile.id };
|
14
15
|
};
|
15
16
|
/**
|
16
17
|
* Save data to Google Drive in the specified folder type.
|