diff --git a/scripts/heads.js b/scripts/heads.js index d24e3d82..cbca5ef8 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 e815481d..bd2b9d49 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); } }