diff --git a/publish/changeLog.md b/publish/changeLog.md index 3cb825a..29d96c9 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -5,6 +5,7 @@ ### 优化 - 过滤tx源某些不支持播放的歌曲,解决播放此类内容会导致意外的问题 +- 备份与恢复兼容单个列表文件的导入 ### 修复 diff --git a/src/screens/Home/List/components/MyList.js b/src/screens/Home/List/components/MyList.js index 19faf6f..6956a82 100644 --- a/src/screens/Home/List/components/MyList.js +++ b/src/screens/Home/List/components/MyList.js @@ -113,6 +113,7 @@ const ImportExport = ({ actionType, visible, hide, selectedListRef }) => { source: listData.data.source, sourceListId: listData.data.sourceListId, }) + toast(t('setting_backup_part_import_list_tip_success')) return } listData.data.id += `__${Date.now()}` @@ -125,6 +126,7 @@ const ImportExport = ({ actionType, visible, hide, selectedListRef }) => { sourceListId: listData.data.sourceListId, position: Math.max(selectedListRef.current.index, -1), }) + toast(t('setting_backup_part_import_list_tip_success')) }) break case 'export': diff --git a/src/screens/Home/Setting/Backup/Part.js b/src/screens/Home/Setting/Backup/Part.js index ac2510a..3ddd95e 100644 --- a/src/screens/Home/Setting/Backup/Part.js +++ b/src/screens/Home/Setting/Backup/Part.js @@ -10,7 +10,7 @@ import SubTitle from '../components/SubTitle' import Button from '../components/Button' import ChoosePath from '@/components/common/ChoosePath' import { useTranslation } from '@/plugins/i18n' -import { toast, handleSaveFile, handleReadFile } from '@/utils/tools' +import { toast, handleSaveFile, handleReadFile, confirmDialog } from '@/utils/tools' const exportAllList = async(allList, path) => { const data = JSON.parse(JSON.stringify({ @@ -71,6 +71,7 @@ export default memo(() => { // const setting = useGetter('common', 'setting') const allList = useGetter('list', 'allList') const setList = useDispatch('list', 'setList') + const createUserList = useDispatch('list', 'createUserList') const importAndExportData = useCallback(async(action, type) => { setDirOnly(action == 'export') @@ -90,6 +91,40 @@ export default memo(() => { setShowChoosePath(true) }, [t]) + const handleImportPartList = useCallback(async(listData) => { + const targetList = global.allList[listData.data.id] + if (targetList) { + const confirm = await confirmDialog({ + message: t('list_import_part_confirm', { importName: listData.data.name, localName: targetList.name }), + cancelButtonText: t('list_import_part_button_cancel'), + confirmButtonText: t('list_import_part_button_confirm'), + bgClose: false, + }) + if (confirm) { + listData.data.name = targetList.name + setList({ + name: listData.data.name, + id: listData.data.id, + list: listData.data.list, + source: listData.data.source, + sourceListId: listData.data.sourceListId, + }) + toast(t('setting_backup_part_import_list_tip_success')) + return + } + listData.data.id += `__${Date.now()}` + } + createUserList({ + name: listData.data.name, + id: listData.data.id, + list: listData.data.list, + source: listData.data.source, + sourceListId: listData.data.sourceListId, + // position: Math.max(selectedListRef.current.index, -1), + }) + toast(t('setting_backup_part_import_list_tip_success')) + }, [createUserList, setList, t]) + const onConfirmPath = useCallback(path => { setShowChoosePath(false) switch (actionTypeRef.current) { @@ -130,6 +165,10 @@ export default memo(() => { toast(t('setting_backup_part_import_list_tip_success')) break + case 'playListPart': + handleImportPartList(listData) + break + default: return toast(t('setting_backup_part_import_list_tip_failed')) } }) @@ -162,7 +201,7 @@ export default memo(() => { // setTitle(t('setting_backup_all_import_desc')) // break } - }, [allList, setList, t]) + }, [allList, handleImportPartList, setList, t]) return ( diff --git a/src/utils/music/wy/utils/crypto.js b/src/utils/music/wy/utils/crypto.js index e39aad1..b32ebff 100644 --- a/src/utils/music/wy/utils/crypto.js +++ b/src/utils/music/wy/utils/crypto.js @@ -1,10 +1,11 @@ // https://github.com/Binaryify/NeteaseCloudMusicApi/blob/master/util/crypto.js -import { createCipheriv, publicEncrypt, randomBytes } from 'crypto' +import { createCipheriv, publicEncrypt, randomBytes, createHash } from 'crypto' const iv = Buffer.from('0102030405060708') const presetKey = Buffer.from('0CoJUm6Qyw8W8jud') const linuxapiKey = Buffer.from('rFgB&h#%2?^eDg:Q') const base62 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' const publicKey = '-----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDgtQn2JZ34ZC28NWYpAUd98iZ37BUrX/aKzmFbt7clFSs6sXqHauqKWqdtLkF2KexO40H1YTX8z2lSgBBOAxLsvaklV8k4cBFK9snQXE9/DDaFt6Rr7iVZMldczhC0JNgTz+SHXT6CBHuX3e9SdB1Ua44oncaTWz7OBGLbCiK45wIDAQAB\n-----END PUBLIC KEY-----' +const eapiKey = 'e82ckenh8dichen8' const aesEncrypt = (buffer, mode, key, iv) => { const cipher = createCipheriv('aes-128-' + mode, key, iv) @@ -31,3 +32,15 @@ export const linuxapi = object => { eparams: aesEncrypt(Buffer.from(text), 'ecb', linuxapiKey, '').toString('hex').toUpperCase(), } } + +export const eapi = (url, object) => { + const text = typeof object === 'object' ? JSON.stringify(object) : object + const message = `nobody${url}use${text}md5forencrypt` + const digest = createHash('md5').update(message).digest('hex') + const data = `${url}-36cd479b6b5-${text}-36cd479b6b5-${digest}` + return { + params: aesEncrypt(Buffer.from(data), 'ecb', eapiKey, '') + .toString('hex') + .toUpperCase(), + } +}