-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
[Components] zip_archive_api #11789 #11827
Changes from all commits
ea2e20f
1795653
fa0ec12
a831338
ce4983e
2eb196c
7cffdea
fcbe336
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import app from "../../zip_archive_api.app.mjs"; | ||
import fs from "fs"; | ||
import FormData from "form-data"; | ||
|
||
export default { | ||
key: "zip_archive_api-compress-files", | ||
name: "Compress Files", | ||
description: "Compress files provided through URLs into a zip folder. [See the documentation](https://archiveapi.com/rest-api/file-compression/)", | ||
version: "0.0.1", | ||
type: "action", | ||
props: { | ||
app, | ||
uploadType: { | ||
propDefinition: [ | ||
app, | ||
"uploadType", | ||
], | ||
}, | ||
archiveName: { | ||
propDefinition: [ | ||
app, | ||
"archiveName", | ||
], | ||
}, | ||
compressionLevel: { | ||
propDefinition: [ | ||
app, | ||
"compressionLevel", | ||
], | ||
}, | ||
password: { | ||
propDefinition: [ | ||
app, | ||
"password", | ||
], | ||
}, | ||
files: { | ||
propDefinition: [ | ||
app, | ||
"files", | ||
], | ||
}, | ||
}, | ||
async run({ $ }) { | ||
let data = { | ||
files: this.files, | ||
archiveName: this.archiveName, | ||
compressionLevel: this.compressionLevel, | ||
password: this.password, | ||
}; | ||
|
||
if (this.uploadType === "File") { | ||
data = new FormData(); | ||
|
||
if (this.password) data.append("Password", this.password); | ||
if (this.compressionLevel) data.append("CompressionLevel", this.compressionLevel); | ||
data.append("ArchiveName", this.archiveName); | ||
|
||
for (const file of this.files) { | ||
data.append("Files", fs.createReadStream(file)); | ||
} | ||
} | ||
|
||
const headers = this.uploadType === "File" | ||
? data.getHeaders() | ||
: {}; | ||
|
||
const response = await this.app.compressFiles({ | ||
$, | ||
data, | ||
headers, | ||
responseType: "arraybuffer", | ||
}); | ||
|
||
const tmpPath = `/tmp/${this.archiveName}`; | ||
fs.writeFileSync(tmpPath, response); | ||
|
||
$.export("$summary", `Successfully compressed the files into '${tmpPath}'`); | ||
|
||
return tmpPath; | ||
}, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
UPLOAD_TYPES: [ | ||
"URL", | ||
"File", | ||
], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "@pipedream/zip_archive_api", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Pipedream Zip Archive API Components", | ||
"main": "zip_archive_api.app.mjs", | ||
"keywords": [ | ||
|
@@ -11,5 +11,9 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^1.6.5", | ||
"form-data": "^4.0.0" | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,71 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import constants from "./common/constants.mjs"; | ||
|
||
export default { | ||
type: "app", | ||
app: "zip_archive_api", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
uploadType: { | ||
type: "string", | ||
label: "Upload Type", | ||
description: "The upload type of the file", | ||
options: constants.UPLOAD_TYPES, | ||
}, | ||
archiveName: { | ||
type: "string", | ||
label: "Archive Name", | ||
description: "Compressed archive name", | ||
}, | ||
compressionLevel: { | ||
type: "integer", | ||
label: "Compression Level", | ||
description: "Archive compression level. Value range: 1-9", | ||
optional: true, | ||
}, | ||
password: { | ||
type: "string", | ||
label: "Password", | ||
description: "The compressed ZIP archive password", | ||
optional: true, | ||
}, | ||
files: { | ||
type: "string[]", | ||
label: "Files URLs", | ||
description: "The URLs or path of the files to be compressed", | ||
}, | ||
file: { | ||
type: "string", | ||
label: "File URL", | ||
description: "The URL or path of the archive to extract the files from", | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://api.archiveapi.com"; | ||
}, | ||
async _makeRequest(opts = {}) { | ||
const { | ||
$ = this, | ||
path, | ||
params, | ||
...otherOpts | ||
} = opts; | ||
|
||
return axios($, { | ||
...otherOpts, | ||
url: this._baseUrl() + path, | ||
params: { | ||
...params, | ||
secret: `${this.$auth.secret}`, | ||
}, | ||
}); | ||
}, | ||
Comment on lines
+46
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Review: The
Consider the following improvements:
|
||
async compressFiles(args = {}) { | ||
return this._makeRequest({ | ||
method: "post", | ||
path: "/zip", | ||
...args, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review of the
run
MethodThe
run
method is structured to handle different types of uploads based onuploadType
. The use ofFormData
for file uploads is appropriate. The method handles the compression settings and file handling robustly. Key observations:uploadType
, which is a good practice for handling different input types.fs.createReadStream
for file uploads ensures that large files can be handled efficiently.However, there are a few areas that could be improved:
Consider adding try-catch blocks around the API call and file operations to handle errors gracefully. Additionally, ensure that temporary files are securely handled or cleaned up after use to avoid potential security risks.
Here's a suggested refactor for error handling:
Committable suggestion