- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.5k
Add optional file download URL to file-related source emits #18269
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 6 commits
      Commits
    
    
            Show all changes
          
          
            12 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      7c91646
              
                add includeLink
              
              
                michelle0927 4f63013
              
                pnpm-lock.yaml
              
              
                michelle0927 5b775d4
              
                versions
              
              
                michelle0927 73d4472
              
                pnpm-lock.yaml
              
              
                michelle0927 fa9b831
              
                updates
              
              
                michelle0927 1d5cb52
              
                pnpm-lock.yaml
              
              
                michelle0927 1b885f6
              
                updates
              
              
                michelle0927 aa584bd
              
                updates
              
              
                michelle0927 79b9cd2
              
                Merge remote-tracking branch 'origin/master' into issue-18218
              
              
                michelle0927 a0fa8a0
              
                versions
              
              
                michelle0927 2571b3e
              
                Merge branch 'master' into issue-18218
              
              
                michelle0927 4816bcb
              
                versions
              
              
                michelle0927 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
  
    
      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 | 
|---|---|---|
| @@ -1 +1 @@ | ||
| {"version":2,"languages":{"nodejs-npm":{"guessedImports":["aws-sdk","axios","shortid"],"guessedImportsHash":"08190b61ee0169fd35ea81dce6f4754d"}}} | ||
| {"version":2, "languages":{"nodejs-npm":{"guessedImports":["aws-sdk", "axios", "shortid"], "guessedImportsHash":"08190b61ee0169fd35ea81dce6f4754d"}}} | 
  
    
      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
    
  
  
    
              
  
    
      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,68 @@ | ||
| import { Readable } from "stream"; | ||
| import { fileTypeFromBuffer } from "file-type"; | ||
|  | ||
| export default { | ||
| props: { | ||
| includeLink: { | ||
| label: "Include Link", | ||
| type: "boolean", | ||
| description: "Upload file to your File Stash and emit temporary download link to the file. See [the docs](https://pipedream.com/docs/connect/components/files) to learn more about working with files in Pipedream.", | ||
| default: false, | ||
| optional: true, | ||
| }, | ||
| dir: { | ||
| type: "dir", | ||
| accessMode: "write", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| async streamToBuffer(stream) { | ||
| const chunks = []; | ||
| for await (const chunk of stream) { | ||
| chunks.push(chunk); | ||
| } | ||
| return Buffer.concat(chunks); | ||
| }, | ||
| async stashFile(item) { | ||
| const { Body } = await this.getObject({ | ||
| Bucket: item.bucket.name, | ||
| Key: item.object.key, | ||
| }); | ||
| const filepath = `${item.bucket.name}/${item.object.key}`; | ||
| const buffer = await this.streamToBuffer(Body); | ||
| const type = await fileTypeFromBuffer(buffer); | ||
| // Upload the attachment to the configured directory (File Stash) so it | ||
| // can be accessed later. | ||
| const file = await this.dir.open(filepath).fromReadableStream( | ||
| Readable.from(buffer), | ||
| type?.mime, | ||
| buffer.length, | ||
| ); | ||
| // Return file details and temporary download link: | ||
| // { path, get_url, s3Key, type } | ||
| return await file.withoutPutUrl().withGetUrl(); | ||
| }, | ||
| async processEvent(event) { | ||
| const { Message: rawMessage } = event.body; | ||
| const { | ||
| Records: s3Events = [], | ||
| Event: eventType, | ||
| } = JSON.parse(rawMessage); | ||
|  | ||
| if (eventType === "s3:TestEvent") { | ||
| console.log("Received initial test event. Skipping..."); | ||
| return; | ||
| } | ||
|  | ||
| for (const s3Event of s3Events) { | ||
| const meta = this.generateMeta(s3Event); | ||
| let { s3: item } = s3Event; | ||
| if (this.includeLink) { | ||
| item.file = await this.stashFile(item); | ||
| } | ||
| this.$emit(item, meta); | ||
|         
                  michelle0927 marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| } | ||
| }, | ||
| }, | ||
| }; | ||
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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 | 
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/box", | ||
| "version": "0.5.0", | ||
| "version": "0.5.1", | ||
| "description": "Pipedream Box Components", | ||
| "main": "box.app.mjs", | ||
| "keywords": [ | ||
|  | @@ -11,6 +11,7 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.0", | ||
| "file-type": "^21.0.0", | ||
| "form-data": "^4.0.0", | ||
| "path": "^0.12.7", | ||
| "stream": "^0.0.2", | ||
|  | ||
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
      
      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.