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>
31 lines
689 B
JavaScript
31 lines
689 B
JavaScript
import fs from 'fs/promises';
|
|
import mkdirp from 'mkdirp';
|
|
import Client from './Client.mjs';
|
|
|
|
export default class FileWriter extends Client {
|
|
key = 'file';
|
|
name = 'FileWriter';
|
|
|
|
dir = 'temp';
|
|
|
|
async send(status, generator) {
|
|
await mkdirp(this.dir);
|
|
|
|
if (status.media?.length > 0) {
|
|
let imgFilename = `${this.dir}/${generator.key}.png`;
|
|
await fs.writeFile(imgFilename, status.media[0].file);
|
|
|
|
let text = [
|
|
'Status:',
|
|
status.status,
|
|
'',
|
|
'Alt text:',
|
|
status.media[0].altText,
|
|
].join('\n');
|
|
|
|
let textFilename = `${this.dir}/${generator.key}.txt`;
|
|
await fs.writeFile(textFilename, text);
|
|
}
|
|
}
|
|
}
|