@8ms/helpers 3.0.25 → 3.0.27
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.
|
@@ -86,6 +86,67 @@ var GoogleCloudDrive = class extends require__class_BaseNamespace.BaseNamespace
|
|
|
86
86
|
});
|
|
87
87
|
};
|
|
88
88
|
/**
|
|
89
|
+
* Rename a file in Google Drive.
|
|
90
|
+
*/
|
|
91
|
+
renameFile = async (fileId, newName) => {
|
|
92
|
+
const apiResponse = await (await import("@googleapis/drive")).drive("v3").files.update({
|
|
93
|
+
auth: this.client,
|
|
94
|
+
fileId,
|
|
95
|
+
fields: "id, name, mimeType, modifiedTime",
|
|
96
|
+
requestBody: { name: newName }
|
|
97
|
+
});
|
|
98
|
+
return {
|
|
99
|
+
id: apiResponse.data.id ?? "",
|
|
100
|
+
name: apiResponse.data.name ?? "",
|
|
101
|
+
mimeType: apiResponse.data.mimeType ?? "",
|
|
102
|
+
modifiedTime: apiResponse.data.modifiedTime ?? ""
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Copy a file in Google Drive, optionally renaming it and/or placing it in a new parent folder.
|
|
107
|
+
*/
|
|
108
|
+
copyFile = async (fileId, newName, parentFolderId) => {
|
|
109
|
+
const apiResponse = await (await import("@googleapis/drive")).drive("v3").files.copy({
|
|
110
|
+
auth: this.client,
|
|
111
|
+
fileId,
|
|
112
|
+
fields: "id, name, mimeType, modifiedTime",
|
|
113
|
+
requestBody: {
|
|
114
|
+
...newName ? { name: newName } : {},
|
|
115
|
+
...parentFolderId ? { parents: [parentFolderId] } : {}
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return {
|
|
119
|
+
id: apiResponse.data.id ?? "",
|
|
120
|
+
name: apiResponse.data.name ?? "",
|
|
121
|
+
mimeType: apiResponse.data.mimeType ?? "",
|
|
122
|
+
modifiedTime: apiResponse.data.modifiedTime ?? ""
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
* Move a file to a new parent folder in Google Drive.
|
|
127
|
+
*/
|
|
128
|
+
moveFile = async (fileId, newParentFolderId) => {
|
|
129
|
+
const drive = (await import("@googleapis/drive")).drive("v3");
|
|
130
|
+
const previousParents = ((await drive.files.get({
|
|
131
|
+
auth: this.client,
|
|
132
|
+
fileId,
|
|
133
|
+
fields: "parents"
|
|
134
|
+
})).data.parents ?? []).join(",");
|
|
135
|
+
const apiResponse = await drive.files.update({
|
|
136
|
+
auth: this.client,
|
|
137
|
+
fileId,
|
|
138
|
+
addParents: newParentFolderId,
|
|
139
|
+
removeParents: previousParents,
|
|
140
|
+
fields: "id, name, mimeType, modifiedTime"
|
|
141
|
+
});
|
|
142
|
+
return {
|
|
143
|
+
id: apiResponse.data.id ?? "",
|
|
144
|
+
name: apiResponse.data.name ?? "",
|
|
145
|
+
mimeType: apiResponse.data.mimeType ?? "",
|
|
146
|
+
modifiedTime: apiResponse.data.modifiedTime ?? ""
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
89
150
|
* Write a file to Google Drive within the given parent folder.
|
|
90
151
|
*/
|
|
91
152
|
writeFile = async (parentFolderId, fileName, data, options = {}) => {
|
|
@@ -32,6 +32,18 @@ declare class GoogleCloudDrive extends BaseNamespace {
|
|
|
32
32
|
* Move a file to the Google Drive trash.
|
|
33
33
|
*/
|
|
34
34
|
deleteFile: (fileId: string) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Rename a file in Google Drive.
|
|
37
|
+
*/
|
|
38
|
+
renameFile: (fileId: string, newName: string) => Promise<DriveFile>;
|
|
39
|
+
/**
|
|
40
|
+
* Copy a file in Google Drive, optionally renaming it and/or placing it in a new parent folder.
|
|
41
|
+
*/
|
|
42
|
+
copyFile: (fileId: string, newName?: string, parentFolderId?: string) => Promise<DriveFile>;
|
|
43
|
+
/**
|
|
44
|
+
* Move a file to a new parent folder in Google Drive.
|
|
45
|
+
*/
|
|
46
|
+
moveFile: (fileId: string, newParentFolderId: string) => Promise<DriveFile>;
|
|
35
47
|
/**
|
|
36
48
|
* Write a file to Google Drive within the given parent folder.
|
|
37
49
|
*/
|
|
@@ -32,6 +32,18 @@ declare class GoogleCloudDrive extends BaseNamespace {
|
|
|
32
32
|
* Move a file to the Google Drive trash.
|
|
33
33
|
*/
|
|
34
34
|
deleteFile: (fileId: string) => Promise<void>;
|
|
35
|
+
/**
|
|
36
|
+
* Rename a file in Google Drive.
|
|
37
|
+
*/
|
|
38
|
+
renameFile: (fileId: string, newName: string) => Promise<DriveFile>;
|
|
39
|
+
/**
|
|
40
|
+
* Copy a file in Google Drive, optionally renaming it and/or placing it in a new parent folder.
|
|
41
|
+
*/
|
|
42
|
+
copyFile: (fileId: string, newName?: string, parentFolderId?: string) => Promise<DriveFile>;
|
|
43
|
+
/**
|
|
44
|
+
* Move a file to a new parent folder in Google Drive.
|
|
45
|
+
*/
|
|
46
|
+
moveFile: (fileId: string, newParentFolderId: string) => Promise<DriveFile>;
|
|
35
47
|
/**
|
|
36
48
|
* Write a file to Google Drive within the given parent folder.
|
|
37
49
|
*/
|
|
@@ -85,6 +85,67 @@ var GoogleCloudDrive = class extends BaseNamespace {
|
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
87
|
/**
|
|
88
|
+
* Rename a file in Google Drive.
|
|
89
|
+
*/
|
|
90
|
+
renameFile = async (fileId, newName) => {
|
|
91
|
+
const apiResponse = await (await import("@googleapis/drive")).drive("v3").files.update({
|
|
92
|
+
auth: this.client,
|
|
93
|
+
fileId,
|
|
94
|
+
fields: "id, name, mimeType, modifiedTime",
|
|
95
|
+
requestBody: { name: newName }
|
|
96
|
+
});
|
|
97
|
+
return {
|
|
98
|
+
id: apiResponse.data.id ?? "",
|
|
99
|
+
name: apiResponse.data.name ?? "",
|
|
100
|
+
mimeType: apiResponse.data.mimeType ?? "",
|
|
101
|
+
modifiedTime: apiResponse.data.modifiedTime ?? ""
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
/**
|
|
105
|
+
* Copy a file in Google Drive, optionally renaming it and/or placing it in a new parent folder.
|
|
106
|
+
*/
|
|
107
|
+
copyFile = async (fileId, newName, parentFolderId) => {
|
|
108
|
+
const apiResponse = await (await import("@googleapis/drive")).drive("v3").files.copy({
|
|
109
|
+
auth: this.client,
|
|
110
|
+
fileId,
|
|
111
|
+
fields: "id, name, mimeType, modifiedTime",
|
|
112
|
+
requestBody: {
|
|
113
|
+
...newName ? { name: newName } : {},
|
|
114
|
+
...parentFolderId ? { parents: [parentFolderId] } : {}
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return {
|
|
118
|
+
id: apiResponse.data.id ?? "",
|
|
119
|
+
name: apiResponse.data.name ?? "",
|
|
120
|
+
mimeType: apiResponse.data.mimeType ?? "",
|
|
121
|
+
modifiedTime: apiResponse.data.modifiedTime ?? ""
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Move a file to a new parent folder in Google Drive.
|
|
126
|
+
*/
|
|
127
|
+
moveFile = async (fileId, newParentFolderId) => {
|
|
128
|
+
const drive = (await import("@googleapis/drive")).drive("v3");
|
|
129
|
+
const previousParents = ((await drive.files.get({
|
|
130
|
+
auth: this.client,
|
|
131
|
+
fileId,
|
|
132
|
+
fields: "parents"
|
|
133
|
+
})).data.parents ?? []).join(",");
|
|
134
|
+
const apiResponse = await drive.files.update({
|
|
135
|
+
auth: this.client,
|
|
136
|
+
fileId,
|
|
137
|
+
addParents: newParentFolderId,
|
|
138
|
+
removeParents: previousParents,
|
|
139
|
+
fields: "id, name, mimeType, modifiedTime"
|
|
140
|
+
});
|
|
141
|
+
return {
|
|
142
|
+
id: apiResponse.data.id ?? "",
|
|
143
|
+
name: apiResponse.data.name ?? "",
|
|
144
|
+
mimeType: apiResponse.data.mimeType ?? "",
|
|
145
|
+
modifiedTime: apiResponse.data.modifiedTime ?? ""
|
|
146
|
+
};
|
|
147
|
+
};
|
|
148
|
+
/**
|
|
88
149
|
* Write a file to Google Drive within the given parent folder.
|
|
89
150
|
*/
|
|
90
151
|
writeFile = async (parentFolderId, fileName, data, options = {}) => {
|