mirror of
https://github.com/misenhower/splatoon3.ink.git
synced 2026-04-25 23:37:43 -05:00
Guard against accessing undefined media arrays in FileWriter, ImageWriter, and protect against findIndex returning -1 in SplatfestResultsBox. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
22 lines
518 B
JavaScript
22 lines
518 B
JavaScript
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) {
|
|
if (!status.media?.length) {
|
|
return;
|
|
}
|
|
|
|
await mkdirp(this.dir);
|
|
|
|
let imgFilename = `${this.dir}/${generator.key}.png`;
|
|
await fs.writeFile(imgFilename, status.media[0].file);
|
|
}
|
|
}
|