Skip to content

Commit a2f4c83

Browse files
committed
some adjusts
1 parent a8e69b0 commit a2f4c83

File tree

6 files changed

+93
-215
lines changed

6 files changed

+93
-215
lines changed

components/alttextify/actions/delete-image/delete-image.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export default {
99
props: {
1010
alttextify,
1111
assetId: {
12-
type: "string",
13-
label: "Asset ID",
12+
propDefinition: [
13+
alttextify,
14+
"assetId",
15+
],
1416
description: "The ID of the asset for retrieving or deleting alt text.",
1517
},
1618
},

components/alttextify/actions/get-alttext-by-asset-id/get-alttext-by-asset-id.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ export default {
99
props: {
1010
alttextify,
1111
assetId: {
12-
type: "string",
13-
label: "Asset ID",
14-
description: "The ID of the asset for retrieving alt text.",
12+
propDefinition: [
13+
alttextify,
14+
"assetId",
15+
],
1516
},
1617
},
1718
async run({ $ }) {

components/alttextify/actions/get-alttext-by-job-id/get-alttext-by-job-id.mjs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ export default {
99
props: {
1010
alttextify,
1111
jobId: {
12-
type: "string",
13-
label: "Job ID",
12+
propDefinition: [
13+
alttextify,
14+
"assetId",
15+
],
1416
description: "The ID of the job for retrieving alt text.",
1517
},
1618
},

components/alttextify/actions/submit-image-from-url/submit-image-from-url.mjs

Lines changed: 0 additions & 107 deletions
This file was deleted.

components/alttextify/actions/submit-image/submit-image.mjs

Lines changed: 66 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import fs from "fs";
1+
import { getFileStreamAndMetadata } from "@pipedream/platform";
22
import alttextify from "../../alttextify.app.mjs";
3-
import { checkTmp } from "../../common/utils.mjs";
43

54
export default {
65
key: "alttextify-submit-image",
@@ -16,80 +15,99 @@ export default {
1615
content: "Supported formats: JPEG, PNG, GIF, WEBP, BMP\nMaximum file size: 16 MB\nMinimum dimensions: 50 x 50 (smaller images may not be able to generate alt text).",
1716
},
1817
async: {
19-
propDefinition: [
20-
alttextify,
21-
"async",
22-
],
18+
type: "boolean",
19+
label: "Async",
20+
description: "Whether to add the image in the background or immediately (synchronously). If async is set to true, the API response will always be successful with an empty response body.",
21+
default: false,
2322
},
2423
image: {
2524
type: "string",
26-
label: "Image Path",
27-
description: "The path to the image 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)",
25+
label: "Image",
26+
description: "The URL of the file or path to the file saved to the `/tmp` directory. [See the documentation on working with files](https://pipedream.com/docs/code/nodejs/working-with-files/#writing-a-file-to-tmp)",
2827
},
2928
lang: {
30-
propDefinition: [
31-
alttextify,
32-
"lang",
33-
],
29+
type: "string",
30+
label: "Language",
31+
description: "The language for the alt text. Supported language codes are accepted. If not provided, the account's default language is used.",
32+
default: "en",
3433
},
3534
maxChars: {
36-
propDefinition: [
37-
alttextify,
38-
"maxChars",
39-
],
35+
type: "integer",
36+
label: "Max Characters",
37+
description: "Maximum length of the generated alt text.",
4038
},
4139
assetId: {
42-
propDefinition: [
43-
alttextify,
44-
"assetId",
45-
],
40+
type: "string",
41+
label: "Asset ID",
42+
description: "The unique identifier for the asset.",
43+
optional: true,
4644
},
4745
keywords: {
48-
propDefinition: [
49-
alttextify,
50-
"keywords",
51-
],
46+
type: "string[]",
47+
label: "Keywords",
48+
description: "List of keywords/phrases for SEO-optimized alt text. Only one or two will be used per alt text, but all are considered. Keywords must be in English, even for alt text in other languages.",
49+
optional: true,
5250
},
5351
ecommerceRunOCR: {
54-
propDefinition: [
55-
alttextify,
56-
"ecommerceRunOCR",
57-
],
52+
type: "boolean",
53+
label: "Ecommerce Run OCR",
54+
description: "Flag to indicate if OCR should be run on the product.",
5855
},
5956
ecommerceProductName: {
60-
propDefinition: [
61-
alttextify,
62-
"ecommerceProductName",
63-
],
57+
type: "string",
58+
label: "Ecommerce Product Name",
59+
description: "The name of the product in the image.",
60+
optional: true,
6461
},
6562
ecommerceProductBrand: {
66-
propDefinition: [
67-
alttextify,
68-
"ecommerceProductBrand",
69-
],
63+
type: "string",
64+
label: "Ecommerce Product Brand",
65+
description: "The brand of the product in the image.",
66+
optional: true,
7067
},
7168
ecommerceProductColor: {
72-
propDefinition: [
73-
alttextify,
74-
"ecommerceProductColor",
75-
],
69+
type: "string",
70+
label: "Ecommerce Product Color",
71+
description: "The color of the product in the image.",
72+
optional: true,
7673
},
7774
ecommerceProductSize: {
78-
propDefinition: [
79-
alttextify,
80-
"ecommerceProductSize",
81-
],
75+
type: "string",
76+
label: "Ecommerce Product Size",
77+
description: "The size of the product in the image.",
78+
optional: true,
79+
},
80+
},
81+
methods: {
82+
async streamToBase64(stream) {
83+
return new Promise((resolve, reject) => {
84+
let base64String = "";
85+
86+
stream.on("data", (chunk) => {
87+
base64String += Buffer.from(chunk).toString("base64");
88+
});
89+
90+
stream.on("end", () => {
91+
resolve(base64String);
92+
});
93+
94+
stream.on("error", (err) => {
95+
reject(err);
96+
});
97+
});
8298
},
8399
},
84100
async run({ $ }) {
85-
const imagePath = checkTmp(this.image);
86-
const image = fs.readFileSync(imagePath, "base64");
101+
const {
102+
stream, metadata,
103+
} = await getFileStreamAndMetadata(this.image);
104+
const base64String = await this.streamToBase64(stream);
87105

88106
const response = await this.alttextify.uploadImage({
89107
$,
90108
data: {
91109
async: this.async,
92-
image: `data:image/${imagePath.split(".")[1]};base64,${image}`,
110+
image: `data:${metadata.contentType};base64,${base64String}`,
93111
lang: this.lang,
94112
maxChars: this.maxChars,
95113
assetId: this.assetId,
@@ -104,6 +122,7 @@ export default {
104122
},
105123
},
106124
},
125+
107126
});
108127

109128
$.export("$summary", `Successfully submitted image to Alttextify for alt text generation with Asset ID: ${response.asset_id}`);

components/alttextify/alttextify.app.mjs

Lines changed: 15 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,63 +4,24 @@ export default {
44
type: "app",
55
app: "alttextify",
66
propDefinitions: {
7-
async: {
8-
type: "boolean",
9-
label: "Async",
10-
description: "whether to add the image in the background or immediately (synchronously). If async is set to true, the API response will always be successful with an empty response body.",
11-
default: false,
12-
},
13-
lang: {
14-
type: "string",
15-
label: "Language",
16-
description: "The language for the alt text. Supported language codes are accepted. If not provided, the account's default language is used.",
17-
default: "en",
18-
},
19-
maxChars: {
20-
type: "integer",
21-
label: "Max Characters",
22-
description: "Maximum length of the generated alt text.",
23-
},
247
assetId: {
258
type: "string",
269
label: "Asset ID",
27-
description: "The unique identifier for the asset.",
28-
optional: true,
29-
},
30-
keywords: {
31-
type: "string[]",
32-
label: "Keywords",
33-
description: "List of keywords/phrases for SEO-optimized alt text. Only one or two will be used per alt text, but all are considered. Keywords must be in English, even for alt text in other languages.",
34-
optional: true,
35-
},
36-
ecommerceRunOCR: {
37-
type: "boolean",
38-
label: "Ecommerce Run OCR",
39-
description: "Flag to indicate if OCR should be run on the product.",
40-
},
41-
ecommerceProductName: {
42-
type: "string",
43-
label: "Ecommerce Product Name",
44-
description: "The name of the product in the image.",
45-
optional: true,
46-
},
47-
ecommerceProductBrand: {
48-
type: "string",
49-
label: "Ecommerce Product Brand",
50-
description: "The brand of the product in the image.",
51-
optional: true,
52-
},
53-
ecommerceProductColor: {
54-
type: "string",
55-
label: "Ecommerce Product Color",
56-
description: "The color of the product in the image.",
57-
optional: true,
58-
},
59-
ecommerceProductSize: {
60-
type: "string",
61-
label: "Ecommerce Product Size",
62-
description: "The size of the product in the image.",
63-
optional: true,
10+
description: "The ID of the asset for retrieving alt text.",
11+
async options({ page }) {
12+
const data = await this.listAltTexts({
13+
params: {
14+
page: page + 1,
15+
},
16+
});
17+
18+
return data.map(({
19+
asset_id: value, alt_text: label,
20+
}) => ({
21+
label,
22+
value,
23+
}));
24+
},
6425
},
6526
},
6627
methods: {

0 commit comments

Comments
 (0)