mioku-service-webui 4.0.6 → 4.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/system.ts +38 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mioku-service-webui",
3
- "version": "4.0.6",
3
+ "version": "4.0.7",
4
4
  "description": "Mioku WebUI 服务",
5
5
  "main": "index.ts",
6
6
  "type": "module",
package/system.ts CHANGED
@@ -1798,6 +1798,9 @@ export async function updateWebUIDistFromRelease(): Promise<
1798
1798
  );
1799
1799
  }
1800
1800
 
1801
+ let lastLogTime = 0;
1802
+ const LOG_INTERVAL_MS = 2000;
1803
+ const downloadUrl = new URL(check.assetUrl);
1801
1804
  const tempDir = path.join(
1802
1805
  os.tmpdir(),
1803
1806
  `mioku-webui-update-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`,
@@ -1810,7 +1813,6 @@ export async function updateWebUIDistFromRelease(): Promise<
1810
1813
 
1811
1814
  let backupPath = "";
1812
1815
  try {
1813
- const downloadUrl = check.proxiedAssetUrl || check.assetUrl;
1814
1816
  const downloadRes = await fetch(downloadUrl, {
1815
1817
  headers: {
1816
1818
  Accept: "application/octet-stream",
@@ -1822,7 +1824,41 @@ export async function updateWebUIDistFromRelease(): Promise<
1822
1824
  throw new Error(`下载 dist 压缩包失败: HTTP_${downloadRes.status}`);
1823
1825
  }
1824
1826
 
1825
- const buffer = Buffer.from(await downloadRes.arrayBuffer());
1827
+ const contentLength = Number(downloadRes.headers.get("content-length") || 0);
1828
+ const reader = downloadRes.body?.getReader();
1829
+ if (!reader) {
1830
+ throw new Error("无法读取下载流");
1831
+ }
1832
+
1833
+ const chunks: Buffer[] = [];
1834
+ let receivedBytes = 0;
1835
+
1836
+ while (true) {
1837
+ const { done, value } = await reader.read();
1838
+ if (done) break;
1839
+
1840
+ if (value) {
1841
+ chunks.push(Buffer.from(value));
1842
+ receivedBytes += value.length;
1843
+
1844
+ if (contentLength > 0) {
1845
+ const now = Date.now();
1846
+ if (now - lastLogTime >= LOG_INTERVAL_MS) {
1847
+ const progress = Math.round((receivedBytes / contentLength) * 100);
1848
+ logger.info(`[webui] 正在下载 WebUI dist... ${receivedBytes}/${contentLength} bytes (${progress}%)`);
1849
+ lastLogTime = now;
1850
+ }
1851
+ }
1852
+ }
1853
+ }
1854
+
1855
+ if (contentLength > 0 && receivedBytes !== contentLength) {
1856
+ logger.warn(`[webui] 下载字节数不匹配: 预期 ${contentLength}, 实际 ${receivedBytes}`);
1857
+ }
1858
+
1859
+ logger.info(`[webui] 下载完成,正在解压...`);
1860
+
1861
+ const buffer = Buffer.concat(chunks);
1826
1862
  fs.writeFileSync(zipPath, buffer);
1827
1863
 
1828
1864
  const zip = new AdmZip(zipPath);