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