-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploads.ts
43 lines (34 loc) · 1.19 KB
/
uploads.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import { TwitterApi } from "twitter-api-v2";
import tumblr from "tumblr.js";
import { twitterConfig, tumblrConfig } from "./config";
import { FrameInfo } from "./types";
export const twitterUpload = async (frame: FrameInfo): Promise<FrameInfo> => {
const client = new TwitterApi(twitterConfig);
// You can use media IDs generated by v1 API to send medias!
const mediaId = await client.v1.uploadMedia(`${frame.path}`);
const resPost = await client.v2.tweetThread([
{
text: `Frame: ${frame.num}`,
media: { media_ids: [mediaId] },
},
]);
if (await resPost) {
console.log("Tweet", resPost, ":", resPost);
return frame;
} else throw new Error("Could not complete your post");
console.log("Your post is complete!");
};
export const tumblrUpload = async (frame: FrameInfo): Promise<FrameInfo> => {
const client = tumblr.createClient(tumblrConfig);
const fs = require("fs");
const contents = fs.readFileSync("./fs/frame.png", { encoding: "base64" });
client.createPhotoPost(
"spider-test",
{ data64: contents, caption: `Frame: ${frame.num}` },
(err, res) => {
if (err) throw new Error(err);
else console.log(res);
}
);
return frame;
};