add ImageWriter

This commit is contained in:
kitt 2022-12-31 00:12:38 -05:00
parent e93c49348b
commit 9e337ca1ab
No known key found for this signature in database
5 changed files with 28 additions and 0 deletions

View File

@ -5,6 +5,7 @@ import { sendStatuses, testStatuses } from './social/index.mjs';
import { updateAll } from './data/index.mjs';
import { warmCaches } from "./splatnet/index.mjs";
import MastodonClient from './social/clients/MastodonClient.mjs';
import ImageWriter from './social/clients/ImageWriter.mjs';
consoleStamp(console);
dotenv.config();
@ -14,6 +15,7 @@ const actions = {
social: sendStatuses,
socialTest: testStatuses,
socialTestMastodon: () => testStatuses([new MastodonClient]),
socialTestImage: () => testStatuses([new ImageWriter]),
splatnet: updateAll,
warmCaches,
}

View File

@ -0,0 +1,17 @@
import fs from 'fs/promises';
import mkdirp from 'mkdirp';
import Client from "./Client.mjs";
export default class ImageWriter extends Client {
key = 'image';
name = 'ImageWriter';
dir = 'dist/status-screenshots'; // `/screenshots` points to the page used by puppeteer
async send(status, generator) {
await mkdirp(this.dir);
let imgFilename = `${this.dir}/${generator.key}.png`;
await fs.writeFile(imgFilename, status.media[0].file);
}
}

View File

@ -1,4 +1,5 @@
import FileWriter from "./clients/FileWriter.mjs";
import ImageWriter from "./clients/ImageWriter.mjs";
import MastodonClient from "./clients/MastodonClient.mjs";
import TwitterClient from "./clients/TwitterClient.mjs";
import DailyDropGearStatus from "./generators/DailyDropGearStatus.mjs";
@ -26,6 +27,7 @@ function defaultClients() {
return [
new TwitterClient,
new MastodonClient,
new ImageWriter,
];
}

View File

@ -19,6 +19,12 @@ server {
autoindex on;
}
location /status-screenshots/ {
add_header Cache-Control no-cache;
add_header Access-Control-Allow-Origin *;
autoindex on;
}
# Gear redirect
location ~ /nso/g/(.*) {
return 302 https://s.nintendo.com/av5ja-lp1/znca/game/4834290508791808?p=/gesotown/$1;

View File

@ -9,6 +9,7 @@
"cron": "node app/index.mjs cron",
"social": "node app/index.mjs social",
"social:test": "node app/index.mjs socialTest",
"social:test:image": "node app/index.mjs socialTestImage",
"social:test:mastodon": "node app/index.mjs socialTestMastodon",
"splatnet": "node app/index.mjs splatnet",
"warmCaches": "node app/index.mjs warmCaches"