Skip to content

Commit acbab99

Browse files
committed
init
1 parent fcde7cf commit acbab99

File tree

3 files changed

+139
-5
lines changed

3 files changed

+139
-5
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import imagior from "../../imagior.app.mjs";
2+
3+
export default {
4+
key: "imagior-generate-image",
5+
name: "Generate Image",
6+
description: "Generates a unique and robust image using a provided template.",
7+
version: "0.0.{{ts}}",
8+
type: "action",
9+
props: {
10+
imagior,
11+
template_id: {
12+
propDefinition: [
13+
imagior,
14+
"template_id",
15+
],
16+
},
17+
image_parameters: {
18+
propDefinition: [
19+
imagior,
20+
"image_parameters",
21+
],
22+
optional: true,
23+
},
24+
},
25+
async run({ $ }) {
26+
const response = await this.imagior.generateImage({
27+
template_id: this.template_id,
28+
image_parameters: this.image_parameters,
29+
});
30+
$.export("$summary", "Successfully generated image");
31+
return response;
32+
},
33+
};

components/imagior/imagior.app.mjs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,58 @@
1+
import { axios } from "@pipedream/platform";
2+
13
export default {
24
type: "app",
35
app: "imagior",
4-
propDefinitions: {},
6+
propDefinitions: {
7+
template_id: {
8+
type: "string",
9+
label: "Template ID",
10+
description: "The unique ID of the design template you created",
11+
required: true,
12+
},
13+
image_parameters: {
14+
type: "object",
15+
label: "Image Parameters",
16+
description: "Optional parameters to customize the appearance of the image",
17+
optional: true,
18+
},
19+
},
520
methods: {
6-
// this.$auth contains connected account data
7-
authKeys() {
8-
console.log(Object.keys(this.$auth));
21+
_baseUrl() {
22+
return "https://api.imagior.com";
23+
},
24+
async _makeRequest(opts = {}) {
25+
const {
26+
$ = this, method = "GET", path, headers, ...otherOpts
27+
} = opts;
28+
return axios($, {
29+
...otherOpts,
30+
method,
31+
url: this._baseUrl() + path,
32+
headers: {
33+
...headers,
34+
Authorization: `Bearer ${this.$auth.oauth_access_token}`,
35+
},
36+
});
37+
},
38+
async createTemplate(opts = {}) {
39+
return this._makeRequest({
40+
method: "POST",
41+
path: "/templates",
42+
...opts,
43+
});
44+
},
45+
async generateImage({
46+
template_id, image_parameters,
47+
}) {
48+
return this._makeRequest({
49+
method: "POST",
50+
path: "/image/generate",
51+
data: {
52+
templateId: template_id,
53+
elements: image_parameters,
54+
},
55+
});
956
},
1057
},
11-
};
58+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import imagior from "../../imagior.app.mjs";
2+
3+
export default {
4+
key: "imagior-new-template",
5+
name: "New Template Created",
6+
description: "Emits a new event when a new template is created.",
7+
version: "0.0.1",
8+
type: "source",
9+
dedupe: "unique",
10+
props: {
11+
imagior,
12+
db: "$.service.db",
13+
timer: {
14+
type: "$.interface.timer",
15+
default: {
16+
intervalSeconds: 60 * 15, // 15 minutes
17+
},
18+
},
19+
},
20+
methods: {
21+
_getPrevTemplateId() {
22+
return this.db.get("prevTemplateId");
23+
},
24+
_setPrevTemplateId(id) {
25+
this.db.set("prevTemplateId", id);
26+
},
27+
},
28+
async run() {
29+
const { elements: templates } = await this.imagior._makeRequest({
30+
path: "/templates/all",
31+
});
32+
33+
if (!templates.length) {
34+
console.log("No templates found");
35+
return;
36+
}
37+
38+
const sortedTemplates = templates.sort((a, b) => new Date(b.updatedAt) - new Date(a.updatedAt));
39+
const latestTemplate = sortedTemplates[0];
40+
const prevTemplateId = this._getPrevTemplateId();
41+
42+
if (prevTemplateId && latestTemplate.id === prevTemplateId) {
43+
console.log("No new templates found");
44+
return;
45+
}
46+
47+
this._setPrevTemplateId(latestTemplate.id);
48+
this.$emit(latestTemplate, {
49+
id: latestTemplate.id,
50+
summary: `New template: ${latestTemplate.name}`,
51+
ts: Date.parse(latestTemplate.createdAt),
52+
});
53+
},
54+
};

0 commit comments

Comments
 (0)