Skip to content

Commit 293d8cc

Browse files
committed
[Components] alttextify #16964
Sources - New Image Processed Actions - Submit Image - Submit Image From URL - Get AltText By Asset ID - Get AltText By Job ID - Delete Image
1 parent 6b059d8 commit 293d8cc

File tree

13 files changed

+391
-358
lines changed

13 files changed

+391
-358
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
import alttextify from "../../alttextify.app.mjs";
2-
import { axios } from "@pipedream/platform";
32

43
export default {
54
key: "alttextify-delete-image",
65
name: "Delete Image Alt Text",
7-
description: "Delete the generated alt text for a specific image using the asset ID. [See the documentation](https://apidoc.alttextify.net/)",
8-
version: "0.0.{{ts}}",
6+
description: "Delete the generated alt text for a specific image using the asset ID. [See the documentation](https://apidoc.alttextify.net/#api-Image-DeleteImage)",
7+
version: "0.0.1",
98
type: "action",
109
props: {
1110
alttextify,
1211
assetId: {
13-
propDefinition: [
14-
alttextify,
15-
"assetId",
16-
],
12+
type: "string",
13+
label: "Asset ID",
14+
description: "The ID of the asset for retrieving or deleting alt text.",
1715
},
1816
},
1917
async run({ $ }) {
2018
const response = await this.alttextify.deleteAltTextByAssetId({
19+
$,
2120
assetId: this.assetId,
2221
});
2322

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import alttextify from "../../alttextify.app.mjs";
2+
3+
export default {
4+
key: "alttextify-get-alttext-by-asset-id",
5+
name: "Retrieve Alt Text by Asset ID",
6+
description: "Retrieve alt text for a previously submitted image using the asset ID. [See the documentation](https://apidoc.alttextify.net/#api-Image-GetImageByAssetID)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
alttextify,
11+
assetId: {
12+
type: "string",
13+
label: "Asset ID",
14+
description: "The ID of the asset for retrieving alt text.",
15+
},
16+
},
17+
async run({ $ }) {
18+
const response = await this.alttextify.retrieveAltTextByAssetId({
19+
$,
20+
assetId: this.assetId,
21+
});
22+
$.export("$summary", `Successfully retrieved alt text by Asset ID: ${this.assetId}`);
23+
24+
return response;
25+
},
26+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import alttextify from "../../alttextify.app.mjs";
2+
3+
export default {
4+
key: "alttextify-get-alttext-by-job-id",
5+
name: "Retrieve Alt Text by Job ID",
6+
description: "Retrieve alt text for a previously submitted image using the job ID. [See the documentation](https://apidoc.alttextify.net/#api-Image-GetImagesByJobID)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
alttextify,
11+
jobId: {
12+
type: "string",
13+
label: "Job ID",
14+
description: "The ID of the job for retrieving alt text.",
15+
},
16+
},
17+
async run({ $ }) {
18+
const response = await this.alttextify.retrieveAltTextByJobId({
19+
$,
20+
jobId: this.jobId,
21+
});
22+
$.export("$summary", `Successfully retrieved alt text by Job ID: ${this.jobId}`);
23+
24+
return response;
25+
},
26+
};

components/alttextify/actions/get-alttext/get-alttext.mjs

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
import alttextify from "../../alttextify.app.mjs";
2+
3+
export default {
4+
key: "alttextify-submit-image-from-url",
5+
name: "Submit Image from URL to Alttextify",
6+
description: "Upload or submit an image URL to Alttextify for alt text generation. [See the documentation](https://apidoc.alttextify.net/#api-Image-UploadImageURL)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
alttextify,
11+
alert: {
12+
type: "alert",
13+
alertType: "info",
14+
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).",
15+
},
16+
async: {
17+
propDefinition: [
18+
alttextify,
19+
"async",
20+
],
21+
},
22+
image: {
23+
type: "string",
24+
label: "Image URL",
25+
description: "The URL of the image to upload.",
26+
},
27+
lang: {
28+
propDefinition: [
29+
alttextify,
30+
"lang",
31+
],
32+
},
33+
maxChars: {
34+
propDefinition: [
35+
alttextify,
36+
"maxChars",
37+
],
38+
},
39+
assetId: {
40+
propDefinition: [
41+
alttextify,
42+
"assetId",
43+
],
44+
},
45+
keywords: {
46+
propDefinition: [
47+
alttextify,
48+
"keywords",
49+
],
50+
},
51+
ecommerceRunOCR: {
52+
propDefinition: [
53+
alttextify,
54+
"ecommerceRunOCR",
55+
],
56+
},
57+
ecommerceProductName: {
58+
propDefinition: [
59+
alttextify,
60+
"ecommerceProductName",
61+
],
62+
},
63+
ecommerceProductBrand: {
64+
propDefinition: [
65+
alttextify,
66+
"ecommerceProductBrand",
67+
],
68+
},
69+
ecommerceProductColor: {
70+
propDefinition: [
71+
alttextify,
72+
"ecommerceProductSize",
73+
],
74+
},
75+
ecommerceProductSize: {
76+
propDefinition: [
77+
alttextify,
78+
"ecommerceProductSize",
79+
],
80+
},
81+
},
82+
async run({ $ }) {
83+
const response = await this.alttextify.uploadImageFromUrl({
84+
$,
85+
data: {
86+
async: this.async,
87+
image: this.image,
88+
lang: this.lang,
89+
maxChars: this.maxChars,
90+
assetId: this.assetId,
91+
keywords: this.keywords,
92+
ecommerce: {
93+
run_ocr: this.ecommerceRunOCR,
94+
product: {
95+
name: this.ecommerceProductName,
96+
brand: this.ecommerceProductBrand,
97+
color: this.ecommerceProductColor,
98+
size: this.ecommerceProductSize,
99+
},
100+
},
101+
},
102+
});
103+
104+
$.export("$summary", `Successfully submitted image to Alttextify for alt text generation with Asset ID: ${response.asset_id}`);
105+
return response;
106+
},
107+
};

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

