-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - imagior #14303
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
New Components - imagior #14303
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
acbab99
init
michelle0927 e0e32f5
new components
michelle0927 95fcdcb
pnpm-lock.yaml
michelle0927 f61c434
add $ variable
michelle0927 9aef718
improve prop names
michelle0927 efa6874
return if no new templates
michelle0927 bafe40c
updates
michelle0927 b6c3418
add prefix to customize props labels
michelle0927 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
components/imagior/actions/generate-image/generate-image.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import imagior from "../../imagior.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "imagior-generate-image", | ||
| name: "Generate Image", | ||
| description: "Generates a unique and robust image using a provided template. [See the documentation](https://docs.imagior.com/api-reference/image-generate)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| imagior, | ||
| templateId: { | ||
| propDefinition: [ | ||
| imagior, | ||
| "templateId", | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (!this.templateId) { | ||
| return props; | ||
| } | ||
| const { elements } = await this.imagior.listTemplateElements({ | ||
| templateId: this.templateId, | ||
| }); | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(elements)) { | ||
| props[`customize_${key}`] = { | ||
| type: "boolean", | ||
| label: `Customize ${key}`, | ||
| optional: true, | ||
| reloadProps: true, | ||
| }; | ||
| if (this[`customize_${key}`]) { | ||
| for (const elementKey of Object.keys(value)) { | ||
| props[`${key}_${elementKey}`] = { | ||
| type: "string", | ||
| label: `${key} - ${elementKey}`, | ||
| optional: true, | ||
| }; | ||
| } | ||
| } | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const elements = {}; | ||
| const { elements: allElements } = await this.imagior.listTemplateElements({ | ||
| $, | ||
| templateId: this.templateId, | ||
| }); | ||
| for (const [ | ||
| key, | ||
| value, | ||
| ] of Object.entries(allElements)) { | ||
| if (!this[`customize_${key}`]) { | ||
| continue; | ||
| } | ||
| elements[key] = {}; | ||
| for (const elementKey of Object.keys(value)) { | ||
| if (this[`${key}_${elementKey}`]) { | ||
| elements[key][elementKey] = this[`${key}_${elementKey}`]; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| const response = await this.imagior.generateImage({ | ||
| $, | ||
| data: { | ||
| templateId: this.templateId, | ||
| elements, | ||
| }, | ||
| }); | ||
| $.export("$summary", `${response.message}`); | ||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,62 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "imagior", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| templateId: { | ||
| type: "string", | ||
| label: "Template ID", | ||
| description: "The unique ID of the design template to use", | ||
| async options() { | ||
| const templates = await this.listTemplates(); | ||
| return templates?.map(({ | ||
| id: value, name: label, | ||
| }) => ({ | ||
| value, | ||
| label, | ||
| })) || []; | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.imagior.com"; | ||
| }, | ||
| async _makeRequest(opts = {}) { | ||
| const { | ||
| $ = this, | ||
| path, | ||
| ...otherOpts | ||
| } = opts; | ||
| return axios($, { | ||
| ...otherOpts, | ||
| url: `${this._baseUrl()}${path}`, | ||
| headers: { | ||
| Authorization: `Bearer ${this.$auth.api_key}`, | ||
| }, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| listTemplates(opts = {}) { | ||
| return this._makeRequest({ | ||
| path: "/templates/all", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listTemplateElements({ | ||
| templateId, ...opts | ||
| }) { | ||
| return this._makeRequest({ | ||
| path: `/templates/${templateId}/elements`, | ||
| ...opts, | ||
| }); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| generateImage(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/image/generate", | ||
| ...opts, | ||
| }); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| { | ||
| "name": "@pipedream/imagior", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream Imagior Components", | ||
| "main": "imagior.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import imagior from "../../imagior.app.mjs"; | ||
| import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| key: "imagior-new-template", | ||
| name: "New Template Created", | ||
| description: "Emit new event when a new template is created.", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| imagior, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastTs() { | ||
| return this.db.get("lastTs") || 0; | ||
| }, | ||
| _setLastTs(lastTs) { | ||
| this.db.set("lastTs", lastTs); | ||
| }, | ||
| generateMeta(template) { | ||
| return { | ||
| id: template.id, | ||
| summary: `New Template: ${template.name}`, | ||
| ts: Date.parse(template.createdAt), | ||
| }; | ||
| }, | ||
| }, | ||
| async run() { | ||
| const lastTs = this._getLastTs(); | ||
|
|
||
| const templates = await this.imagior.listTemplates({ | ||
| params: { | ||
| sort: "createdAt", | ||
| order: "desc", | ||
| }, | ||
| }); | ||
|
|
||
| if (!templates?.length) { | ||
| return; | ||
| } | ||
|
|
||
| const newTemplates = templates.filter(({ createdAt }) => Date.parse(createdAt) >= lastTs); | ||
|
|
||
| if (!newTemplates?.length) { | ||
| return; | ||
| } | ||
|
|
||
| this._setLastTs(Date.parse(newTemplates[0].createdAt)); | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| newTemplates.forEach((template) => { | ||
| const meta = this.generateMeta(template); | ||
| this.$emit(template, meta); | ||
| }); | ||
| }, | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.