diff --git a/src/index.ts b/src/index.ts index 0946e1b..b8299ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,6 +2,7 @@ import { readFileSync } from "fs"; import MediaWiki from "./mediawiki.js"; import { createRestAPIClient } from "masto"; import IConfig from "./IConfig.js"; +import axios from "axios"; const Config : IConfig = JSON.parse(readFileSync("config.json", "utf8")); async function main() { @@ -12,10 +13,21 @@ async function main() { }); var title = await mw.RandomInCategory("Bootlegs"); var metadata = await mw.GetBootlegMetadata(title); + // download screenshot + var screenshot = await axios.get(Config.mwUrl + "/index.php?title=Special:FilePath/" + encodeURIComponent(metadata.screenshot), { + responseType: "arraybuffer" + }); + // upload screenshot + console.log(`Uploading screenshot for ${metadata.title}`); + var media = await mastodon.v1.media.create({ + file: new Blob([screenshot.data], { type: screenshot.headers["content-type"] }), + description: `Screenshot of ${metadata.title}` + }); console.log(`Creating toot for ${metadata.title}`); var toot = await mastodon.v1.statuses.create({ status: `${metadata.description}\nhttps://crustywindo.ws/${title}`, - visibility: "public", + visibility: "private", + mediaIds: [media.id] }); } diff --git a/src/mediawiki.ts b/src/mediawiki.ts index e1fa83f..1455a5a 100644 --- a/src/mediawiki.ts +++ b/src/mediawiki.ts @@ -21,7 +21,6 @@ export default class MediaWiki { GetBootlegMetadata(title : string) : Promise { return new Promise(async (res, rej) => { - console.log(title); var wikitext = String((await axios.get(this.url + `/index.php?title=${title}&action=raw`)).data); var metadata : any = {}; // get screenshot