- 
                Notifications
    
You must be signed in to change notification settings  - Fork 5.5k
 
[Components] PixelBin: New action components #14146
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
                    Changes from all commits
      Commits
    
    
  File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            52 changes: 52 additions & 0 deletions
          
          52 
        
  components/pixelbin/actions/create-folder/create-folder.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import app from "../../pixelbin.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "pixelbin-create-folder", | ||
| name: "Create Folder", | ||
| description: "Creates a new folder in Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| name: { | ||
| optional: false, | ||
| description: "Name of the folder.", | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| path: { | ||
| description: "Path of the containing folder. Eg. `folder1/folder2`.", | ||
| propDefinition: [ | ||
| app, | ||
| "path", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| createFolder(args = {}) { | ||
| return this.app.post({ | ||
| path: "/folders", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| createFolder, | ||
| name, | ||
| path, | ||
| } = this; | ||
| 
     | 
||
| const response = await createFolder({ | ||
| $, | ||
| data: { | ||
| name, | ||
| path, | ||
| }, | ||
| }); | ||
| $.export("$summary", `Successfully created folder with ID \`${response._id}\`.`); | ||
| return response; | ||
| }, | ||
| }; | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import app from "../../pixelbin.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "pixelbin-delete-file", | ||
| name: "Delete File", | ||
| description: "Deletes a file from Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| path: { | ||
| optional: false, | ||
| propDefinition: [ | ||
| app, | ||
| "path", | ||
| () => ({ | ||
| params: { | ||
| onlyFolders: false, | ||
| onlyFiles: true, | ||
| }, | ||
| }), | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| deleteFile({ | ||
| path, ...args | ||
| }) { | ||
| return this.app.delete({ | ||
| path: `/files/${path}`, | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| deleteFile, | ||
| path, | ||
| } = this; | ||
| const response = await deleteFile({ | ||
| $, | ||
| path, | ||
| }); | ||
| $.export("$summary", `Successfully deleted file with ID \`${response._id}\`.`); | ||
| return response; | ||
| }, | ||
| }; | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import app from "../../pixelbin.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "pixelbin-list-files", | ||
| name: "List Files", | ||
| description: "List all files. [See the documentation](https://www.pixelbin.io/docs/api-docs/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| name: { | ||
| description: "Find items with matching name.", | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| path: { | ||
| description: "Find items with matching path.", | ||
| propDefinition: [ | ||
| app, | ||
| "path", | ||
| ], | ||
| }, | ||
| format: { | ||
| type: "string", | ||
| label: "Format", | ||
| description: "Find items with matching format.", | ||
| optional: true, | ||
| }, | ||
| tags: { | ||
| description: "Find items containing these tags", | ||
| propDefinition: [ | ||
| app, | ||
| "tags", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| name, | ||
| path, | ||
| format, | ||
| tags, | ||
| } = this; | ||
| 
     | 
||
| const result = await app.paginate({ | ||
| resourcesFn: app.listFiles, | ||
| resourcesFnArgs: { | ||
| $, | ||
| params: { | ||
| name, | ||
| path, | ||
| format, | ||
| tags, | ||
| onlyFiles: true, | ||
| }, | ||
| }, | ||
| resourceName: "items", | ||
| }); | ||
| $.export("$summary", `Successfully listed \`${result.length}\` file(s).`); | ||
| return result; | ||
| }, | ||
| }; | 
        
          
          
            97 changes: 97 additions & 0 deletions
          
          97 
        
  components/pixelbin/actions/upload-asset-url/upload-asset-url.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import app from "../../pixelbin.app.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "pixelbin-upload-asset-url", | ||
| name: "Upload Asset From URL", | ||
| description: "Uploads an asset to Pixelbin from a given URL. [See the documentation](https://www.pixelbin.io/docs/api-docs/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| url: { | ||
| type: "string", | ||
| label: "URL", | ||
| description: "URL of the asset you want to upload.", | ||
| }, | ||
| path: { | ||
| propDefinition: [ | ||
| app, | ||
| "path", | ||
| ], | ||
| }, | ||
| name: { | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| access: { | ||
| propDefinition: [ | ||
| app, | ||
| "access", | ||
| ], | ||
| }, | ||
| tags: { | ||
| propDefinition: [ | ||
| app, | ||
| "tags", | ||
| ], | ||
| }, | ||
| metadata: { | ||
| propDefinition: [ | ||
| app, | ||
| "metadata", | ||
| ], | ||
| }, | ||
| overwrite: { | ||
| propDefinition: [ | ||
| app, | ||
| "overwrite", | ||
| ], | ||
| }, | ||
| filenameOverride: { | ||
| propDefinition: [ | ||
| app, | ||
| "filenameOverride", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| uploadAssetFromUrl(args = {}) { | ||
| return this.app.post({ | ||
| path: "/upload/url", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| uploadAssetFromUrl, | ||
| url, | ||
| path, | ||
| name, | ||
| access, | ||
| tags, | ||
| metadata, | ||
| overwrite, | ||
| filenameOverride, | ||
| } = this; | ||
| 
     | 
||
| const response = await uploadAssetFromUrl({ | ||
| $, | ||
| data: { | ||
| url, | ||
| path, | ||
| name, | ||
| access, | ||
| tags, | ||
| metadata, | ||
| overwrite, | ||
| filenameOverride, | ||
| }, | ||
| }); | ||
| 
     | 
||
| $.export("$summary", `Successfully uploaded asset with ID: \`${response._id}\`.`); | ||
| return response; | ||
| }, | ||
| }; | 
        
          
          
            112 changes: 112 additions & 0 deletions
          
          112 
        
  components/pixelbin/actions/upload-file/upload-file.mjs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| import fs from "fs"; | ||
| import FormData from "form-data"; | ||
| import { ConfigurationError } from "@pipedream/platform"; | ||
| import app from "../../pixelbin.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
| 
     | 
||
| export default { | ||
| key: "pixelbin-upload-file", | ||
| name: "Upload File", | ||
| description: "Upload a file to Pixelbin. [See the documentation](https://www.pixelbin.io/docs/api-docs/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| filePath: { | ||
| type: "string", | ||
| label: "File Path", | ||
| description: "Assete file path. The path to the file saved to the `/tmp` directory (e.g. `/tmp/example.pdf`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).", | ||
| }, | ||
| path: { | ||
| propDefinition: [ | ||
| app, | ||
| "path", | ||
| ], | ||
| }, | ||
| name: { | ||
| propDefinition: [ | ||
| app, | ||
| "name", | ||
| ], | ||
| }, | ||
| access: { | ||
| propDefinition: [ | ||
| app, | ||
| "access", | ||
| ], | ||
| }, | ||
| tags: { | ||
| propDefinition: [ | ||
| app, | ||
| "tags", | ||
| ], | ||
| }, | ||
| metadata: { | ||
| propDefinition: [ | ||
| app, | ||
| "metadata", | ||
| ], | ||
| }, | ||
| overwrite: { | ||
| propDefinition: [ | ||
| app, | ||
| "overwrite", | ||
| ], | ||
| }, | ||
| filenameOverride: { | ||
| propDefinition: [ | ||
| app, | ||
| "filenameOverride", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| uploadFile(args = {}) { | ||
| return this.app.post({ | ||
| path: "/upload/direct", | ||
| headers: { | ||
| "Content-Type": "multipart/form-data", | ||
| }, | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| uploadFile, | ||
| filePath, | ||
| path, | ||
| name, | ||
| access, | ||
| tags, | ||
| metadata, | ||
| overwrite, | ||
| filenameOverride, | ||
| } = this; | ||
| 
     | 
||
| if (!filePath.startsWith("/tmp/")) { | ||
| throw new ConfigurationError("File must be located in `/tmp` directory."); | ||
| } | ||
| 
     | 
||
| const data = new FormData(); | ||
| data.append("file", fs.createReadStream(filePath)); | ||
| 
     | 
||
| utils.appendPropsToFormData(data, { | ||
| path, | ||
| name, | ||
| access, | ||
| tags, | ||
| metadata, | ||
| overwrite, | ||
| filenameOverride, | ||
| }); | ||
| 
     | 
||
| const response = await uploadFile({ | ||
| $, | ||
| data, | ||
| }); | ||
| 
     | 
||
| $.export("$summary", `Successfully uploaded file with ID \`${response._id}\`.`); | ||
| return response; | ||
| }, | ||
| }; | 
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.