|
| 1 | +import { axios } from "@pipedream/platform"; |
| 2 | +import constants from "./common/constants.mjs"; |
| 3 | + |
1 | 4 | export default { |
2 | 5 | type: "app", |
3 | 6 | app: "cincopa", |
4 | | - propDefinitions: {}, |
| 7 | + propDefinitions: { |
| 8 | + fid: { |
| 9 | + type: "string", |
| 10 | + label: "Gallery FID", |
| 11 | + description: "Gallery FID to add the assets", |
| 12 | + async options({ page }) { |
| 13 | + const { galleries } = await this.listGalleries({ |
| 14 | + params: { |
| 15 | + page: page + 1, |
| 16 | + }, |
| 17 | + }); |
| 18 | + return galleries.map(({ |
| 19 | + fid: value, name: label, |
| 20 | + }) => ({ |
| 21 | + value, |
| 22 | + label, |
| 23 | + })); |
| 24 | + }, |
| 25 | + }, |
| 26 | + rid: { |
| 27 | + type: "string[]", |
| 28 | + label: "Asset RIDs", |
| 29 | + description: "List of RIDs (assets id) to be added", |
| 30 | + optional: true, |
| 31 | + useQuery: true, |
| 32 | + async options({ |
| 33 | + query: search, page, |
| 34 | + }) { |
| 35 | + const { items } = await this.listAssets({ |
| 36 | + params: { |
| 37 | + search, |
| 38 | + page: page + 1, |
| 39 | + }, |
| 40 | + }); |
| 41 | + return items.map(({ |
| 42 | + rid: value, filename: label, |
| 43 | + }) => ({ |
| 44 | + value, |
| 45 | + label, |
| 46 | + })); |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, |
5 | 50 | methods: { |
6 | | - // this.$auth contains connected account data |
7 | | - authKeys() { |
8 | | - console.log(Object.keys(this.$auth)); |
| 51 | + getUrl(path) { |
| 52 | + return `${constants.BASE_URL}${constants.VERSION_PATH}${path}`; |
| 53 | + }, |
| 54 | + getAuthParams(params) { |
| 55 | + return { |
| 56 | + ...params, |
| 57 | + api_token: this.$auth.api_token, |
| 58 | + }; |
| 59 | + }, |
| 60 | + _makeRequest({ |
| 61 | + $ = this, path, params, ...args |
| 62 | + } = {}) { |
| 63 | + return axios($, { |
| 64 | + ...args, |
| 65 | + url: this.getUrl(path), |
| 66 | + params: this.getAuthParams(params), |
| 67 | + }); |
| 68 | + }, |
| 69 | + listGalleries(args = {}) { |
| 70 | + return this._makeRequest({ |
| 71 | + path: "/gallery.list.json", |
| 72 | + ...args, |
| 73 | + }); |
| 74 | + }, |
| 75 | + listAssets(args = {}) { |
| 76 | + return this._makeRequest({ |
| 77 | + path: "/asset.list.json", |
| 78 | + ...args, |
| 79 | + }); |
9 | 80 | }, |
10 | 81 | }, |
11 | 82 | }; |
0 commit comments