From 212397d193dba801c7575e8bddd37324cc0daba3 Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 10 Feb 2024 12:58:41 +0700 Subject: [PATCH] fix: model downloads broken on nightly (#1984) * fix: download error state handling * fix: download error on Windows --- core/src/node/api/routes/download.ts | 6 +++--- electron/handlers/download.ts | 12 ++++++------ web/hooks/useDownloadState.ts | 5 ++++- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/core/src/node/api/routes/download.ts b/core/src/node/api/routes/download.ts index 7fb05daee7..cc95fe1d4f 100644 --- a/core/src/node/api/routes/download.ts +++ b/core/src/node/api/routes/download.ts @@ -1,5 +1,5 @@ import { DownloadRoute } from '../../../api' -import { join } from 'path' +import { join, sep } from 'path' import { DownloadManager } from '../../download' import { HttpServer } from '../HttpServer' import { createWriteStream } from 'fs' @@ -38,7 +38,7 @@ export const downloadRouter = async (app: HttpServer) => { }) const localPath = normalizedArgs[1] - const array = localPath.split('/') + const array = localPath.split(sep) const fileName = array.pop() ?? '' const modelId = array.pop() ?? '' console.debug('downloadFile', normalizedArgs, fileName, modelId) @@ -99,7 +99,7 @@ export const downloadRouter = async (app: HttpServer) => { }) const localPath = normalizedArgs[0] - const fileName = localPath.split('/').pop() ?? '' + const fileName = localPath.split(sep).pop() ?? '' const rq = DownloadManager.instance.networkRequests[fileName] DownloadManager.instance.networkRequests[fileName] = undefined rq?.abort() diff --git a/electron/handlers/download.ts b/electron/handlers/download.ts index 5f1d8371e3..85261847b2 100644 --- a/electron/handlers/download.ts +++ b/electron/handlers/download.ts @@ -1,5 +1,5 @@ import { ipcMain } from 'electron' -import { resolve } from 'path' +import { resolve, sep } from 'path' import { WindowManager } from './../managers/window' import request from 'request' import { createWriteStream, renameSync } from 'fs' @@ -46,7 +46,7 @@ export function handleDownloaderIPCs() { DownloadEvent.onFileDownloadError, { fileName, - err: { message: 'aborted' }, + error: 'aborted', } ) } @@ -68,7 +68,7 @@ export function handleDownloaderIPCs() { if (typeof localPath === 'string') { localPath = normalizeFilePath(localPath) } - const array = localPath.split('/') + const array = localPath.split(sep) const fileName = array.pop() ?? '' const modelId = array.pop() ?? '' @@ -92,13 +92,13 @@ export function handleDownloaderIPCs() { } ) }) - .on('error', function (err: Error) { + .on('error', function (error: Error) { WindowManager?.instance.currentWindow?.webContents.send( DownloadEvent.onFileDownloadError, { fileName, - err, modelId, + error, } ) }) @@ -121,7 +121,7 @@ export function handleDownloaderIPCs() { { fileName, modelId, - err: { message: 'aborted' }, + error: 'aborted', } ) } diff --git a/web/hooks/useDownloadState.ts b/web/hooks/useDownloadState.ts index 207cca69fd..863c612ede 100644 --- a/web/hooks/useDownloadState.ts +++ b/web/hooks/useDownloadState.ts @@ -44,7 +44,10 @@ export const setDownloadStateAtom = atom( }) } else { let error = state.error - if (state.error?.includes('certificate')) { + if ( + typeof error?.includes === 'function' && + state.error?.includes('certificate') + ) { error += '. To fix enable "Ignore SSL Certificates" in Advanced settings.' }