* fix(PromptStore): import prompt template using different dict keys * chore(PromptStore): clear url field after downloading
This commit is contained in:
@@ -144,24 +144,41 @@ const clearPromptTemplate = () => {
|
||||
const importPromptTemplate = () => {
|
||||
try {
|
||||
const jsonData = JSON.parse(tempPromptValue.value)
|
||||
let key = ''
|
||||
let value = ''
|
||||
// 可以扩展加入更多模板字典的key
|
||||
if ('key' in jsonData[0]) {
|
||||
key = 'key'
|
||||
value = 'value'
|
||||
}
|
||||
else if ('act' in jsonData[0]) {
|
||||
key = 'act'
|
||||
value = 'prompt'
|
||||
}
|
||||
else {
|
||||
// 不支持的字典的key防止导入 以免破坏prompt商店打开
|
||||
message.warning('prompt key not supported.')
|
||||
throw new Error('prompt key not supported.')
|
||||
}
|
||||
|
||||
for (const i of jsonData) {
|
||||
if (!('key' in i) || !('value' in i))
|
||||
throw new Error('键值不匹配')
|
||||
let safe = true
|
||||
for (const j of promptList.value) {
|
||||
if (j.key === i.key) {
|
||||
message.warning(`因标题重复跳过:${i.key}`)
|
||||
if (j.key === i[key]) {
|
||||
message.warning(`因标题重复跳过:${i[key]}`)
|
||||
safe = false
|
||||
break
|
||||
}
|
||||
if (j.value === i.value) {
|
||||
message.warning(`因内容重复跳过:${i.key}`)
|
||||
if (j.value === i[value]) {
|
||||
message.warning(`因内容重复跳过:${i[key]}`)
|
||||
safe = false
|
||||
break
|
||||
}
|
||||
}
|
||||
if (safe)
|
||||
promptList.value.unshift({ key: i.key, value: i.value } as never)
|
||||
promptList.value.unshift({ key: i[key], value: i[value] } as never)
|
||||
}
|
||||
message.success('导入成功')
|
||||
changeShowModal('')
|
||||
@@ -194,6 +211,7 @@ const downloadPromptTemplate = async () => {
|
||||
}).then(() => {
|
||||
importPromptTemplate()
|
||||
})
|
||||
downloadURL.value = ''
|
||||
}
|
||||
catch {
|
||||
message.error('网络导入出现问题,请检查网络状态与 JSON 文件有效性')
|
||||
|
||||
Reference in New Issue
Block a user