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}`); })();