自定义源新增支持local源的musicUrl、pic、lyric的获取操作
This commit is contained in:
@@ -23,13 +23,14 @@ const eventNames = Object.values(EVENT_NAMES)
|
||||
const events = {
|
||||
request: null,
|
||||
}
|
||||
const allSources = ['kw', 'kg', 'tx', 'wy', 'mg']
|
||||
const allSources = ['kw', 'kg', 'tx', 'wy', 'mg', 'local']
|
||||
const supportQualitys = {
|
||||
kw: ['128k', '320k', 'flac', 'flac24bit'],
|
||||
kg: ['128k', '320k', 'flac', 'flac24bit'],
|
||||
tx: ['128k', '320k', 'flac', 'flac24bit'],
|
||||
wy: ['128k', '320k', 'flac', 'flac24bit'],
|
||||
mg: ['128k', '320k', 'flac', 'flac24bit'],
|
||||
local: [],
|
||||
}
|
||||
const supportActions = {
|
||||
kw: ['musicUrl'],
|
||||
@@ -38,6 +39,18 @@ const supportActions = {
|
||||
wy: ['musicUrl'],
|
||||
mg: ['musicUrl'],
|
||||
xm: ['musicUrl'],
|
||||
local: ['musicUrl', 'lyric', 'pic'],
|
||||
}
|
||||
|
||||
const verifyLyricInfo = (info) => {
|
||||
if (typeof info != 'object' || typeof info.lyric != 'string') throw new Error('failed')
|
||||
if (info.lyric.length > 4096) throw new Error('failed')
|
||||
return {
|
||||
lyric: info.lyric,
|
||||
tlyric: (typeof info.tlyric == 'string' && info.tlyric.length < 4096) ? info.tlyric : null,
|
||||
mlyric: typeof info.mlyric == 'string' && info.mlyric.length < 4096 ? info.mlyric : null,
|
||||
lxlyric: typeof info.lxlyric == 'string' && info.lxlyric.length < 4096 ? info.lxlyric : null,
|
||||
}
|
||||
}
|
||||
|
||||
const handleRequest = (context, { requestKey, data }) => {
|
||||
@@ -50,6 +63,7 @@ const handleRequest = (context, { requestKey, data }) => {
|
||||
}
|
||||
switch (data.action) {
|
||||
case 'musicUrl':
|
||||
if (typeof response != 'string' || response.length > 2048 || !/^https?:/.test(response)) throw new Error('failed')
|
||||
sendData.result = {
|
||||
source: data.source,
|
||||
action: data.action,
|
||||
@@ -59,6 +73,21 @@ const handleRequest = (context, { requestKey, data }) => {
|
||||
},
|
||||
}
|
||||
break
|
||||
case 'lyric':
|
||||
sendData.result = {
|
||||
source: data.source,
|
||||
action: data.action,
|
||||
data: verifyLyricInfo(response),
|
||||
}
|
||||
break
|
||||
case 'pic':
|
||||
if (typeof response != 'string' || response.length > 2048 || !/^https?:/.test(response)) throw new Error('failed')
|
||||
sendData.result = {
|
||||
source: data.source,
|
||||
action: data.action,
|
||||
data: response,
|
||||
}
|
||||
break
|
||||
}
|
||||
sendMessage(USER_API_RENDERER_EVENT_NAME.response, sendData, true)
|
||||
}).catch(err => {
|
||||
|
||||
@@ -79,16 +79,16 @@ export const createUserLists = (position: number, lists: LX.List.UserListInfo[])
|
||||
* 覆盖列表
|
||||
* @param lists 列表信息
|
||||
*/
|
||||
export const setUserLists = (lists: LX.List.UserListInfo[]) => {
|
||||
const newUserLists: LX.DBService.UserListInfo[] = lists.map((list, index) => {
|
||||
return {
|
||||
...list,
|
||||
position: index,
|
||||
}
|
||||
})
|
||||
inertUserLists(newUserLists, true)
|
||||
userLists = newUserLists
|
||||
}
|
||||
// const setUserLists = (lists: LX.List.UserListInfo[]) => {
|
||||
// const newUserLists: LX.DBService.UserListInfo[] = lists.map((list, index) => {
|
||||
// return {
|
||||
// ...list,
|
||||
// position: index,
|
||||
// }
|
||||
// })
|
||||
// inertUserLists(newUserLists, true)
|
||||
// userLists = newUserLists
|
||||
// }
|
||||
|
||||
/**
|
||||
* 批量删除列表
|
||||
|
||||
Reference in New Issue
Block a user