Skip to content

Commit b7b190b

Browse files
committed
add: raindrop, ramp, reform
1 parent 9d2183e commit b7b190b

File tree

7 files changed

+42
-66
lines changed

7 files changed

+42
-66
lines changed

components/raindrop/actions/parse-bookmark-file/parse-bookmark-file.mjs

Lines changed: 13 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,31 @@
11
import raindrop from "../../raindrop.app.mjs";
2-
import fs from "fs";
3-
import got from "got";
4-
import stream from "stream";
5-
import { promisify } from "util";
2+
import { getFileStreamAndMetadata } from "@pipedream/platform";
63
import FormData from "form-data";
74

85
export default {
96
key: "raindrop-parse-bookmark-file",
107
name: "Parse HTML Bookmark File",
11-
description: "Convert HTML bookmark file to JSON. Support Nestcape, Pocket and Instapaper file formats. [See the docs here](https://developer.raindrop.io/v1/import#parse-html-import-file)",
12-
version: "0.0.7",
8+
description: "Convert an HTML bookmark file to JSON. Supports Nestcape, Pocket and Instapaper file formats. [See the documentation](https://developer.raindrop.io/v1/import#parse-html-import-file)",
9+
version: "0.1.0",
1310
type: "action",
1411
props: {
1512
raindrop,
16-
fileUrl: {
17-
type: "string",
18-
label: "File URL",
19-
description: "The URL of the HTML bookmark file you want to convert. Must specify either File URL or File Path.",
20-
optional: true,
21-
},
2213
filePath: {
2314
type: "string",
24-
label: "File Path",
25-
description: "The path to the file, e.g. /tmp/bookmarks.html . Must specify either File URL or File Path.",
26-
optional: true,
15+
label: "File Path or URL",
16+
description: "The file to parse. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/bookmarks.html`)",
2717
},
2818
},
2919
async run({ $ }) {
30-
const {
31-
fileUrl,
32-
filePath,
33-
} = this;
34-
35-
if (!fileUrl && !filePath) {
36-
throw new Error("Must specify either File URL or File Path");
37-
}
38-
3920
const form = new FormData();
40-
if (filePath) {
41-
if (!fs.existsSync(filePath)) {
42-
throw new Error(`${filePath} does not exists`);
43-
}
44-
const readStream = fs.createReadStream(filePath);
45-
form.append("import", readStream);
46-
} else if (fileUrl) {
47-
const tempFilePath = "/tmp/temp_bookmarks.html";
48-
const pipeline = promisify(stream.pipeline);
49-
await pipeline(
50-
got.stream(fileUrl),
51-
fs.createWriteStream(tempFilePath),
52-
);
53-
const readStream = fs.createReadStream(tempFilePath);
54-
form.append("import", readStream);
55-
}
21+
const {
22+
stream, metadata,
23+
} = getFileStreamAndMetadata(this.filePath);
24+
form.append("import", stream, {
25+
contentType: metadata.contentType,
26+
knownLength: metadata.size,
27+
filename: metadata.name,
28+
});
5629

5730
const response = await this.raindrop.importFile($, form);
5831
$.export("$summary", "Successfully parsed bookmark file");

components/raindrop/package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/raindrop",
3-
"version": "0.3.14",
3+
"version": "0.4.0",
44
"description": "Pipedream Raindrop.io Components",
55
"main": "raindrop.app.mjs",
66
"keywords": [
@@ -17,10 +17,7 @@
1717
"access": "public"
1818
},
1919
"dependencies": {
20-
"@pipedream/platform": "^1.2.0",
21-
"form-data": "^4.0.0",
22-
"got": "^13.0.0",
23-
"stream": "^0.0.2",
24-
"util": "^0.12.5"
20+
"@pipedream/platform": "^3.1.0",
21+
"form-data": "^4.0.0"
2522
}
2623
}

components/ramp/actions/upload-receipt/upload-receipt.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import ramp from "../../ramp.app.mjs";
22
import { v4 as uuidv4 } from "uuid";
3-
import fs from "fs";
3+
import { getFileStream } from "@pipedream/platform";
44

55
export default {
66
key: "ramp-upload-receipt",
77
name: "Upload Receipt",
88
description: "Uploads a receipt for a given transaction and user. [See the documentation](https://docs.ramp.com/developer-api/v1/reference/rest/receipts#post-developer-v1-receipts)",
9-
version: "0.0.2",
9+
version: "0.1.0",
1010
type: "action",
1111
props: {
1212
ramp,
@@ -24,8 +24,8 @@ export default {
2424
},
2525
filePath: {
2626
type: "string",
27-
label: "File Path",
28-
description: "The path to a file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
27+
label: "File Path or URL",
28+
description: "The file to upload. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
2929
},
3030
},
3131
async run({ $ }) {
@@ -42,9 +42,12 @@ export default {
4242
`--${boundary}\r\n` +
4343
`Content-Disposition: attachment; name="receipt"; filename="${this.filePath.split("/").pop()}"\r\n\r\n`;
4444

45-
const fileContent = fs.readFileSync(this.filePath.includes("tmp/")
46-
? this.filePath
47-
: `/tmp/${this.filePath}`);
45+
const stream = getFileStream(this.filePath);
46+
const chunks = [];
47+
for await (const chunk of stream) {
48+
chunks.push(chunk);
49+
}
50+
const fileContent = Buffer.concat(chunks);
4851

4952
const formEnd = `\r\n--${boundary}--`;
5053

components/ramp/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/ramp",
3-
"version": "0.1.2",
3+
"version": "0.2.0",
44
"description": "Pipedream Ramp Components",
55
"main": "ramp.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^3.0.0",
16+
"@pipedream/platform": "^3.1.0",
1717
"uuid": "^10.0.0"
1818
}
1919
}

components/reform/actions/extract-data-from-document/extract-data-from-document.mjs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import reform from "../../reform.app.mjs";
22
import utils from "../common/utils.mjs";
33
import FormData from "form-data";
4-
import fs from "fs";
4+
import { getFileStreamAndMetadata } from "@pipedream/platform";
55

66
export default {
77
key: "reform-extract-data-from-document",
88
name: "Extract Data From Document",
99
description: "Extract structured data from a document. [See the documentation](https://docs.reformhq.com/synchronous-data-processing/extract)",
10-
version: "0.0.1",
10+
version: "0.1.0",
1111
type: "action",
1212
props: {
1313
reform,
@@ -26,12 +26,15 @@ export default {
2626
},
2727
async run({ $ }) {
2828
const fields = utils.parseFields(this.fields);
29-
const documentPath = this.document.includes("tmp/")
30-
? this.document
31-
: `/tmp/${this.document}`;
32-
3329
const formData = new FormData();
34-
formData.append("document", fs.createReadStream(documentPath));
30+
const {
31+
stream, metadata,
32+
} = getFileStreamAndMetadata(this.document);
33+
formData.append("document", stream, {
34+
filename: metadata.name,
35+
contentType: metadata.contentType,
36+
knownLength: metadata.size,
37+
});
3538
formData.append("fields_to_extract", JSON.stringify(fields));
3639

3740
const response = await this.reform.extractDataFromDocument({

components/reform/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/reform",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pipedream Reform Components",
55
"main": "reform.app.mjs",
66
"keywords": [
@@ -13,7 +13,7 @@
1313
"access": "public"
1414
},
1515
"dependencies": {
16-
"@pipedream/platform": "^1.6.0",
16+
"@pipedream/platform": "^3.1.0",
1717
"form-data": "^4.0.0"
1818
}
1919
}

components/reform/reform.app.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default {
66
propDefinitions: {
77
document: {
88
type: "string",
9-
label: "Document",
10-
description: "The path to a document file in the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#the-tmp-directory).",
9+
label: "File Path or URL",
10+
description: "The file to process. Provide either a file URL or a path to a file in the `/tmp` directory (for example, `/tmp/myFile.txt`)",
1111
},
1212
fields: {
1313
type: "string[]",

0 commit comments

Comments
 (0)