From ad9baf2b27ce22d69b04d7f2bd3005617053e56a Mon Sep 17 00:00:00 2001 From: Elijah R Date: Sun, 21 Jan 2024 21:27:38 -0500 Subject: [PATCH] add screenshot uploading --- src/index.ts | 14 +++++++++++++- src/mediawiki.ts | 1 - 2 files changed, 13 insertions(+), 2 deletions(-) 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