|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | + |
1 | 3 | export default { |
2 | 4 | type: "app", |
3 | 5 | 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 | + }, |
5 | 38 | methods: { |
6 | | - // this.$auth contains connected account data |
| 39 | + // Existing method |
7 | 40 | authKeys() { |
8 | 41 | console.log(Object.keys(this.$auth)); |
9 | 42 | }, |
| 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 | + }, |
10 | 90 | }, |
11 | 91 | }; |
0 commit comments