Skip to content

Commit 33b1b2d

Browse files
committed
[Components] what_are_those #15195
Actions - Identify Sneakers From Photo - Grade Sneakers Condition - Find Sneakers By SKU
1 parent c9fdcc0 commit 33b1b2d

File tree

6 files changed

+117
-185
lines changed

6 files changed

+117
-185
lines changed
Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
1-
import what_are_those from "../../what_are_those.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import fs from "fs";
2+
import { checkTmp } from "../../common/utils.mjs";
3+
import app from "../../what_are_those.app.mjs";
34

45
export default {
56
key: "what_are_those-find-sneakers-by-sku",
67
name: "Find Sneakers by SKU",
7-
description: "Identifies sneakers from a size tag photo and returns sneaker name and details. [See the documentation]()",
8-
version: "0.0.{{ts}}",
8+
description: "Identifies sneakers from a size tag photo and returns sneaker name and details. [See the documentation](https://documenter.getpostman.com/view/3847098/2sAY4rDQDs#4f6a49f9-3393-42cd-8474-3856a79888af)",
9+
version: "0.0.1",
910
type: "action",
1011
props: {
11-
what_are_those: {
12-
type: "app",
13-
app: "what_are_those",
14-
},
15-
sizeTagPhoto: {
16-
propDefinition: [
17-
"what_are_those",
18-
"sizeTagPhoto",
19-
],
12+
app,
13+
sizeTagImage: {
14+
type: "string",
15+
label: "Size Tag Image",
16+
description: "The path to the size tag image 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).",
2017
},
2118
},
2219
async run({ $ }) {
23-
const sneakerData = await this.what_are_those.identifySneakersFromSizeTag({
24-
sizeTagPhoto: this.sizeTagPhoto,
20+
const data = fs.readFileSync(checkTmp(this.sizeTagImage));
21+
const base64Image = Buffer.from(data, "binary").toString("base64");
22+
23+
const response = await this.app.identifySneakersFromSizeTag({
24+
$,
25+
data: base64Image,
2526
});
26-
const sneakerName = sneakerData.name;
27-
const sneakerDetails = sneakerData.details;
28-
$.export("$summary", `Identified sneaker: ${sneakerName}`);
29-
return {
30-
name: sneakerName,
31-
details: sneakerDetails,
32-
};
27+
28+
$.export("$summary", `Identified sneaker: ${response}`);
29+
return response;
3330
},
3431
};

components/what_are_those/actions/grade-sneakers-condition/grade-sneakers-condition.mjs

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,75 @@
1-
import what_are_those from "../../what_are_those.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import FormData from "form-data";
2+
import fs from "fs";
3+
import { checkTmp } from "../../common/utils.mjs";
4+
import app from "../../what_are_those.app.mjs";
35

46
export default {
57
key: "what_are_those-grade-sneakers-condition",
68
name: "Grade and Authenticate Sneakers",
7-
description: "Grades and authenticates sneakers using provided images. [See the documentation]()",
8-
version: "0.0.{{ts}}",
9+
description: "Grades and authenticates sneakers using provided images. [See the documentation](https://documenter.getpostman.com/view/3847098/2sAY4rDQDs#13d527e8-5d8f-4511-857c-b40b8dd921b8)",
10+
version: "0.0.1",
911
type: "action",
1012
props: {
11-
what_are_those,
13+
app,
1214
frontImage: {
13-
propDefinition: [
14-
what_are_those,
15-
"frontImage",
16-
],
15+
type: "string",
16+
label: "Front Image",
17+
description: "Base64 encoded or multipart form data image of the front.",
1718
},
1819
leftImage: {
19-
propDefinition: [
20-
what_are_those,
21-
"leftImage",
22-
],
20+
type: "string",
21+
label: "Left Image",
22+
description: "Base64 encoded or multipart form data image of the left side.",
2323
},
2424
rightImage: {
25-
propDefinition: [
26-
what_are_those,
27-
"rightImage",
28-
],
25+
type: "string",
26+
label: "Right Image",
27+
description: "Base64 encoded or multipart form data image of the right side.",
2928
},
3029
soleImage: {
31-
propDefinition: [
32-
what_are_those,
33-
"soleImage",
34-
],
30+
type: "string",
31+
label: "Sole Image",
32+
description: "Base64 encoded or multipart form data image of the sole.",
3533
},
3634
insoleImage: {
37-
propDefinition: [
38-
what_are_those,
39-
"insoleImage",
40-
],
35+
type: "string",
36+
label: "Insole Image",
37+
description: "Base64 encoded or multipart form data image of the insole.",
4138
},
4239
sizeTagImage: {
43-
propDefinition: [
44-
what_are_those,
45-
"sizeTagImage",
46-
],
40+
type: "string",
41+
label: "Size Tag Image",
42+
description: "Base64 encoded or multipart form data image of the size tag.",
4743
},
4844
type: {
49-
propDefinition: [
50-
what_are_those,
51-
"type",
45+
type: "string",
46+
label: "Use Type",
47+
description: "the type parameter to see specific types of data.",
48+
options: [
49+
"grading",
50+
"authentication",
5251
],
5352
optional: true,
5453
},
5554
},
5655
async run({ $ }) {
57-
const response = await this.what_are_those.gradeAuthenticateSneakers({
58-
frontImage: this.frontImage,
59-
leftImage: this.leftImage,
60-
rightImage: this.rightImage,
61-
soleImage: this.soleImage,
62-
insoleImage: this.insoleImage,
63-
sizeTagImage: this.sizeTagImage,
64-
type: this.type,
56+
const data = new FormData();
57+
data.append("image1", fs.createReadStream(checkTmp(this.frontImage)));
58+
data.append("image2", fs.createReadStream(checkTmp(this.leftImage)));
59+
data.append("image3", fs.createReadStream(checkTmp(this.rightImage)));
60+
data.append("image4", fs.createReadStream(checkTmp(this.soleImage)));
61+
data.append("image5", fs.createReadStream(checkTmp(this.insoleImage)));
62+
data.append("image6", fs.createReadStream(checkTmp(this.sizeTagImage)));
63+
64+
const response = await this.app.gradeAuthenticateSneakers({
65+
headers: {
66+
...data.getHeaders(),
67+
},
68+
data: data,
69+
maxBodyLength: Infinity,
70+
params: {
71+
type: this.type,
72+
},
6573
});
6674
$.export("$summary", "Successfully graded and authenticated sneakers.");
6775
return response;
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,34 @@
1-
import what_are_those from "../../what_are_those.app.mjs";
2-
import { axios } from "@pipedream/platform";
1+
import FormData from "form-data";
2+
import fs from "fs";
3+
import { checkTmp } from "../../common/utils.mjs";
4+
import app from "../../what_are_those.app.mjs";
35

46
export default {
57
key: "what_are_those-identify-sneakers-from-photo",
68
name: "Identify Sneakers from Photo",
7-
description: "Identifies sneakers from an uploaded image and returns details such as name, links, images, prices, and confidence scores. [See the documentation]().",
8-
version: "0.0.{{ts}}",
9+
description: "Identifies sneakers from an uploaded image and returns details such as name, links, images, prices, and confidence scores. [See the documentation](https://documenter.getpostman.com/view/3847098/2sAY4rDQDs#957c900c-501f-4c8f-9b8b-71655a8cfb5d).",
10+
version: "0.0.1",
911
type: "action",
1012
props: {
11-
what_are_those,
13+
app,
1214
image: {
13-
propDefinition: [
14-
what_are_those,
15-
"image",
16-
],
15+
type: "string",
16+
label: "Image",
17+
description: "The path to the size tag image 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).",
1718
},
1819
},
1920
async run({ $ }) {
20-
const response = await this.what_are_those.identifySneakers({
21-
image: this.image,
21+
const data = new FormData();
22+
data.append("image1", fs.createReadStream(checkTmp(this.image)));
23+
24+
const response = await this.app.identifySneakers({
25+
headers: {
26+
...data.getHeaders(),
27+
},
28+
data: data,
2229
});
23-
const sneakerCount = Array.isArray(response)
24-
? response.length
25-
: 1;
26-
$.export("$summary", `Identified ${sneakerCount} sneakers successfully`);
30+
31+
$.export("$summary", `Identified ${response.names} sneakers successfully`);
2732
return response;
2833
},
2934
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const checkTmp = (filename) => {
2+
if (!filename.startsWith("/tmp")) {
3+
return "/tmp/filename";
4+
}
5+
return filename;
6+
};

components/what_are_those/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pipedream/what_are_those",
3-
"version": "0.0.1",
3+
"version": "0.1.0",
44
"description": "Pipedream What Are Those Components",
55
"main": "what_are_those.app.mjs",
66
"keywords": [
@@ -11,5 +11,8 @@
1111
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
1212
"publishConfig": {
1313
"access": "public"
14+
},
15+
"dependencies": {
16+
"@pipedream/platform": "^3.0.3"
1417
}
1518
}

components/what_are_those/what_are_those.app.mjs

Lines changed: 20 additions & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -3,127 +3,40 @@ import { axios } from "@pipedream/platform";
33
export default {
44
type: "app",
55
app: "what_are_those",
6-
version: "0.0.{{ts}}",
7-
propDefinitions: {
8-
// Props for identifying sneakers from an uploaded image
9-
image: {
10-
type: "string",
11-
label: "Image",
12-
description: "Base64 encoded or multipart form data image.",
13-
},
14-
// Props for grading and authenticating sneakers
15-
frontImage: {
16-
type: "string",
17-
label: "Front Image",
18-
description: "Base64 encoded or multipart form data image of the front.",
19-
},
20-
leftImage: {
21-
type: "string",
22-
label: "Left Image",
23-
description: "Base64 encoded or multipart form data image of the left side.",
24-
},
25-
rightImage: {
26-
type: "string",
27-
label: "Right Image",
28-
description: "Base64 encoded or multipart form data image of the right side.",
29-
},
30-
soleImage: {
31-
type: "string",
32-
label: "Sole Image",
33-
description: "Base64 encoded or multipart form data image of the sole.",
34-
},
35-
insoleImage: {
36-
type: "string",
37-
label: "Insole Image",
38-
description: "Base64 encoded or multipart form data image of the insole.",
39-
},
40-
sizeTagImage: {
41-
type: "string",
42-
label: "Size Tag Image",
43-
description: "Base64 encoded or multipart form data image of the size tag.",
44-
},
45-
type: {
46-
type: "string",
47-
label: "Type",
48-
description: "Optional parameter for grading-only results.",
49-
optional: true,
50-
},
51-
// Props for identifying sneakers from a size tag photo
52-
sizeTagPhoto: {
53-
type: "string",
54-
label: "Size Tag Photo",
55-
description: "File or base64 encoded data of the size tag photo.",
56-
},
57-
},
586
methods: {
59-
// Existing method
60-
authKeys() {
61-
console.log(Object.keys(this.$auth));
62-
},
63-
// Base URL for the API
64-
_baseUrl() {
65-
return "https://api.whatarethose.com";
66-
},
67-
// Method to make API requests
68-
async _makeRequest(opts = {}) {
69-
const {
70-
$ = this, method = "GET", path = "/", headers, ...otherOpts
71-
} = opts;
7+
_headers(headers = {}) {
8+
return {
9+
"x-api-key": this.$auth.api_key,
10+
...headers,
11+
};
12+
},
13+
_makeRequest({
14+
$ = this, headers, ...opts
15+
}) {
7216
return axios($, {
73-
method,
74-
url: `${this._baseUrl()}${path}`,
75-
headers: {
76-
...headers,
77-
Authorization: `Bearer ${this.$auth.api_token}`,
78-
},
79-
...otherOpts,
17+
headers: this._headers(headers),
18+
...opts,
8019
});
8120
},
82-
// Method to identify sneakers from an uploaded image
83-
async identifySneakers(opts = {}) {
84-
const { image } = opts;
21+
identifySneakers(opts = {}) {
8522
return this._makeRequest({
8623
method: "POST",
87-
path: "/identify_sneakers",
88-
data: {
89-
image: image,
90-
},
24+
url: "https://ayq6s37rv6.execute-api.us-east-1.amazonaws.com/Prod/rec?data_type=multi",
25+
...opts,
9126
});
9227
},
93-
// Method to grade and authenticate sneakers from multiple images
94-
async gradeAuthenticateSneakers(opts = {}) {
95-
const {
96-
frontImage,
97-
leftImage,
98-
rightImage,
99-
soleImage,
100-
insoleImage,
101-
sizeTagImage,
102-
type,
103-
} = opts;
28+
gradeAuthenticateSneakers(opts = {}) {
10429
return this._makeRequest({
10530
method: "POST",
106-
path: "/grade_authenticate_sneakers",
107-
data: {
108-
front: frontImage,
109-
left: leftImage,
110-
right: rightImage,
111-
sole: soleImage,
112-
insole: insoleImage,
113-
size_tag: sizeTagImage,
114-
type: type,
115-
},
31+
url: "https://6mdt6kw7ig.execute-api.us-east-1.amazonaws.com/Prod/list?data_type=multi",
32+
...opts,
11633
});
11734
},
118-
// Method to identify sneakers from a size tag photo
119-
async identifySneakersFromSizeTag(opts = {}) {
120-
const { sizeTagPhoto } = opts;
35+
identifySneakersFromSizeTag(opts = {}) {
12136
return this._makeRequest({
12237
method: "POST",
123-
path: "/identify_from_size_tag",
124-
data: {
125-
size_tag_photo: sizeTagPhoto,
126-
},
38+
url: "https://0blrzg7ahc.execute-api.us-east-1.amazonaws.com/Prod/sku",
39+
...opts,
12740
});
12841
},
12942
},

0 commit comments

Comments
 (0)