fix: Prompt商店在线导入可以导入两种recommend.json里提到的模板 (#516) (#521)

* fix(PromptStore): import prompt template using different dict keys

* chore(PromptStore): clear url field after downloading
main
吴杉(Shan Wu) 2 years ago committed by GitHub
parent bc5e835f78
commit 7bebee202e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,8 +1,14 @@
[ [
{
"key": "chatgpt-prompt-collection",
"desc": "Nothing1024收集整理的prompts",
"downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json",
"url": "https://github.com/Nothing1024/chatgpt-prompt-collection"
},
{ {
"key": "awesome-chatgpt-prompts-zh", "key": "awesome-chatgpt-prompts-zh",
"desc": "ChatGPT 中文调教指南", "desc": "ChatGPT 中文调教指南",
"downloadUrl": "https://raw.githubusercontent.com/Nothing1024/chatgpt-prompt-collection/main/awesome-chatgpt-prompts-zh.json", "downloadUrl": "https://raw.githubusercontent.com/PlexPt/awesome-chatgpt-prompts-zh/main/prompts-zh.json",
"url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh" "url": "https://github.com/PlexPt/awesome-chatgpt-prompts-zh"
} }
] ]

@ -144,24 +144,41 @@ const clearPromptTemplate = () => {
const importPromptTemplate = () => { const importPromptTemplate = () => {
try { try {
const jsonData = JSON.parse(tempPromptValue.value) 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) { for (const i of jsonData) {
if (!('key' in i) || !('value' in i)) if (!('key' in i) || !('value' in i))
throw new Error('键值不匹配') throw new Error('键值不匹配')
let safe = true let safe = true
for (const j of promptList.value) { for (const j of promptList.value) {
if (j.key === i.key) { if (j.key === i[key]) {
message.warning(`因标题重复跳过:${i.key}`) message.warning(`因标题重复跳过:${i[key]}`)
safe = false safe = false
break break
} }
if (j.value === i.value) { if (j.value === i[value]) {
message.warning(`因内容重复跳过:${i.key}`) message.warning(`因内容重复跳过:${i[key]}`)
safe = false safe = false
break break
} }
} }
if (safe) 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('导入成功') message.success('导入成功')
changeShowModal('') changeShowModal('')
@ -194,6 +211,7 @@ const downloadPromptTemplate = async () => {
}).then(() => { }).then(() => {
importPromptTemplate() importPromptTemplate()
}) })
downloadURL.value = ''
} }
catch { catch {
message.error('网络导入出现问题,请检查网络状态与 JSON 文件有效性') message.error('网络导入出现问题,请检查网络状态与 JSON 文件有效性')

Loading…
Cancel
Save