summaryrefslogtreecommitdiffstats
path: root/src/index.ts
blob: 7185e23a37c6126c4ac65d88f0d8e2bd346d8967 (plain) (blame)
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
import * as e621 from "./api/e621";
import * as mastodon from "./api/mastodon";
import config from "./config";

(async () => {
    console.log("Fetching post...");

    const post = await e621.randomPost();
    const source = post.sources.length ? post.sources[0] : undefined;
    const cws = config.cw.filter((w) => post.tags.general.includes(w));

    console.log(`Got ${post.id}`);
    console.log(`Downloading image...`);

    const file = await e621.client.get(post.file.url).buffer();

    /*console.log(`Compressing...`);

    const compressedFile = await sharp(file)
        .resize(1000, 1000, {
            fit: "inside",
            withoutEnlargement: true,
        })
        .jpeg({ quality: 85, mozjpeg: true })
        .toBuffer();*/

    console.log(`Uploading...`);

    const attachment = await mastodon.upload(file, post.id.toString(10));

    console.log(`Posting status...`);

    const status = await mastodon.createStatus(`https://e926.net/posts/${post.id}`, source, cws, attachment.id);

    console.log(`Done! ${status.url}`);
})();