Merge pull request #3991 from janhq/fix/inconsistent-model-dropdown-list
fix: inconsistent model dropdown list and my models
This commit is contained in:
commit
5cb4b64383
@ -1,6 +1,6 @@
|
|||||||
import { resolve, sep } from 'path'
|
import { resolve, sep } from 'path'
|
||||||
import { DownloadEvent } from '../../../types/api'
|
import { DownloadEvent } from '../../../types/api'
|
||||||
import { normalizeFilePath, validatePath } from '../../helper/path'
|
import { normalizeFilePath } from '../../helper/path'
|
||||||
import { getJanDataFolderPath } from '../../helper'
|
import { getJanDataFolderPath } from '../../helper'
|
||||||
import { DownloadManager } from '../../helper/download'
|
import { DownloadManager } from '../../helper/download'
|
||||||
import { createWriteStream, renameSync } from 'fs'
|
import { createWriteStream, renameSync } from 'fs'
|
||||||
@ -37,7 +37,6 @@ export class Downloader implements Processor {
|
|||||||
const modelId = downloadRequest.modelId ?? array.pop() ?? ''
|
const modelId = downloadRequest.modelId ?? array.pop() ?? ''
|
||||||
|
|
||||||
const destination = resolve(getJanDataFolderPath(), normalizedPath)
|
const destination = resolve(getJanDataFolderPath(), normalizedPath)
|
||||||
validatePath(destination)
|
|
||||||
const rq = request({ url, strictSSL, proxy })
|
const rq = request({ url, strictSSL, proxy })
|
||||||
|
|
||||||
// Put request to download manager instance
|
// Put request to download manager instance
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
import { join, resolve } from 'path'
|
import { join, resolve } from 'path'
|
||||||
import { normalizeFilePath, validatePath } from '../../helper/path'
|
import { normalizeFilePath } from '../../helper/path'
|
||||||
import { getJanDataFolderPath } from '../../helper'
|
import { getJanDataFolderPath } from '../../helper'
|
||||||
import { Processor } from './Processor'
|
import { Processor } from './Processor'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
@ -36,7 +36,6 @@ export class FileSystem implements Processor {
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
const absolutePath = resolve(path)
|
const absolutePath = resolve(path)
|
||||||
validatePath(absolutePath)
|
|
||||||
return absolutePath
|
return absolutePath
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
@ -55,7 +54,6 @@ export class FileSystem implements Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const absolutePath = resolve(path)
|
const absolutePath = resolve(path)
|
||||||
validatePath(absolutePath)
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.rm(absolutePath, { recursive: true, force: true }, (err) => {
|
fs.rm(absolutePath, { recursive: true, force: true }, (err) => {
|
||||||
@ -79,7 +77,6 @@ export class FileSystem implements Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const absolutePath = resolve(path)
|
const absolutePath = resolve(path)
|
||||||
validatePath(absolutePath)
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.mkdir(absolutePath, { recursive: true }, (err) => {
|
fs.mkdir(absolutePath, { recursive: true }, (err) => {
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import { basename, join } from 'path'
|
import { basename, join } from 'path'
|
||||||
import fs, { readdirSync } from 'fs'
|
import fs, { readdirSync } from 'fs'
|
||||||
import { appResourcePath, normalizeFilePath, validatePath } from '../../helper/path'
|
import { appResourcePath, normalizeFilePath } from '../../helper/path'
|
||||||
import { defaultAppConfig, getJanDataFolderPath, getJanDataFolderPath as getPath } from '../../helper'
|
import { defaultAppConfig, getJanDataFolderPath, getJanDataFolderPath as getPath } from '../../helper'
|
||||||
import { Processor } from './Processor'
|
import { Processor } from './Processor'
|
||||||
import { FileStat } from '../../../types'
|
import { FileStat } from '../../../types'
|
||||||
@ -61,7 +61,6 @@ export class FSExt implements Processor {
|
|||||||
|
|
||||||
const dataBuffer = Buffer.from(data, 'base64')
|
const dataBuffer = Buffer.from(data, 'base64')
|
||||||
const writePath = join(getJanDataFolderPath(), normalizedPath)
|
const writePath = join(getJanDataFolderPath(), normalizedPath)
|
||||||
validatePath(writePath)
|
|
||||||
fs.writeFileSync(writePath, dataBuffer)
|
fs.writeFileSync(writePath, dataBuffer)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(`writeFile ${path} result: ${err}`)
|
console.error(`writeFile ${path} result: ${err}`)
|
||||||
@ -69,7 +68,6 @@ export class FSExt implements Processor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
copyFile(src: string, dest: string): Promise<void> {
|
copyFile(src: string, dest: string): Promise<void> {
|
||||||
validatePath(dest)
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
fs.copyFile(src, dest, (err) => {
|
fs.copyFile(src, dest, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|||||||
@ -34,18 +34,4 @@ export function appResourcePath() {
|
|||||||
|
|
||||||
// server
|
// server
|
||||||
return join(global.core.appPath(), '../../..')
|
return join(global.core.appPath(), '../../..')
|
||||||
}
|
}
|
||||||
|
|
||||||
export function validatePath(path: string) {
|
|
||||||
const appDataFolderPath = getJanDataFolderPath()
|
|
||||||
const resourcePath = appResourcePath()
|
|
||||||
const applicationSupportPath = global.core?.appPath() ?? resourcePath
|
|
||||||
const absolutePath = resolve(__dirname, path)
|
|
||||||
if (
|
|
||||||
![appDataFolderPath, resourcePath, applicationSupportPath].some((whiteListedPath) =>
|
|
||||||
absolutePath.startsWith(whiteListedPath)
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error(`Invalid path: ${absolutePath}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -179,8 +179,8 @@ export default class JanModelExtension extends ModelExtension {
|
|||||||
if (toImportModels.length > 0) {
|
if (toImportModels.length > 0) {
|
||||||
// Import models
|
// Import models
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
toImportModels.map(async (model: Model & { file_path: string }) =>
|
toImportModels.map(async (model: Model & { file_path: string }) => {
|
||||||
this.importModel(
|
return this.importModel(
|
||||||
model.id,
|
model.id,
|
||||||
model.sources[0].url.startsWith('http') ||
|
model.sources[0].url.startsWith('http') ||
|
||||||
!(await fs.existsSync(model.sources[0].url))
|
!(await fs.existsSync(model.sources[0].url))
|
||||||
@ -200,7 +200,7 @@ export default class JanModelExtension extends ModelExtension {
|
|||||||
...model.parameters,
|
...model.parameters,
|
||||||
} as Partial<Model>)
|
} as Partial<Model>)
|
||||||
})
|
})
|
||||||
)
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
return currentModels
|
return currentModels
|
||||||
|
|||||||
@ -108,6 +108,11 @@ const ModelDropdown = ({
|
|||||||
const filteredDownloadedModels = useMemo(
|
const filteredDownloadedModels = useMemo(
|
||||||
() =>
|
() =>
|
||||||
configuredModels
|
configuredModels
|
||||||
|
.concat(
|
||||||
|
downloadedModels.filter(
|
||||||
|
(e) => !configuredModels.some((x) => x.id === e.id)
|
||||||
|
)
|
||||||
|
)
|
||||||
.filter((e) =>
|
.filter((e) =>
|
||||||
e.name.toLowerCase().includes(searchText.toLowerCase().trim())
|
e.name.toLowerCase().includes(searchText.toLowerCase().trim())
|
||||||
)
|
)
|
||||||
|
|||||||
@ -21,7 +21,7 @@ const SelectingModelModal = () => {
|
|||||||
|
|
||||||
const onSelectFileClick = useCallback(async () => {
|
const onSelectFileClick = useCallback(async () => {
|
||||||
const platform = (await systemInformation()).osInfo?.platform
|
const platform = (await systemInformation()).osInfo?.platform
|
||||||
if (platform === 'win32') {
|
if (platform !== 'darwin') {
|
||||||
setImportModelStage('CHOOSE_WHAT_TO_IMPORT')
|
setImportModelStage('CHOOSE_WHAT_TO_IMPORT')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user