@cooperation/vc-storage 1.0.10 → 1.0.11
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.
@@ -79,6 +79,7 @@ export class GoogleDriveStorage {
|
|
79
79
|
const formData = new FormData();
|
80
80
|
formData.append('metadata', new Blob([JSON.stringify(fileMetadata)], { type: 'application/json' }));
|
81
81
|
formData.append('file', new Blob([data.body], { type: fileMetadata.mimeType })); // Set file data and MIME type
|
82
|
+
// Upload file to Google Drive
|
82
83
|
const file = await this.fetcher({
|
83
84
|
method: 'POST',
|
84
85
|
headers: {},
|
@@ -86,10 +87,25 @@ export class GoogleDriveStorage {
|
|
86
87
|
url: uploadUrl,
|
87
88
|
});
|
88
89
|
console.log('File uploaded successfully:', file.id);
|
89
|
-
|
90
|
+
// Set the file permission to "Anyone with the link" can view
|
91
|
+
const permissionUrl = `https://www.googleapis.com/drive/v3/files/${file.id}/permissions`;
|
92
|
+
const permissionData = {
|
93
|
+
role: 'reader',
|
94
|
+
type: 'anyone', // Public access
|
95
|
+
};
|
96
|
+
await this.fetcher({
|
97
|
+
method: 'POST',
|
98
|
+
url: permissionUrl,
|
99
|
+
headers: {
|
100
|
+
'Content-Type': 'application/json',
|
101
|
+
},
|
102
|
+
body: JSON.stringify(permissionData),
|
103
|
+
});
|
104
|
+
console.log('Permission set to public for file:', file.id);
|
105
|
+
return { id: file.id };
|
90
106
|
}
|
91
107
|
catch (error) {
|
92
|
-
console.error('Error uploading file:', error.message);
|
108
|
+
console.error('Error uploading file or setting permission:', error.message);
|
93
109
|
return null;
|
94
110
|
}
|
95
111
|
}
|
package/dist/utils/google.js
CHANGED
@@ -68,9 +68,7 @@ export async function saveToGoogleDrive(storage, data, type, uuid) {
|
|
68
68
|
*/
|
69
69
|
export async function uploadImageToGoogleDrive(storage, imageFile) {
|
70
70
|
try {
|
71
|
-
// Get all root folders
|
72
71
|
const rootFolders = await storage.findFolders();
|
73
|
-
// Find or create the "Credentials" folder
|
74
72
|
let credentialsFolder = rootFolders.find((f) => f.name === 'Credentials');
|
75
73
|
let credentialsFolderId;
|
76
74
|
if (!credentialsFolder) {
|
@@ -79,9 +77,7 @@ export async function uploadImageToGoogleDrive(storage, imageFile) {
|
|
79
77
|
else {
|
80
78
|
credentialsFolderId = credentialsFolder.id;
|
81
79
|
}
|
82
|
-
// Get subfolders within the "Credentials" folder
|
83
80
|
const subfolders = await storage.findFolders(credentialsFolderId);
|
84
|
-
// Find or create the "MEDIAs" folder
|
85
81
|
let mediasFolder = subfolders.find((f) => f.name === 'MEDIAs');
|
86
82
|
let mediasFolderId;
|
87
83
|
if (!mediasFolder) {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "@cooperation/vc-storage",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.0.
|
4
|
+
"version": "1.0.11",
|
5
5
|
"description": "Sign and store your verifiable credentials.",
|
6
6
|
"main": "dist/index.js",
|
7
7
|
"types": "dist/types/index.d.ts",
|
@@ -16,7 +16,6 @@
|
|
16
16
|
"author": "cooperation",
|
17
17
|
"license": "ISC",
|
18
18
|
"dependencies": {
|
19
|
-
"@cooperation/vc-storage": "^1.0.6",
|
20
19
|
"@digitalbazaar/did-method-key": "^5.2.0",
|
21
20
|
"@digitalbazaar/ed25519-signature-2020": "^5.3.0",
|
22
21
|
"@digitalbazaar/ed25519-verification-key-2020": "^4.1.0",
|