mirror of
https://hubproxy.babadafafafafa.cn/https://github.com/lyswhut/lx-music-desktop.git
synced 2026-09-20 08:04:00 +08:00
fix: 音源导入去重 (#2681)
* fix: 音源导入添加去重逻辑 修复音源导入时未对重复数据进行去重的问题。现在会根据url去重,避免导入重复的音源。 Fixes lyswhut/lx-music-desktop#2649 * fix: check script content instead of name for dedup Allow duplicate source names (intentional behavior). Only reject import when script content is identical to an existing source, and report which source name conflicts.
This commit is contained in:
committed by
GitHub
parent
b9c3c3506e
commit
a339f0fd0c
@@ -109,14 +109,20 @@ const inflateScript = async(script: string) => new Promise<string>((resolve, rej
|
|||||||
})
|
})
|
||||||
export const importApi = async(scriptRaw: string): Promise<LX.UserApi.UserApiInfo> => {
|
export const importApi = async(scriptRaw: string): Promise<LX.UserApi.UserApiInfo> => {
|
||||||
let scriptInfo = parseScriptInfo(scriptRaw)
|
let scriptInfo = parseScriptInfo(scriptRaw)
|
||||||
|
const script = await deflateScript(scriptRaw)
|
||||||
|
userApis ??= []
|
||||||
|
for (const api of userApis) {
|
||||||
|
const existingScript = scripts.get(api.id)
|
||||||
|
if (existingScript === script) {
|
||||||
|
throw new Error(`导入失败,脚本内容与已有的源「${api.name}」相同`)
|
||||||
|
}
|
||||||
|
}
|
||||||
const apiInfo = {
|
const apiInfo = {
|
||||||
id: `user_api_${Math.random().toString().substring(2, 5)}_${Date.now()}`,
|
id: `user_api_${Math.random().toString().substring(2, 5)}_${Date.now()}`,
|
||||||
...scriptInfo,
|
...scriptInfo,
|
||||||
allowShowUpdateAlert: true,
|
allowShowUpdateAlert: true,
|
||||||
}
|
}
|
||||||
userApis ??= []
|
|
||||||
userApis.push(apiInfo)
|
userApis.push(apiInfo)
|
||||||
const script = await deflateScript(scriptRaw)
|
|
||||||
scripts.set(apiInfo.id, script)
|
scripts.set(apiInfo.id, script)
|
||||||
saveData()
|
saveData()
|
||||||
return apiInfo
|
return apiInfo
|
||||||
|
|||||||
Reference in New Issue
Block a user