Add null/bounds checks for media arrays and Splatfest results

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>
This commit is contained in:
Matt Isenhower 2026-01-31 20:03:48 -08:00
parent abb6eff676
commit c1a290e7bc
3 changed files with 19 additions and 13 deletions

View File

@ -11,18 +11,20 @@ export default class FileWriter extends Client {
async send(status, generator) {
await mkdirp(this.dir);
let imgFilename = `${this.dir}/${generator.key}.png`;
await fs.writeFile(imgFilename, status.media[0].file);
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 text = [
'Status:',
status.status,
'',
'Alt text:',
status.media[0].altText,
].join('\n');
let textFilename = `${this.dir}/${generator.key}.txt`;
await fs.writeFile(textFilename, text);
let textFilename = `${this.dir}/${generator.key}.txt`;
await fs.writeFile(textFilename, text);
}
}
}

View File

@ -9,6 +9,10 @@ export default class ImageWriter extends Client {
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`;

View File

@ -1,5 +1,5 @@
<template>
<ProductContainer class="pt-10 pb-4" bg="bg-camo-purple" :bg-style="`background-color: ${toRgba(winner.color)};`">
<ProductContainer v-if="winner" class="pt-10 pb-4" bg="bg-camo-purple" :bg-style="`background-color: ${toRgba(winner.color)};`">
<div class="space-y-2">
<div class="font-splatoon1 text-2xl lg:text-3xl text-shadow mx-2">
{{ $t('festival.results.title') }}
@ -89,7 +89,7 @@ const resultRows = computed(() => {
});
const winnerIndex = computed(() => props.festival.teams.findIndex(t => t.result.isWinner));
const winner = computed(() => props.festival.teams[winnerIndex.value]);
const winner = computed(() => winnerIndex.value >= 0 ? props.festival.teams[winnerIndex.value] : null);
</script>
<style scoped>