refactor(stage-tamagotchi): use ofetch for Steam SDK download

This commit is contained in:
Lulu
2026-08-07 23:21:44 +08:00
parent 4f34dfd274
commit dcab9c274e
3 changed files with 14 additions and 2 deletions
+1
View File
@@ -112,6 +112,7 @@
"mediabunny": "catalog:",
"node-vibrant": "catalog:",
"nprogress": "catalog:",
"ofetch": "catalog:",
"onnxruntime-web": "catalog:",
"pinia": "catalog:",
"popmotion": "catalog:",
@@ -25,6 +25,7 @@ import { dirname, join, resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
import { errorMessageFrom } from '@moeru/std'
import { ofetch } from 'ofetch'
// NOTICE:
// Keep in sync with apps/stage-tamagotchi/steam_appid.txt. Inlined here so the
@@ -53,12 +54,19 @@ function mirrorBaseUrl(): string {
}
async function downloadFile(url: string, dest: string): Promise<void> {
const response = await fetch(url)
const response = await ofetch.raw(url, {
responseType: 'arrayBuffer',
ignoreResponseError: true,
})
if (!response.ok) {
throw new Error(`Failed to download ${url}: HTTP ${response.status}`)
}
const bytes = Buffer.from(await response.arrayBuffer())
const data = response._data
if (!(data instanceof ArrayBuffer))
throw new Error(`Unexpected response type from ${url}`)
const bytes = Buffer.from(data)
if (bytes.length === 0) {
throw new Error(`Downloaded empty file from ${url}`)
}
+3
View File
@@ -2026,6 +2026,9 @@ importers:
nprogress:
specifier: 'catalog:'
version: 0.2.0
ofetch:
specifier: 'catalog:'
version: 1.5.1
onnxruntime-web:
specifier: npm:onnxruntime-web@^1.24.3
version: 1.24.3