Skip to content

Commit 747949b

Browse files
committed
add: tinypng, todoist
1 parent 91bf402 commit 747949b

File tree

6 files changed

+29
-58
lines changed

6 files changed

+29
-58
lines changed

components/tinypng/actions/compress-image/compress-image.mjs

Lines changed: 13 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,14 @@
1-
import { ConfigurationError } from "@pipedream/platform";
2-
import fs from "fs";
3-
import { IMAGE_TYPES } from "../../common/constants.mjs";
4-
import { checkTmp } from "../../common/utils.mjs";
1+
import { getFileStreamAndMetadata } from "@pipedream/platform";
52
import tinypng from "../../tinypng.app.mjs";
63

74
export default {
85
key: "tinypng-compress-image",
96
name: "Compress Image",
107
description: "Compress a WebP, JPEG, or PNG image using the TinyPNG API. [See the documentation](https://tinypng.com/developers/reference#compressing-images)",
11-
version: "0.0.1",
8+
version: "0.1.0",
129
type: "action",
1310
props: {
1411
tinypng,
15-
url: {
16-
propDefinition: [
17-
tinypng,
18-
"url",
19-
],
20-
},
2112
file: {
2213
propDefinition: [
2314
tinypng,
@@ -26,36 +17,19 @@ export default {
2617
},
2718
},
2819
async run({ $ }) {
29-
if (!this.url && !this.file) {
30-
throw new Error("You must provide either a URL or a file for compression.");
31-
}
32-
33-
let data;
34-
let headers = {};
35-
36-
if (this.url) {
37-
data = {
38-
source: {
39-
url: this.url,
40-
},
41-
};
42-
}
43-
44-
if (this.file) {
45-
const fileData = this.file.split(".");
46-
const ext = fileData[1];
47-
48-
if (!IMAGE_TYPES.includes(ext)) {
49-
throw new ConfigurationError("You can upload either WebP, JPEG or PNG.");
50-
}
51-
const file = fs.readFileSync(checkTmp(this.file));
52-
data = file;
53-
headers = {
54-
"Content-Type": `image/${ext}`,
55-
"content-disposition": "attachment; filename=" + fileData[0],
56-
};
20+
const {
21+
stream, metadata,
22+
} = await getFileStreamAndMetadata(this.file);
5723

24+
const chunks = [];
25+
for await (const chunk of stream) {
26+
chunks.push(chunk);
5827
}
28+
const data = Buffer.concat(chunks);
29+
const headers = {
30+
"Content-Type": metadata.contentType,
31+
"content-disposition": "attachment; filename=" + metadata.name,
32+
};
5933

6034
const response = await this.tinypng.compressImage({
6135
$,

components/tinypng/package.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/tinypng",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream TinyPNG AI Components",
55
"main": "tinypng.app.mjs",
66
"keywords": [
@@ -13,8 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.5.1",
17-
"fs": "^0.0.1-security",
16+
"@pipedream/platform": "^3.1.0",
1817
"stream": "^0.0.2",
1918
"util": "^0.12.5"
2019
}

components/tinypng/tinypng.app.mjs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,10 @@ export default {
55
type: "app",
66
app: "tinypng",
77
propDefinitions: {
8-
url: {
9-
type: "string",
10-
label: "Image URL",
11-
description: "URL of the image to compress (WebP, JPEG, or PNG).",
12-
optional: true,
13-
},
148
file: {
159
type: "string",
16-
label: "Image File",
17-
description: "The path to the image file (WebP, JPEG, or PNG) saved to the `/tmp` directory (e.g. `/tmp/example.jpg`). [See the documentation](https://pipedream.com/docs/workflows/steps/code/nodejs/working-with-files/#the-tmp-directory).",
18-
optional: true,
10+
label: "Image Path or URL",
11+
description: "The image to upload (WebP, JPEG, or PNG). Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.png`)",
1912
},
2013
imageId: {
2114
type: "string",

components/todoist/actions/import-tasks/import-tasks.mjs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import todoist from "../../todoist.app.mjs";
2-
import fs from "fs";
32
import converter from "json-2-csv";
3+
import { getFileStream } from "@pipedream/platform";
44

55
export default {
66
key: "todoist-import-tasks",
77
name: "Import Tasks",
88
description: "Import tasks into a selected project. [See Docs](https://developer.todoist.com/sync/v9/#add-an-item)",
9-
version: "0.0.3",
9+
version: "0.1.0",
1010
type: "action",
1111
props: {
1212
todoist,
@@ -37,7 +37,12 @@ export default {
3737
project,
3838
} = this;
3939

40-
const fileContents = (await fs.promises.readFile(path)).toString();
40+
const stream = await getFileStream(path);
41+
const chunks = [];
42+
for await (const chunk of stream) {
43+
chunks.push(chunk);
44+
}
45+
const fileContents = Buffer.concat(chunks).toString();
4146
const tasks = await converter.csv2jsonAsync(fileContents);
4247
// CREATE TASKS
4348
const data = tasks.map((task) => ({

components/todoist/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/todoist",
3-
"version": "0.1.4",
3+
"version": "0.2.0",
44
"description": "Pipedream Todoist Components",
55
"main": "todoist.app.mjs",
66
"keywords": [
@@ -10,7 +10,7 @@
1010
"homepage": "https://pipedream.com/apps/todoist",
1111
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
1212
"dependencies": {
13-
"@pipedream/platform": "^3.0.3",
13+
"@pipedream/platform": "^3.1.0",
1414
"json-2-csv": "^3.15.1",
1515
"query-string": "^7.1.3",
1616
"tmp-promise": "^3.0.3",

components/todoist/todoist.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,8 @@ export default {
255255
},
256256
path: {
257257
type: "string",
258-
label: "File Path",
259-
description: "Path to .csv file containing task data. Enter a static value (e.g., `/tmp/myFile.csv`) or reference prior step exports via the `steps` object (e.g., `{{steps.export_tasks.$return_value}}`).",
258+
label: "File Path or URL",
259+
description: "The .csv file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.csv`)",
260260
},
261261
},
262262
methods: {

0 commit comments

Comments
 (0)