Skip to content

Google drive: adding selection between file URL or path #15457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 39 additions & 13 deletions components/google_drive/actions/update-file/update-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,36 @@ import {
toSingleLineString,
getFileStream,
} from "../../common/utils.mjs";
import { additionalProps } from "../../common/filePathOrUrl.mjs";

export default {
key: "google_drive-update-file",
name: "Update File",
description: "Update a file's metadata and/or content. [See the documentation](https://developers.google.com/drive/api/v3/reference/files/update) for more information",
version: "0.1.7",
version: "1.0.0",
type: "action",
additionalProps,
props: {
googleDrive,
requiredPropsAlert: {
type: "alert",
alertType: "info",
content: "Either `File URL` and `File Path` should be specified.",
updateType: {
type: "string",
label: "Update Type",
description: "Whether to update content or metadata only",
options: [
{
label: "Upload content from File URL",
value: "File URL",
},
{
label: "Upload content from File Path",
value: "File Path",
},
{
label: "Update file metadata only",
value: "File Metadata",
},
],
reloadProps: true,
},
drive: {
propDefinition: [
Expand All @@ -40,6 +57,8 @@ export default {
"fileUrl",
],
description: "The URL of the file to use to update content",
optional: false,
hidden: true,
},
filePath: {
propDefinition: [
Expand All @@ -51,6 +70,8 @@ export default {
directory](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory)
(e.g., \`/tmp/myFile.csv\`) with which to update content
`),
optional: false,
hidden: true,
},
name: {
propDefinition: [
Expand Down Expand Up @@ -128,16 +149,21 @@ export default {
ocrLanguage,
useContentAsIndexableText,
advanced,
updateType,
} = this;

const fileStream =
fileUrl || filePath
? await getFileStream({
$,
fileUrl,
filePath,
})
: undefined;
let fileStream;
if (updateType === "File URL") {
fileStream = await getFileStream({
$,
fileUrl,
});
} else if (updateType === "File Path") {
fileStream = await getFileStream({
$,
filePath,
});
}

// Update file content, if set, separately from metadata to prevent
// multipart upload, which `google-apis-nodejs-client` doesn't seem to
Expand Down
20 changes: 10 additions & 10 deletions components/google_drive/actions/upload-file/upload-file.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ import {
omitEmptyStringValues,
} from "../../common/utils.mjs";
import { GOOGLE_DRIVE_UPLOAD_TYPE_MULTIPART } from "../../common/constants.mjs";
import { ConfigurationError } from "@pipedream/platform";
import {
additionalProps, updateType,
} from "../../common/filePathOrUrl.mjs";

export default {
key: "google_drive-upload-file",
name: "Upload File",
description: "Upload a file to Google Drive. [See the documentation](https://developers.google.com/drive/api/v3/manage-uploads) for more information",
version: "0.1.10",
version: "1.0.0",
type: "action",
additionalProps,
props: {
googleDrive,
infoAlert: {
type: "alert",
alertType: "info",
content: "Either `File URL` and `File Path` should be specified.",
},
updateType,
drive: {
propDefinition: [
googleDrive,
Expand All @@ -44,12 +43,16 @@ export default {
googleDrive,
"fileUrl",
],
optional: false,
hidden: true,
},
filePath: {
propDefinition: [
googleDrive,
"filePath",
],
optional: false,
hidden: true,
},
name: {
propDefinition: [
Expand Down Expand Up @@ -94,9 +97,6 @@ export default {
mimeType,
} = this;
let { uploadType } = this;
if (!fileUrl && !filePath) {
throw new ConfigurationError("Either `File URL` and `File Path` should be specified.");
}
const driveId = this.googleDrive.getDriveId(this.drive);

const filename = name || path.basename(fileUrl || filePath);
Expand Down
27 changes: 27 additions & 0 deletions components/google_drive/common/filePathOrUrl.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export const updateType = {
type: "string",
label: "Use File URL or File Path",
description: "Whether to upload a file from a URL or from the `/tmp` folder",
options: [
"File URL",
"File Path",
],
reloadProps: true,
};

export async function additionalProps(previousProps) {
const { updateType } = this;

if (updateType === "File URL") {
previousProps.fileUrl.hidden = false;
previousProps.filePath.hidden = true;
} else if (updateType === "File Path") {
previousProps.fileUrl.hidden = true;
previousProps.filePath.hidden = false;
} else {
previousProps.fileUrl.hidden = true;
previousProps.filePath.hidden = true;
}

return {};
}
2 changes: 1 addition & 1 deletion components/google_drive/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/google_drive",
"version": "0.8.9",
"version": "0.8.10",
"description": "Pipedream Google_drive Components",
"main": "google_drive.app.mjs",
"keywords": [
Expand Down
31 changes: 15 additions & 16 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading