@pipedream/google_drive 5.0.0 → 5.0.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.
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { ConfigurationError } from "@pipedream/platform";
|
|
1
2
|
import googleDrive from "../../google_drive.app.mjs";
|
|
2
3
|
|
|
3
4
|
export default {
|
|
4
5
|
key: "google_drive-move-file",
|
|
5
6
|
name: "Move File",
|
|
6
|
-
description: "Move a file from
|
|
7
|
-
version: "0.1.
|
|
7
|
+
description: "Move a file from its current folder to another folder. If the file's current folder isn't accessible to the user (for example, it was shared from someone else's folder), the file is added to the destination folder instead when Drive allows it; otherwise the action returns an error, and a shortcut or copy should be used. [See the documentation](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
|
|
8
|
+
version: "0.1.31",
|
|
8
9
|
annotations: {
|
|
9
10
|
destructiveHint: true,
|
|
10
11
|
openWorldHint: true,
|
|
@@ -46,13 +47,27 @@ export default {
|
|
|
46
47
|
async run({ $ }) {
|
|
47
48
|
// Get file to get parents to remove
|
|
48
49
|
const file = await this.googleDrive.getFile(this.fileId);
|
|
50
|
+
// Drive omits `parents` when the user can't see the file's current folder
|
|
51
|
+
// (typical for shared files). There is nothing to remove then, so the file
|
|
52
|
+
// can only be added to the destination, and only if Drive says that is
|
|
53
|
+
// allowed; otherwise it rejects the update (403 cannotAddParent).
|
|
54
|
+
const hasParents = Boolean(file.parents?.length);
|
|
55
|
+
if (!hasParents && !(file.capabilities?.canAddMyDriveParent && this.folderId)) {
|
|
56
|
+
throw new ConfigurationError(
|
|
57
|
+
`Cannot move "${file.name}": it isn't in a folder you can access (for example, it was shared with you from someone else's folder), so its current folder can't be replaced. Instead, create a shortcut to the file or make a copy of it in the destination folder.`,
|
|
58
|
+
);
|
|
59
|
+
}
|
|
49
60
|
// Update file, removing old parents, adding new parent folder
|
|
50
61
|
const resp = await this.googleDrive.updateFile(this.fileId, {
|
|
51
62
|
fields: "*",
|
|
52
|
-
removeParents:
|
|
63
|
+
removeParents: hasParents
|
|
64
|
+
? file.parents.join(",")
|
|
65
|
+
: undefined,
|
|
53
66
|
addParents: this.folderId,
|
|
54
67
|
});
|
|
55
|
-
$.export("$summary",
|
|
68
|
+
$.export("$summary", hasParents
|
|
69
|
+
? `Successfully moved the file, "${file.name}"`
|
|
70
|
+
: `Added the file, "${file.name}", to the destination folder (it had no accessible parent folder to remove)`);
|
|
56
71
|
return resp;
|
|
57
72
|
},
|
|
58
73
|
};
|