Skip to content

Commit 041fec0

Browse files
authored
17712 actions for hootsuite (#17982)
* actions for hootsuite #17712 Actions - Create Media Upload Job - Get Media Upload Status - Schedule Message * pnpm update * Fix typos in targeting fields and update description formatting in schedule-message component * Update targeting field types and descriptions in schedule-message component; refactor LinkedIn targeting logic for improved clarity
1 parent acf9687 commit 041fec0

File tree

9 files changed

+3216
-27
lines changed

9 files changed

+3216
-27
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { getFileStreamAndMetadata } from "@pipedream/platform";
2+
import hootsuite from "../../hootsuite.app.mjs";
3+
4+
export default {
5+
key: "hootsuite-create-media-upload-job",
6+
name: "Create Media Upload Job",
7+
description: "Creates a new Media Upload Job on your Hootsuite account. [See the documentation](https://apidocs.hootsuite.com/docs/api/index.html#operation/createMedia)",
8+
version: "0.0.1",
9+
type: "action",
10+
props: {
11+
hootsuite,
12+
file: {
13+
type: "string",
14+
label: "File Path or URL",
15+
description: "The path or URL to the image file.",
16+
},
17+
syncDir: {
18+
type: "dir",
19+
accessMode: "read",
20+
sync: true,
21+
},
22+
},
23+
methods: {
24+
initializeUpload(opts = {}) {
25+
return this.hootsuite._makeRequest({
26+
method: "POST",
27+
path: "/media",
28+
...opts,
29+
});
30+
},
31+
streamToBuffer(stream) {
32+
return new Promise((resolve, reject) => {
33+
const chunks = [];
34+
stream.on("data", (chunk) => chunks.push(chunk));
35+
stream.on("end", () => resolve(Buffer.concat(chunks)));
36+
stream.on("error", reject);
37+
});
38+
},
39+
uploadImage(url, fileBinary, headers) {
40+
return this.hootsuite._makeRequest({
41+
url,
42+
method: "PUT",
43+
maxBodyLength: Infinity,
44+
data: Buffer.from(fileBinary, "binary"),
45+
noHeaders: true,
46+
headers,
47+
});
48+
},
49+
},
50+
async run({ $ }) {
51+
const {
52+
stream, metadata,
53+
} = await getFileStreamAndMetadata(this.file);
54+
55+
const {
56+
data: {
57+
uploadUrl, id,
58+
},
59+
} = await this.initializeUpload({
60+
data: {
61+
sizeBytes: metadata.size,
62+
mimeType: metadata.contentType,
63+
},
64+
});
65+
66+
const fileBinary = await this.streamToBuffer(stream);
67+
68+
await this.uploadImage(uploadUrl, fileBinary, {
69+
"Content-Type": metadata.contentType,
70+
});
71+
72+
$.export("$summary", `Successfully created media upload job with ID: ${id}`);
73+
return {
74+
fileId: id,
75+
};
76+
},
77+
};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import hootsuite from "../../hootsuite.app.mjs";
2+
3+
export default {
4+
key: "hootsuite-get-media-upload-status",
5+
name: "Get Media Upload Status",
6+
description: "Gets the status of a Media Upload Job on your Hootsuite account. [See the documentation](https://apidocs.hootsuite.com/docs/api/index.html#operation/getMedia)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
hootsuite,
11+
fileId: {
12+
type: "string",
13+
label: "File ID",
14+
description: "The ID of the file to get the status of.",
15+
},
16+
},
17+
async run({ $ }) {
18+
const response = await this.hootsuite.getMediaUploadStatus({
19+
$,
20+
fileId: this.fileId,
21+
});
22+
23+
$.export("$summary", `Successfully got media upload status for file ID: ${this.fileId}`);
24+
return response;
25+
},
26+
};

0 commit comments

Comments
 (0)