@pipedream/twitter 0.3.9 → 0.3.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,7 +6,7 @@ export default {
6
6
  key: "twitter-upload-media",
7
7
  name: "Upload Media",
8
8
  description: "Upload images or other media types to Twitter. Returns a `media_id_string` to be used with the Create Tweet action. [See the docs here](https://developer.twitter.com/en/docs/tutorials/uploading-media)",
9
- version: "0.0.1",
9
+ version: "0.0.2",
10
10
  type: "action",
11
11
  props: {
12
12
  twitter,
@@ -23,6 +23,17 @@ export default {
23
23
  return Object.values(mime._types);
24
24
  },
25
25
  },
26
+ mediaCategory: {
27
+ type: "string",
28
+ label: "Media Category",
29
+ description: "The category that represents how the media will be used",
30
+ options: [
31
+ "amplify_video",
32
+ "tweet_gif",
33
+ "tweet_image",
34
+ "tweet_video",
35
+ ],
36
+ },
26
37
  },
27
38
  async run({ $ }) {
28
39
  // INIT
@@ -30,18 +41,22 @@ export default {
30
41
  encoding: "base64",
31
42
  });
32
43
  const fileSize = (fs.statSync(this.file)).size;
44
+ const params = {
45
+ command: "INIT",
46
+ total_bytes: fileSize,
47
+ media_type: this.mediaType,
48
+ additional_owners: this.twitter.$auth.oauth_uid,
49
+ };
50
+ if (this.mediaCategory) {
51
+ params.media_category = this.mediaCategory;
52
+ }
33
53
  const { media_id_string: mediaId } = await this.twitter.uploadMedia({
34
- params: {
35
- command: "INIT",
36
- total_bytes: fileSize,
37
- media_type: this.mediaType,
38
- additional_owners: this.twitter.$auth.oauth_uid,
39
- },
54
+ params,
40
55
  $,
41
56
  });
42
57
 
43
58
  // APPEND
44
- const size = 5012;
59
+ const size = 9000;
45
60
  const numSegments = fileContent.length / size;
46
61
  let segment = 0;
47
62
  let startIndex = 0;
@@ -64,13 +79,35 @@ export default {
64
79
  }
65
80
 
66
81
  // FINALIZE
67
- const response = await this.twitter.uploadMedia({
82
+ let response;
83
+ response = await this.twitter.uploadMedia({
68
84
  params: {
69
85
  command: "FINALIZE",
70
86
  media_id: mediaId,
71
87
  },
72
88
  $,
73
89
  });
90
+
91
+ // STATUS
92
+ while (this.mediaCategory?.includes("video")) {
93
+ response = await this.twitter.uploadMedia({
94
+ params: {
95
+ command: "STATUS",
96
+ media_id: mediaId,
97
+ },
98
+ method: "GET",
99
+ $,
100
+ });
101
+ const { processing_info: info } = response;
102
+ if (info?.error) {
103
+ throw new Error(JSON.stringify(info.error));
104
+ }
105
+ if (info?.state === "succeeded") {
106
+ break;
107
+ }
108
+ setTimeout(() => {}, info.check_after_secs * 1000);
109
+ }
110
+
74
111
  response && $.export("$summary", `Successfully uploaded media with Media ID ${mediaId}`);
75
112
  return response;
76
113
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/twitter",
3
- "version": "0.3.9",
3
+ "version": "0.3.10",
4
4
  "description": "Pipedream Twitter Components",
5
5
  "main": "twitter.app.mjs",
6
6
  "keywords": [