add screenshot uploading
This commit is contained in:
parent
4026ad8146
commit
ad9baf2b27
2 changed files with 13 additions and 2 deletions
14
src/index.ts
14
src/index.ts
|
@ -2,6 +2,7 @@ import { readFileSync } from "fs";
|
||||||
import MediaWiki from "./mediawiki.js";
|
import MediaWiki from "./mediawiki.js";
|
||||||
import { createRestAPIClient } from "masto";
|
import { createRestAPIClient } from "masto";
|
||||||
import IConfig from "./IConfig.js";
|
import IConfig from "./IConfig.js";
|
||||||
|
import axios from "axios";
|
||||||
const Config : IConfig = JSON.parse(readFileSync("config.json", "utf8"));
|
const Config : IConfig = JSON.parse(readFileSync("config.json", "utf8"));
|
||||||
|
|
||||||
async function main() {
|
async function main() {
|
||||||
|
@ -12,10 +13,21 @@ async function main() {
|
||||||
});
|
});
|
||||||
var title = await mw.RandomInCategory("Bootlegs");
|
var title = await mw.RandomInCategory("Bootlegs");
|
||||||
var metadata = await mw.GetBootlegMetadata(title);
|
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}`);
|
console.log(`Creating toot for ${metadata.title}`);
|
||||||
var toot = await mastodon.v1.statuses.create({
|
var toot = await mastodon.v1.statuses.create({
|
||||||
status: `${metadata.description}\nhttps://crustywindo.ws/${title}`,
|
status: `${metadata.description}\nhttps://crustywindo.ws/${title}`,
|
||||||
visibility: "public",
|
visibility: "private",
|
||||||
|
mediaIds: [media.id]
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ export default class MediaWiki {
|
||||||
|
|
||||||
GetBootlegMetadata(title : string) : Promise<BootlegMetadata> {
|
GetBootlegMetadata(title : string) : Promise<BootlegMetadata> {
|
||||||
return new Promise<BootlegMetadata>(async (res, rej) => {
|
return new Promise<BootlegMetadata>(async (res, rej) => {
|
||||||
console.log(title);
|
|
||||||
var wikitext = String((await axios.get(this.url + `/index.php?title=${title}&action=raw`)).data);
|
var wikitext = String((await axios.get(this.url + `/index.php?title=${title}&action=raw`)).data);
|
||||||
var metadata : any = {};
|
var metadata : any = {};
|
||||||
// get screenshot
|
// get screenshot
|
||||||
|
|
Loading…
Reference in a new issue