Compare commits

..
1 Commits
Author SHA1 Message Date
jialin 75b70a26bd fix: download log failed 2025-07-25 11:26:09 +08:00
2 changed files with 21 additions and 16 deletions
+20 -15
View File
@@ -97,16 +97,20 @@ const useSetChunkFetch = () => {
this.updateProgress(data); this.updateProgress(data);
} }
public flush(done?: boolean) { public async flush(done?: boolean) {
if (this.buffer.length > 0) { if (this.buffer.length > 0) {
while (this.buffer.length > 0) { while (this.buffer.length > 0) {
const item = this.buffer.shift()!; const item = this.buffer.shift()!;
const isComplete = this.buffer.length === 0 && done; const isComplete = this.buffer.length === 0 && done;
callback(item, {
isComplete: isComplete || this.percent === 100, await new Promise<void>((resolve) => {
percent: this.percent, callback(item, {
progress: this.progress, isComplete: isComplete || this.percent === 100,
contentLength: this.contentLength percent: this.percent,
progress: this.progress,
contentLength: this.contentLength
});
resolve();
}); });
} }
} }
@@ -126,8 +130,8 @@ const useSetChunkFetch = () => {
contentLength: contentLength contentLength: contentLength
}); });
const throttledCallback = throttle(() => { const throttledCallback = throttle(async () => {
bufferManager.flush(); await bufferManager.flush();
}, delay); }, delay);
let isReading = true; let isReading = true;
@@ -135,20 +139,21 @@ const useSetChunkFetch = () => {
while (isReading) { while (isReading) {
const { done, value } = await reader.read(); const { done, value } = await reader.read();
if (done) {
isReading = false;
bufferManager.flush(done);
break;
}
try { try {
const chunk = decoder.decode(value, { stream: true }); const chunk = decoder.decode(value, { stream: true });
bufferManager.add(chunk); bufferManager.add(chunk);
// bufferManager.updateSpeed(chunk.length);
throttledCallback(); throttledCallback();
} catch (error) { } catch (error) {
// handle error // handle error
} }
if (done) {
isReading = false;
await bufferManager.flush(done);
throttledCallback.cancel();
reader.releaseLock();
break;
}
} }
}; };
@@ -347,7 +347,7 @@ const renderMessage = (title: string) => {
return ( return (
<div <div
style={{ style={{
width: 300, width: 280,
textOverflow: 'ellipsis', textOverflow: 'ellipsis',
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
overflow: 'hidden' overflow: 'hidden'