Skip to content

Commit

Permalink
修复 tx 歌单搜索名字、描述出现乱码的问题(#2250
Browse files Browse the repository at this point in the history
  • Loading branch information
lyswhut committed Feb 4, 2025
1 parent 68b32a2 commit 3ac6d0f
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 19 deletions.
1 change: 1 addition & 0 deletions publish/changeLog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
### 修复

- 修复 Windows 下桌面歌词最小高度设置问题(#2244
- 修复 tx 歌单搜索名字、描述出现乱码的问题(#2250
13 changes: 0 additions & 13 deletions src/common/utils/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,6 @@ export const formatPlayTime2 = (time: number) => {
}


const encodeNames = {
' ': ' ',
'&': '&',
'&lt;': '<',
'&gt;': '>',
'&quot;': '"',
'&apos;': "'",
'&#039;': "'",
} as const
export const decodeName = (str: string | null = '') => {
return str?.replace(/(?:&amp;|&lt;|&gt;|&quot;|&apos;|&#039;|&nbsp;)/gm, (s: string) => encodeNames[s as keyof typeof encodeNames]) ?? ''
}

export const isUrl = (path: string) => /https?:\/\//.test(path)

// 解析URL参数为对象
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/core/useApp/useDeeplink/useMusicAction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { markRaw } from '@common/utils/vueTools'
import { useRouter } from '@common/utils/vueRouter'
import { decodeName } from '@common/utils/common'
import { decodeName } from '@renderer/utils'
// import { allList, defaultList, loveList, userLists } from '@renderer/store/list'
import { playMusicInfo, isShowPlayerDetail } from '@renderer/store/player/state'
import { setShowPlayerDetail, addTempPlayList } from '@renderer/store/player/action'
Expand Down
5 changes: 5 additions & 0 deletions src/renderer/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,3 +75,8 @@ export const deduplicationList = <T extends LX.Music.MusicInfo>(list: T[]): T[]
export const langS2T = async(str: string) => {
return window.lx.worker.main.langS2t(Buffer.from(str).toString('base64')).then(b64 => Buffer.from(b64, 'base64').toString())
}

export const decodeName = (str: string | null = '') => {
if (!str) return ''
return new window.DOMParser().parseFromString(str, 'text/html').body.textContent
}
8 changes: 4 additions & 4 deletions src/renderer/utils/musicSdk/tx/songList.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ export default {
img: item.cover_url_medium,
// grade: item.favorcnt / 10,
total: item.song_ids?.length,
desc: item.desc,
desc: decodeName(item.desc).replace(/<br>/g, '\n'),
source: 'tx',
})),
total: data.total,
Expand Down Expand Up @@ -305,13 +305,13 @@ export default {
return {
play_count: formatPlayCount(item.listennum),
id: String(item.dissid),
author: item.creator.name,
name: item.dissname,
author: decodeName(item.creator.name),
name: decodeName(item.dissname),
time: dateFormat(item.createtime, 'Y-M-D'),
img: item.imgurl,
// grade: item.favorcnt / 10,
total: item.song_count,
desc: item.introduction,
desc: decodeName(decodeName(item.introduction)).replace(/<br>/g, '\n'),
source: 'tx',
}
}),
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/utils/musicSdk/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import crypto from 'crypto'
import dns from 'dns'
import { decodeName } from '@common/utils/common'
import { decodeName } from '@renderer/utils'

export const toMD5 = str => crypto.createHash('md5').update(str).digest('hex')

Expand Down

0 comments on commit 3ac6d0f

Please sign in to comment.