Lines changed: 74 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,109 @@
1+
import fs from "fs";
12
import alttextify from "../../alttextify.app.mjs";
2-
import { axios } from "@pipedream/platform";
3+
import { checkTmp } from "../../common/utils.mjs";
34

45
export default {
56
key: "alttextify-submit-image",
67
name: "Submit Image to Alttextify",
7-
description: "Upload or submit an image URL to Alttextify for alt text generation. [See the documentation](https://apidoc.alttextify.net/)",
8+
description: "Upload or submit an image to Alttextify for alt text generation. [See the documentation](https://apidoc.alttextify.net/#api-Image-UploadRawImage)",
89
version: "0.0.1",
910
type: "action",
1011
props: {
1112
alttextify,
12-
imageUrl: {
13-
propDefinition: [
14-
alttextify,
15-
"imageUrl",
16-
],
13+
alert: {
14+
type: "alert",
15+
alertType: "info",
16+
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).",
1717
},
18-
imageType: {
18+
async: {
1919
propDefinition: [
2020
alttextify,
21-
"imageType",
21+
"async",
2222
],
2323
},
24+
image: {
25+
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)",
28+
},
2429
lang: {
2530
propDefinition: [
2631
alttextify,
2732
"lang",
2833
],
29-
optional: true,
3034
},
3135
maxChars: {
3236
propDefinition: [
3337
alttextify,
3438
"maxChars",
3539
],
36-
optional: true,
3740
},
38-
asyncOption: {
41+
assetId: {
42+
propDefinition: [
43+
alttextify,
44+
"assetId",
45+
],
46+
},
47+
keywords: {
3948
propDefinition: [
4049
alttextify,
41-
"asyncOption",
50+
"keywords",
51+
],
52+
},
53+
ecommerceRunOCR: {
54+
propDefinition: [
55+
alttextify,
56+
"ecommerceRunOCR",
57+
],
58+
},
59+
ecommerceProductName: {
60+
propDefinition: [
61+
alttextify,
62+
"ecommerceProductName",
63+
],
64+
},
65+
ecommerceProductBrand: {
66+
propDefinition: [
67+
alttextify,
68+
"ecommerceProductBrand",
69+
],
70+
},
71+
ecommerceProductColor: {
72+
propDefinition: [
73+
alttextify,
74+
"ecommerceProductColor",
75+
],
76+
},
77+
ecommerceProductSize: {
78+
propDefinition: [
79+
alttextify,
80+
"ecommerceProductSize",
4281
],
43-
optional: true,
4482
},
4583
},
4684
async run({ $ }) {
47-
const response = await this.alttextify.uploadImageUrl({
48-
imageUrl: this.imageUrl,
49-
imageType: this.imageType,
50-
lang: this.lang,
51-
maxChars: this.maxChars,
52-
asyncOption: this.asyncOption,
85+
const imagePath = checkTmp(this.image);
86+
const image = fs.readFileSync(imagePath, "base64");
87+
88+
const response = await this.alttextify.uploadImage({
89+
$,
90+
data: {
91+
async: this.async,
92+
image: `data:image/${imagePath.split(".")[1]};base64,${image}`,
93+
lang: this.lang,
94+
maxChars: this.maxChars,
95+
assetId: this.assetId,
96+
keywords: this.keywords,
97+
ecommerce: {
98+
run_ocr: this.ecommerceRunOCR,
99+
product: {
100+
name: this.ecommerceProductName,
101+
brand: this.ecommerceProductBrand,
102+
color: this.ecommerceProductColor,
103+
size: this.ecommerceProductSize,
104+
},
105+
},
106+
},
53107
});
54108

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

0 commit comments

Comments
 (0)