Refactor scan infomation featurn (#174)
* feat: add scanning setting panel * feat: implement the back-end interface * feat: add i18n-zh * chore: remove never used code
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
import SettingCardSize from 'components/SettingCardSize.vue'
|
||||
import { request } from 'hooks/request'
|
||||
import { defineStore } from 'hooks/store'
|
||||
import { $el, app, ComfyDialog } from 'scripts/comfyAPI'
|
||||
import { app } from 'scripts/comfyAPI'
|
||||
import { computed, onMounted, onUnmounted, readonly, ref, watch } from 'vue'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useToast } from './toast'
|
||||
|
||||
export const useConfig = defineStore('config', (store) => {
|
||||
const { t } = useI18n()
|
||||
@@ -98,41 +96,8 @@ export const configSetting = {
|
||||
}
|
||||
|
||||
function useAddConfigSettings(store: import('hooks/store').StoreProvider) {
|
||||
const { toast } = useToast()
|
||||
const { t } = useI18n()
|
||||
|
||||
const confirm = (opts: {
|
||||
message?: string
|
||||
accept?: () => void
|
||||
reject?: () => void
|
||||
}) => {
|
||||
const dialog = new ComfyDialog('div', [])
|
||||
|
||||
dialog.show(
|
||||
$el('div', [
|
||||
$el('p', { textContent: opts.message }),
|
||||
$el('div.flex.gap-4', [
|
||||
$el('button.flex-1', {
|
||||
textContent: 'Cancel',
|
||||
onclick: () => {
|
||||
opts.reject?.()
|
||||
dialog.close()
|
||||
document.body.removeChild(dialog.element)
|
||||
},
|
||||
}),
|
||||
$el('button.flex-1', {
|
||||
textContent: 'Continue',
|
||||
onclick: () => {
|
||||
opts.accept?.()
|
||||
dialog.close()
|
||||
document.body.removeChild(dialog.element)
|
||||
},
|
||||
}),
|
||||
]),
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
// API keys
|
||||
app.ui?.settings.addSetting({
|
||||
@@ -187,101 +152,6 @@ function useAddConfigSettings(store: import('hooks/store').StoreProvider) {
|
||||
},
|
||||
})
|
||||
|
||||
// Scan information
|
||||
app.ui?.settings.addSetting({
|
||||
id: 'ModelManager.ScanFiles.Full',
|
||||
category: [t('modelManager'), t('setting.scan'), 'Full'],
|
||||
name: t('setting.scanAll'),
|
||||
defaultValue: '',
|
||||
type: () => {
|
||||
return $el('button.p-button.p-component.p-button-secondary', {
|
||||
textContent: 'Full Scan',
|
||||
onclick: () => {
|
||||
confirm({
|
||||
message: [
|
||||
'This operation will override current files.',
|
||||
'This may take a while and generate MANY server requests!',
|
||||
'USE AT YOUR OWN RISK! Continue?',
|
||||
].join('\n'),
|
||||
accept: () => {
|
||||
store.loading.loading.value = true
|
||||
request('/model-info/scan', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ scanMode: 'full' }),
|
||||
})
|
||||
.then(() => {
|
||||
toast.add({
|
||||
severity: 'success',
|
||||
summary: 'Complete download information',
|
||||
life: 2000,
|
||||
})
|
||||
store.models.refresh()
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err.message ?? 'Failed to download information',
|
||||
life: 15000,
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
store.loading.loading.value = false
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
app.ui?.settings.addSetting({
|
||||
id: 'ModelManager.ScanFiles.Incremental',
|
||||
category: [t('modelManager'), t('setting.scan'), 'Incremental'],
|
||||
name: t('setting.scanMissing'),
|
||||
defaultValue: '',
|
||||
type: () => {
|
||||
return $el('button.p-button.p-component.p-button-secondary', {
|
||||
textContent: 'Diff Scan',
|
||||
onclick: () => {
|
||||
confirm({
|
||||
message: [
|
||||
'Download missing information or preview.',
|
||||
'This may take a while and generate MANY server requests!',
|
||||
'USE AT YOUR OWN RISK! Continue?',
|
||||
].join('\n'),
|
||||
accept: () => {
|
||||
store.loading.loading.value = true
|
||||
request('/model-info/scan', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ scanMode: 'diff' }),
|
||||
})
|
||||
.then(() => {
|
||||
toast.add({
|
||||
severity: 'success',
|
||||
summary: 'Complete download information',
|
||||
life: 2000,
|
||||
})
|
||||
store.models.refresh()
|
||||
})
|
||||
.catch((err) => {
|
||||
toast.add({
|
||||
severity: 'error',
|
||||
summary: 'Error',
|
||||
detail: err.message ?? 'Failed to download information',
|
||||
life: 15000,
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
store.loading.loading.value = false
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
app.ui?.settings.addSetting({
|
||||
id: configSetting.excludeScanTypes,
|
||||
category: [t('modelManager'), t('setting.scan'), 'ExcludeScanTypes'],
|
||||
|
||||
@@ -443,7 +443,7 @@ export const useModelBaseInfo = () => {
|
||||
|
||||
export const useModelFolder = (
|
||||
option: {
|
||||
type?: MaybeRefOrGetter<string>
|
||||
type?: MaybeRefOrGetter<string | undefined>
|
||||
} = {},
|
||||
) => {
|
||||
const { data: models, folders: modelFolders } = useModels()
|
||||
|
||||
Reference in New Issue
Block a user