Skip to content

Commit 5b75921

Browse files
committed
change_photos init
1 parent 22be9ab commit 5b75921

File tree

3 files changed

+119
-3
lines changed

3 files changed

+119
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import change_photos from "../../change_photos.app.mjs";
2+
import { axios } from "@pipedream/platform";
3+
4+
export default {
5+
key: "change_photos-transform-image",
6+
name: "Transform Image",
7+
description: "Transforms an image with various effects and optimizations. [See the documentation]()",
8+
version: "0.0.{{ts}}",
9+
type: "action",
10+
props: {
11+
change_photos,
12+
imageUrl: {
13+
propDefinition: [
14+
change_photos,
15+
"imageUrl",
16+
],
17+
},
18+
effects: {
19+
propDefinition: [
20+
change_photos,
21+
"effects",
22+
],
23+
},
24+
optimizations: {
25+
propDefinition: [
26+
change_photos,
27+
"optimizations",
28+
],
29+
},
30+
},
31+
async run({ $ }) {
32+
const response = await this.change_photos.transformImage();
33+
$.export("$summary", "Image transformed successfully");
34+
return response;
35+
},
36+
};
Lines changed: 82 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,91 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "change_photos",
4-
propDefinitions: {},
6+
version: "0.0.20240427",
7+
propDefinitions: {
8+
imageUrl: {
9+
type: "string",
10+
label: "Image URL",
11+
description: "URL of the image to transform",
12+
},
13+
effects: {
14+
type: "string[]",
15+
label: "Effects",
16+
description: "Effects to apply to the image",
17+
async options() {
18+
const effects = await this.getEffects();
19+
return effects.map((effect) => ({
20+
label: effect.name,
21+
value: effect.id,
22+
}));
23+
},
24+
},
25+
optimizations: {
26+
type: "string[]",
27+
label: "Optimizations",
28+
description: "Optimizations to apply to the image",
29+
async options() {
30+
const optimizations = await this.getOptimizations();
31+
return optimizations.map((opt) => ({
32+
label: opt.name,
33+
value: opt.id,
34+
}));
35+
},
36+
},
37+
},
538
methods: {
6-
// this.$auth contains connected account data
39+
// Existing method
740
authKeys() {
841
console.log(Object.keys(this.$auth));
942
},
43+
_baseUrl() {
44+
return "https://www.change.photos/api";
45+
},
46+
async _makeRequest(opts = {}) {
47+
const {
48+
$ = this, method = "GET", path = "/", headers, ...otherOpts
49+
} = opts;
50+
return axios($, {
51+
...otherOpts,
52+
method,
53+
url: `${this._baseUrl()}${path}`,
54+
headers: {
55+
...headers,
56+
"User-Agent": "@PipedreamHQ/pipedream v0.1",
57+
"Authorization": `Bearer ${this.$auth.apiToken}`,
58+
},
59+
});
60+
},
61+
async getEffects(opts = {}) {
62+
const response = await this._makeRequest({
63+
method: "GET",
64+
path: "/effects",
65+
...opts,
66+
});
67+
return response;
68+
},
69+
async getOptimizations(opts = {}) {
70+
const response = await this._makeRequest({
71+
method: "GET",
72+
path: "/optimizations",
73+
...opts,
74+
});
75+
return response;
76+
},
77+
async transformImage(opts = {}) {
78+
const response = await this._makeRequest({
79+
method: "POST",
80+
path: "/transform",
81+
data: {
82+
image_url: this.imageUrl,
83+
effects: this.effects,
84+
optimizations: this.optimizations,
85+
...opts,
86+
},
87+
});
88+
return response;
89+
},
1090
},
1191
};

components/change_photos/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212
"publishConfig": {
1313
"access": "public"
1414
}
15-
}
15+
}

0 commit comments

Comments
 (0)