From a2059633b2e4148eed796cc0c93671236adfbddf Mon Sep 17 00:00:00 2001 From: phozzzzzz Date: Fri, 8 May 2026 21:35:33 -0700 Subject: [PATCH] Fix asset script download handling --- scripts/heads.js | 4 ++-- scripts/materials.js | 15 +++++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/scripts/heads.js b/scripts/heads.js index d24e3d826..cbca5ef82 100644 --- a/scripts/heads.js +++ b/scripts/heads.js @@ -55,9 +55,9 @@ await bufferUnordered(items, async item => { await bufferUnordered(heads, async item => { if (!item.texture || await fs.promises.stat(`./assets/textures/${item.id}.png`).then(() => true).catch(e => false)) - return console.log(`Skipped "${item.name}" ${++i}/${items.length}...`); + return console.log(`Skipped "${item.name}" ${++i}/${heads.length}...`); - const { data: buf } = await axios.get(`https://sky.shiiyu.moe/head/${item.texture}`, { + const { data: buf } = await axios.get(`https://sky.shiiiyu.moe/head/${item.texture}`, { responseType: 'arraybuffer' }); diff --git a/scripts/materials.js b/scripts/materials.js index e815481da..bd2b9d49e 100644 --- a/scripts/materials.js +++ b/scripts/materials.js @@ -18,6 +18,7 @@ const ORDER = [ ]; const ANIMATE_REGEX = /_(\d+)\.[^.]+$/; +const MAX_HEAD_DOWNLOAD_ATTEMPTS = 3; fs.mkdirSync('./assets/materials', { recursive: true }); fs.mkdirSync('./assets/textures', { recursive: true }); @@ -68,11 +69,9 @@ for (const name of ORDER) { const texture = data.textures.SKIN.url; const id = texture.slice(texture.lastIndexOf('/') + 1); - let tryagain = true; - - while (tryagain) { + for (let attempt = 1; attempt <= MAX_HEAD_DOWNLOAD_ATTEMPTS; attempt++) { try { - const { data: buf } = await axios.get(`https://sky.shiiyu.moe/head/${id}`, { + const { data: buf } = await axios.get(`https://sky.shiiiyu.moe/head/${id}`, { responseType: 'arraybuffer' }); @@ -83,10 +82,14 @@ for (const name of ORDER) { }) .toFile(`./assets/materials/${name.replace(/:/g, ';').toUpperCase()}.png`); - tryagain = false; - console.log(`[MATERIAL] Processed "${name}" (${path})`); + break; } catch (e) { + if (attempt === MAX_HEAD_DOWNLOAD_ATTEMPTS) { + console.error(`Failed to download head texture "${id}" after ${attempt} attempts`, e); + break; + } + console.error(e); } }