Skip to content

Commit

Permalink
Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
otociulis committed Nov 9, 2024
1 parent d67c332 commit 491af87
Showing 1 changed file with 67 additions and 9 deletions.
76 changes: 67 additions & 9 deletions src/models/DownloadManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ export class DownloadManager {
const download = this.downloads.get(url);

if (download) {
this.reportProgress({url, filename: download.filename, savePath: download.savePath, progress: 0, status: DownloadStatus.PENDING});
this.reportProgress({
url,
filename: download.filename,
savePath: download.savePath,
progress: 0,
status: DownloadStatus.PENDING,
});
item.setSavePath(download.tempPath);
download.item = item;
log.info(`Setting save path to ${item.getSavePath()}`);
Expand All @@ -61,9 +67,21 @@ export class DownloadManager {
const progress = item.getReceivedBytes() / item.getTotalBytes();
if (item.isPaused()) {
log.info('Download is paused');
this.reportProgress({url, progress, filename: download.filename, savePath: download.savePath, status: DownloadStatus.PAUSED });
this.reportProgress({
url,
progress,
filename: download.filename,
savePath: download.savePath,
status: DownloadStatus.PAUSED,
});
} else {
this.reportProgress({url, progress, filename: download.filename, savePath: download.savePath, status: DownloadStatus.IN_PROGRESS });
this.reportProgress({
url,
progress,
filename: download.filename,
savePath: download.savePath,
status: DownloadStatus.IN_PROGRESS,
});
}
}
});
Expand All @@ -77,12 +95,24 @@ export class DownloadManager {
log.error(`Failed to rename downloaded file: ${error}. Deleting temp file.`);
fs.unlinkSync(download.tempPath);
}
this.reportProgress({url, filename: download.filename, savePath: download.savePath, progress: 1, status: DownloadStatus.COMPLETED});
this.reportProgress({
url,
filename: download.filename,
savePath: download.savePath,
progress: 1,
status: DownloadStatus.COMPLETED,
});
this.downloads.delete(url);
} else {
log.info(`Download failed: ${state}`);
const progress = item.getReceivedBytes() / item.getTotalBytes();
this.reportProgress({url, filename: download.filename, progress, status: DownloadStatus.ERROR, savePath: download.savePath });
this.reportProgress({
url,
filename: download.filename,
progress,
status: DownloadStatus.ERROR,
savePath: download.savePath,
});
}
});
}
Expand All @@ -93,14 +123,28 @@ export class DownloadManager {
const localSavePath = this.getLocalSavePath(filename, savePath);
if (!this.isPathInModelsDirectory(localSavePath)) {
log.error(`Save path ${localSavePath} is not in models directory ${this.modelsDirectory}`);
this.reportProgress({url, savePath, filename, progress: 0, status: DownloadStatus.ERROR, message: 'Save path is not in models directory'});
this.reportProgress({
url,
savePath,
filename,
progress: 0,
status: DownloadStatus.ERROR,
message: 'Save path is not in models directory',
});
return false;
}

const validationResult = this.validateSafetensorsFile(url, filename);
if (!validationResult.isValid) {
log.error(validationResult.error);
this.reportProgress({url, savePath, filename, progress:0, status:DownloadStatus.ERROR, message: validationResult.error});
this.reportProgress({
url,
savePath,
filename,
progress: 0,
status: DownloadStatus.ERROR,
message: validationResult.error,
});
return false;
}

Expand Down Expand Up @@ -248,15 +292,29 @@ export class DownloadManager {
return absoluteFilePath.startsWith(absoluteModelsDir);
}

private reportProgress({url, progress, status, savePath, filename, message = ''}: {url: string, progress: number, status: DownloadStatus, filename:string, savePath:string, message?: string}): void {
private reportProgress({
url,
progress,
status,
savePath,
filename,
message = '',
}: {
url: string;
progress: number;
status: DownloadStatus;
filename: string;
savePath: string;
message?: string;
}): void {
log.info(`Download progress [${filename}]: ${progress}, status: ${status}, message: ${message}`);
this.mainWindow.send(IPC_CHANNELS.DOWNLOAD_PROGRESS, {
url,
progress,
status,
message,
savePath,
filename
filename,
});
}

Expand Down

0 comments on commit 491af87

Please sign in to comment.