PipedreamHQ / pipedream

Connect APIs, remarkably fast. Free for developers.
https://pipedream.com
Other
8.32k stars 5.27k forks source link

[ACTION] Dropbox new actions #1956

Closed vellames closed 2 years ago

vellames commented 2 years ago

Create new Actions:

Convert CommonJS to ESM

Add summary to sources

Others

Docs https://www.dropbox.com/developers/documentation/http/documentation https://dropbox.github.io/dropbox-sdk-js/Dropbox.html

vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

pipedream-docs-redirect-do-not-edit – ./docs

🔍 Inspect: https://vercel.com/pipedreamers/pipedream-docs-redirect-do-not-edit/FjRsicktNVrYeWvqTZgwmVwFNus3
✅ Preview: https://pipedream-docs-redirect-do-not-edit-git-dro-a80ba3-pipedreamers.vercel.app

pipedream-docs – ./docs

🔍 Inspect: https://vercel.com/pipedreamers/pipedream-docs/6AGC32ZECBERk7XCXnSfJEvkBmw2
✅ Preview: https://pipedream-docs-git-dropbox-new-actions-pipedreamers.vercel.app

dylburger commented 2 years ago
vellames commented 2 years ago

@dannyroosevelt @michelle0927 In my view, the following action is redundant List All Files/Subfolders in a Folder | Retrieves a list of files or subfolders in a specified folder because Search Files/Folders | Searches for files and folders by name already has a param where you can search a file/folders passing a path Does it make sense?

michelle0927 commented 2 years ago

@dannyroosevelt @michelle0927 In my view, the following action is redundant List All Files/Subfolders in a Folder | Retrieves a list of files or subfolders in a specified folder because Search Files/Folders | Searches for files and folders by name already has a param where you can search a file/folders passing a path Does it make sense?

Integromat has both as separate actions, so I think we should have both of them.

dannyroosevelt commented 2 years ago

I'm generally in favor of reducing redundant actions but yea I think the use case for each is slightly different, even though you might be able to accomplish the goal using either action. And especially since Dropbox is such a popular service, let's keep both. Thanks @vellames-turing and @michelle0927

vellames commented 2 years ago

Hey @michelle0927 . Can you help me with these two asked actions?

I am looking into dropbox SDK and I can't find something related to this. The closest thing that I found was to create a "paper", I am not sure if this is what you want me to do. Thank you!

vellames commented 2 years ago

@michelle0927 Maybe I should create a text file in pipedream and upload it as a text file?

michelle0927 commented 2 years ago

@michelle0927 Maybe I should create a text file in pipedream and upload it as a text file?

I think that's what I would do. Maybe just have the "plain text content" entered as a prop, create a text file from it in the /tmp directory (https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory), and upload it to Dropbox. Would that work?

vellames commented 2 years ago

Thank you for your review, I already pushed some updates. I will send the rest of the adjustments tomorrow morning. Tks!

vellames commented 2 years ago

Thank you for your review! All suggestions were implemented

elibenton commented 2 years ago

Hi all! I'm having trouble with the new file trigger. I use the automatic trigger, and it produces the following code.

const dropbox = require("../../dropbox.app.js");

module.exports = {
  key: "dropbox-new-file",
  name: "New File",
  version: "0.0.4",
  description:
    "Emits an event when a new file is added to your account or a specific folder. Make sure the number of files/folders in the watched folder does not exceed 4000.",
  props: {
    dropbox,
    path: { propDefinition: [dropbox, "path"] },
    recursive: { propDefinition: [dropbox, "recursive"] },
    includeMediaInfo: {
      type: "boolean",
      description:
        "Emit media info for photos and videos (incurs an additional API call)",
      default: false,
    },
    includeLink: {
      type: "boolean",
      description:
        "Emit temporary download link to file (incurs an additional API call)",
      default: false,
    },
    dropboxApphook: {
      type: "$.interface.apphook",
      appProp: "dropbox",
      static: [],
    },
    db: "$.service.db",
  },
  hooks: {
    async activate() {
      const startTime = new Date();
      await this.dropbox.initState(this);
      this.db.set("last_file_mod_time", startTime);
    },
  },
  async run(event) {
    const lastFileModTime = this.db.get("last_file_mod_time");
    let currFileModTime = "";
    const updates = await this.dropbox.getUpdates(this);
    for (update of updates) {
      if (update[".tag"] == "file") {
        if (update.server_modified > currFileModTime) {
          currFileModTime = update.server_modified;
        }
        try {
          const dpx = await this.dropbox.sdk();
          let revisions = await dpx.filesListRevisions({
            path: update.id,
            mode: { ".tag": "id" },
            limit: 10,
          });
          if (revisions.result) {
            revisions = revisions.result;
          }
          if (revisions.entries.length > 1) {
            const oldest = revisions.entries.pop();
            if (lastFileModTime && lastFileModTime >= oldest.client_modified) {
              continue;
            }
          }
          if (this.includeMediaInfo) {
            const dpx = await this.dropbox.sdk();
            update = await dpx.filesGetMetadata({
              path: update.path_lower,
              include_media_info: true,
            });
            if (update.result) {
              update = update.result;
            }
          }
          if (this.includeLink) {
            const dpx = await this.dropbox.sdk();
            let response = await dpx.filesGetTemporaryLink({
              path: update.path_lower,
            });
            if (response.result) {
              response = response.result;
            }
            const { link, metadata } = response;
            update.link = link;
          }
        } catch (err) {
          console.log(err);
          throw `Error looking up revisions for file: ${update.name}`;
        }
        this.$emit(update);
      }
    }
    if (currFileModTime != "") {
      this.db.set("last_file_mod_time", currFileModTime);
    }
  },
};

And when I try to send a test event, nothing ever appears, it just listens forever. I check the logs, and this is what I see.

Any idea why the event is logging, but isn't actually propagating through to the next step?


end
2022-01-23T14:31:36
db.set
db["last_file_mod_time"] ⭅ "2022-01-23T22:31:35Z"
2022-01-23T14:31:36
db.set
db["dropbox_state"] ⭅ {"path":"/Martian Groceries","recursive":true,"cursor":"AAG0e496Pvx5q_4Vc6ip2anA9Zwf88svnoEmGR840_speWgQCnqITYtI1NWePrmupLYyL-MM5LAQDYEfvFx7VR2MobXUBsSTTWLiQPmpSxl6Kwvz7k01xGZO6IZ347r6RwIUkCa4qxRYmOvSWfzcZ9AqP7QJCj92bdINEpOGsiMbLgkIUmJiGAAj7ty3CQrPTCOhOc-YRq5SQPyNfAPVeVp9-lr0rVE9EDPyHFtDDOHWCQ"}
2022-01-23T14:31:36
db.get
db["dropbox_state"] ⭆ {"path":"/Martian Groceries","recursive":true,"cursor":"AAH_1-lTNlONoF3NaG_HytW5OGsgMfe_OIRq2SMRmGQxZUMuCmiUzIUC4GpC3-4VBDeDPiZ3BAOqPiVOzDVFjMkaUOOXuBr5iBYynXfdocNhKfTUPiqzQ3ccYjKpFXenteFWLgqqy_lV7ZXH2Q38oAxIx67vJ67MhpyXBhqy3zKNusUfkYzlqnWe6bbU9T9WOg--K9j0GZxfLqa65ChZscsaCJUBg69UaTluZT5rQv122w"}
2022-01-23T14:31:36
db.get
db["last_file_mod_time"] ⭆ "2022-01-23T22:31:01.897Z"
2022-01-23T14:31:36
start
Apphook Notification
vellames commented 2 years ago

@elibenton I will check it cc: @dannyroosevelt

dannyroosevelt commented 2 years ago

@elibenton I will check it cc: @dannyroosevelt

@vellames-turing none of the sources are working for me either

dannyroosevelt commented 2 years ago

Looks like some of the async options are failing due to needing to be refactored for withLabel (tracking that work in https://github.com/PipedreamHQ/pipedream/issues/2073)

vellames commented 2 years ago

Looks like some of the async options are failing due to needing to be refactored for withLabel (tracking that work in #2073)

I am finishing Reddit and I go back here to check these problems. It was working when I pushed, but as you said, this is probably related to withLabel

vellames commented 2 years ago

@michelle0927 Could you please review the last commits?

dannyroosevelt commented 2 years ago

@vellames-turing plz merge when ready!

vellames commented 2 years ago

@michelle0927 Looks like your approval was dismissed. Could you approve it again, please?

vellames commented 2 years ago

Merged