Skip to content

Commit

Permalink
fix: model downloads broken on nightly (janhq#1984)
Browse files Browse the repository at this point in the history
* fix: download error state handling

* fix: download error on Windows
  • Loading branch information
louis-jan authored Feb 10, 2024
1 parent 5ec4b8e commit 212397d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
6 changes: 3 additions & 3 deletions core/src/node/api/routes/download.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
12 changes: 6 additions & 6 deletions electron/handlers/download.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -46,7 +46,7 @@ export function handleDownloaderIPCs() {
DownloadEvent.onFileDownloadError,
{
fileName,
err: { message: 'aborted' },
error: 'aborted',
}
)
}
Expand All @@ -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() ?? ''

Expand All @@ -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,
}
)
})
Expand All @@ -121,7 +121,7 @@ export function handleDownloaderIPCs() {
{
fileName,
modelId,
err: { message: 'aborted' },
error: 'aborted',
}
)
}
Expand Down
5 changes: 4 additions & 1 deletion web/hooks/useDownloadState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
}
Expand Down

0 comments on commit 212397d

Please sign in to comment.