Commit 97fd7c71 authored by wudizhanche1000's avatar wudizhanche1000

Fix: 下载不能正确报错

parent 74fd12cf
......@@ -66,7 +66,7 @@
<td *ngIf="!mod.isInstalled()">
<button i18n (click)="installMod(mod)" type="button" *ngIf="!mod.isInstalled()" class="btn btn-primary btn-sm">安装</button>
</td>
<td *ngIf="mod.isInstalled()&&!mod.isReady()">:
<td *ngIf="mod.isInstalled()&&!mod.isReady()">
<progress class="progress progress-striped progress-animated" value="{{mod.status.progress}}" max="{{mod.status.total}}"></progress>
<!--<div i18n *ngIf="mod.isWaiting()">等待安装...</div>-->
</td>
......
......@@ -400,7 +400,7 @@ export class AppsService {
app.status.status = "ready";
Logger.info("Update Finished: ", app);
} catch (e) {
Logger.error("Update Failed: ",e);
Logger.error("Update Failed: ", e);
app.status.status = "ready";
}
}
......@@ -472,12 +472,16 @@ export class AppsService {
app.status.status = "downloading";
let metalink = await this.http.get(metalinkUrl).map((response) => response.text()).toPromise();
let downloadId = await this.downloadService.addMetalink(metalink, dir);
await this.downloadService.progress(downloadId, (status: DownloadStatus) => {
app.status.progress = status.completedLength;
app.status.total = status.totalLength;
app.status.progressMessage = status.downloadSpeedText;
this.ref.tick();
});
try {
await this.downloadService.progress(downloadId, (status: DownloadStatus) => {
app.status.progress = status.completedLength;
app.status.total = status.totalLength;
app.status.progressMessage = status.downloadSpeedText;
this.ref.tick();
});
} catch (e) {
}
let files = await this.downloadService.getFiles(downloadId);
app.status.status = "waiting";
return {app: app, files: files}
......
......@@ -112,6 +112,7 @@ export class DownloadService {
let activeList = await this.aria2.tellActive();
let waitList = await this.aria2.tellWaiting(0, MAX_LIST_NUM);
let stoppedList = await this.aria2.tellStopped(0, MAX_LIST_NUM);
this.downloadList.clear();
for (let item of activeList) {
this.downloadList.set(item.gid, new DownloadStatus(item));
}
......@@ -142,33 +143,41 @@ export class DownloadService {
let gids = this.taskMap.get(id);
if (gids) {
let allStatus: DownloadStatus;
this.updateEmitter.subscribe(() => {
let status: DownloadStatus = new DownloadStatus();
// 合并每个状态信息
status =
gids!.map((value, index, array) => {
let s = this.downloadList.get(value);
if (!s) {
throw new Error("Gid not Exists");
}
return s;
})
.reduce((previousValue, currentValue, currentIndex, array) => {
return previousValue.combine(currentValue);
}, status);
if (!allStatus) {
allStatus = status;
} else {
if (allStatus.compareTo(status) != 0) {
let subscription = this.updateEmitter.subscribe(() => {
try {
let status: DownloadStatus = new DownloadStatus();
// 合并每个状态信息
status =
gids!.map((value, index, array) => {
let s = this.downloadList.get(value);
if (!s) {
throw "Gid not exists";
}
return s;
})
.reduce((previousValue, currentValue, currentIndex, array) => {
return previousValue.combine(currentValue);
}, status);
if (!allStatus) {
allStatus = status;
} else {
if (allStatus.compareTo(status) != 0) {
allStatus = status;
}
}
}
if (allStatus.status === "error") {
reject(`Download Error: code ${allStatus.errorCode}, message: ${allStatus.errorMessage}`);
} else if (allStatus.status === "complete") {
resolve();
} else {
callback(allStatus);
if (allStatus.status === "error") {
throw `Download Error: code ${allStatus.errorCode}, message: ${allStatus.errorMessage}`;
} else if (allStatus.status === "complete") {
resolve();
subscription.unsubscribe();
} else {
callback(allStatus);
}
} catch (e) {
reject(e);
subscription.unsubscribe();
}
});
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment