mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-07-03 14:32:10 +08:00
添加更多同步功能的日志记录
This commit is contained in:
parent
3104ca4213
commit
42f88969fb
@ -2,6 +2,10 @@
|
||||
|
||||
- 新增歌曲评论显示,可在播放详情页进入。(与PC端一样,目前仅支持显示部分评论)
|
||||
|
||||
### 优化
|
||||
|
||||
- 添加更多同步功能的日志记录
|
||||
|
||||
### 修复
|
||||
|
||||
- 修复kg源的歌单链接无法打开的问题
|
||||
|
@ -136,7 +136,7 @@
|
||||
"setting_other_log_btn_clean": "Clear",
|
||||
"setting_other_log_btn_hide": "Close",
|
||||
"setting_other_log_btn_show": "View log",
|
||||
"setting_other_log_sync_error_log": "Record synchronization connection failure error log",
|
||||
"setting_other_log_sync_log": "Record synchronization log",
|
||||
"setting_other_log_tip_clean_success": "Log cleaning completed",
|
||||
"setting_other_log_tip_null": "The log is empty~",
|
||||
"setting_play": "Play",
|
||||
|
@ -136,7 +136,7 @@
|
||||
"setting_other_log_btn_clean": "清空",
|
||||
"setting_other_log_btn_hide": "关闭",
|
||||
"setting_other_log_btn_show": "查看日志",
|
||||
"setting_other_log_sync_error_log": "记录同步连接失败错误日志",
|
||||
"setting_other_log_sync_log": "记录同步日志",
|
||||
"setting_other_log_tip_clean_success": "日志清理完成",
|
||||
"setting_other_log_tip_null": "日志是空的哦~",
|
||||
"setting_play": "播放设置",
|
||||
|
@ -2,12 +2,13 @@ import { getSyncAuthKey, setSyncAuthKey } from '@/utils/tools'
|
||||
import { request, aesEncrypt, aesDecrypt } from './utils'
|
||||
import { getDeviceName } from '@/utils/utils'
|
||||
import { SYNC_CODE } from './config'
|
||||
import { log } from '@/utils/log'
|
||||
import log from '../log'
|
||||
|
||||
|
||||
const hello = (host, port) => request(`http://${host}:${port}/hello`)
|
||||
.then(text => text == SYNC_CODE.helloMsg)
|
||||
.catch(err => {
|
||||
log.error('[auth] hello', err.message)
|
||||
console.log(err)
|
||||
return false
|
||||
})
|
||||
@ -18,6 +19,7 @@ const getServerId = (host, port) => request(`http://${host}:${port}/id`)
|
||||
return text.replace(SYNC_CODE.idPrefix, '')
|
||||
})
|
||||
.catch(err => {
|
||||
log.error('[auth] getServerId', err.message)
|
||||
console.log(err)
|
||||
return false
|
||||
})
|
||||
@ -33,6 +35,7 @@ const codeAuth = async(host, port, serverId, authCode) => {
|
||||
try {
|
||||
msg = aesDecrypt(text, key, iv)
|
||||
} catch (err) {
|
||||
log.error('[auth] codeAuth decryptMsg error', err.message)
|
||||
throw new Error(SYNC_CODE.authFailed)
|
||||
}
|
||||
if (!msg) return Promise.reject(new Error(SYNC_CODE.authFailed))
|
||||
@ -49,6 +52,7 @@ const keyAuth = async(host, port, keyInfo) => {
|
||||
try {
|
||||
msg = aesDecrypt(text, keyInfo.key, keyInfo.iv)
|
||||
} catch (err) {
|
||||
log.error('[auth] keyAuth decryptMsg error', err.message)
|
||||
throw new Error(SYNC_CODE.authFailed)
|
||||
}
|
||||
if (msg != SYNC_CODE.helloMsg) return Promise.reject(new Error(SYNC_CODE.authFailed))
|
||||
|
@ -4,7 +4,7 @@ import * as modules from '../modules'
|
||||
import { action as commonAction } from '@/store/modules/common'
|
||||
import { getStore } from '@/store'
|
||||
import syncList from './syncList'
|
||||
import { log } from '@/utils/log'
|
||||
import log from '../log'
|
||||
|
||||
const handleConnection = (socket) => {
|
||||
for (const module of Object.values(modules)) {
|
||||
@ -26,16 +26,23 @@ export const connect = (host, port, keyInfo) => {
|
||||
|
||||
socket.on('connect', async() => {
|
||||
console.log('connect')
|
||||
log.info('connect')
|
||||
const store = getStore()
|
||||
global.syncKeyInfo = keyInfo
|
||||
try {
|
||||
await syncList(socket)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
log.error(err.stack)
|
||||
log.r_error(err.stack)
|
||||
store.dispatch(commonAction.setSyncStatus({
|
||||
status: false,
|
||||
message: err.message,
|
||||
}))
|
||||
return
|
||||
}
|
||||
log.info('sync list success')
|
||||
handleConnection(socket)
|
||||
log.info('register list sync service success')
|
||||
store.dispatch(commonAction.setSyncStatus({
|
||||
status: true,
|
||||
message: '',
|
||||
@ -43,7 +50,7 @@ export const connect = (host, port, keyInfo) => {
|
||||
})
|
||||
socket.on('connect_error', (err) => {
|
||||
console.log(err.message)
|
||||
if (global.isEnableSyncLog) log.error(err.stack)
|
||||
log.error('connect error: ', err.stack)
|
||||
const store = getStore()
|
||||
store.dispatch(commonAction.setSyncStatus({
|
||||
status: false,
|
||||
@ -56,6 +63,7 @@ export const connect = (host, port, keyInfo) => {
|
||||
})
|
||||
socket.on('disconnect', (reason) => {
|
||||
console.log('disconnect', reason)
|
||||
log.warn('disconnect: ', reason)
|
||||
const store = getStore()
|
||||
store.dispatch(commonAction.setSyncStatus({
|
||||
status: false,
|
||||
@ -91,6 +99,7 @@ export const connect = (host, port, keyInfo) => {
|
||||
|
||||
export const disconnect = async() => {
|
||||
if (!socket) return
|
||||
log.info('disconnecting...')
|
||||
await socket.close()
|
||||
socket = null
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import { getSyncHost } from '@/utils/tools'
|
||||
import { action as commonAction } from '@/store/modules/common'
|
||||
import { getStore } from '@/store'
|
||||
import { SYNC_CODE } from './config'
|
||||
import { log } from '@/utils/log'
|
||||
import log from '../log'
|
||||
|
||||
const handleConnect = async authCode => {
|
||||
const hostInfo = await getSyncHost()
|
||||
@ -41,7 +41,7 @@ const connect = authCode => {
|
||||
case SYNC_CODE.missingAuthCode:
|
||||
break
|
||||
default:
|
||||
log.warn(err.message)
|
||||
log.r_warn(err.message)
|
||||
break
|
||||
}
|
||||
|
||||
@ -50,6 +50,7 @@ const connect = authCode => {
|
||||
}
|
||||
|
||||
const disconnect = (isResetStatus = true) => handleDisconnect().then(() => {
|
||||
log.info('disconnect...')
|
||||
if (isResetStatus) {
|
||||
const store = getStore()
|
||||
store.dispatch(commonAction.setSyncStatus({
|
||||
@ -59,6 +60,7 @@ const disconnect = (isResetStatus = true) => handleDisconnect().then(() => {
|
||||
}
|
||||
}).catch(err => {
|
||||
const store = getStore()
|
||||
log.error('disconnect error: ' + err.message)
|
||||
store.dispatch(commonAction.setSyncStatus({
|
||||
message: err.message,
|
||||
}))
|
||||
|
@ -4,6 +4,8 @@ import { action as listAction } from '@/store/modules/list'
|
||||
import { toast } from '@/utils/tools'
|
||||
|
||||
import { decryptMsg, encryptMsg } from './utils'
|
||||
import log from '../log'
|
||||
|
||||
let socket
|
||||
let syncAction
|
||||
|
||||
@ -31,7 +33,9 @@ const sendListData = type => {
|
||||
socket.emit('list:sync', encryptMsg(JSON.stringify({
|
||||
action: 'getData',
|
||||
data: listData,
|
||||
})))
|
||||
})), () => {
|
||||
log.info('[syncList]send data success')
|
||||
})
|
||||
// console.log('sendListData', 'encryptMsg')
|
||||
}
|
||||
|
||||
@ -46,13 +50,17 @@ const handleListSync = enMsg => {
|
||||
// console.log('handleListSync', action)
|
||||
switch (action) {
|
||||
case 'getData':
|
||||
log.info('[syncList]get data')
|
||||
sendListData(data)
|
||||
break
|
||||
case 'setData':
|
||||
log.info('[syncList]set data')
|
||||
saveList(data)
|
||||
log.info('[syncList]set data success')
|
||||
break
|
||||
case 'finished':
|
||||
if (!syncAction) return
|
||||
log.info('[syncList]finished')
|
||||
syncAction[0]()
|
||||
syncAction = null
|
||||
toast('Sync successfully')
|
||||
|
22
src/plugins/sync/log.js
Normal file
22
src/plugins/sync/log.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { log as writeLog } from '@/utils/log'
|
||||
|
||||
export default {
|
||||
r_info(...args) {
|
||||
writeLog.info(...args)
|
||||
},
|
||||
r_warn(...args) {
|
||||
writeLog.warn(...args)
|
||||
},
|
||||
r_error(...args) {
|
||||
writeLog.error(...args)
|
||||
},
|
||||
info(...args) {
|
||||
if (global.isEnableSyncLog) writeLog.info(...args)
|
||||
},
|
||||
warn(...args) {
|
||||
if (global.isEnableSyncLog) writeLog.warn(...args)
|
||||
},
|
||||
error(...args) {
|
||||
if (global.isEnableSyncLog) writeLog.error(...args)
|
||||
},
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
import { getStore } from '@/store'
|
||||
import { decryptMsg } from '../../client/utils'
|
||||
import log from '../../log'
|
||||
import {
|
||||
setList,
|
||||
listAdd,
|
||||
@ -27,6 +28,7 @@ const handleListAction = enMsg => {
|
||||
const { action, data } = JSON.parse(decryptMsg(enMsg))
|
||||
if (typeof data == 'object') data.isSync = true
|
||||
console.log(action)
|
||||
log.info(action)
|
||||
|
||||
switch (action) {
|
||||
// case 'init_list':
|
||||
|
@ -64,7 +64,7 @@ export default memo(() => {
|
||||
<>
|
||||
<SubTitle title={t('setting_other_log')}>
|
||||
<View style={{ paddingTop: 10, paddingBottom: 15, marginLeft: -25 }}>
|
||||
<CheckBoxItem check={isEnableSyncErrorLog} label={t('setting_other_log_sync_error_log')} onChange={handleSetEnableSyncErrorLog} />
|
||||
<CheckBoxItem check={isEnableSyncErrorLog} label={t('setting_other_log_sync_log')} onChange={handleSetEnableSyncErrorLog} />
|
||||
</View>
|
||||
<View style={styles.btn}>
|
||||
<Button onPress={openLogModal}>{t('setting_other_log_btn_show')}</Button>
|
||||
|
@ -1,11 +1,11 @@
|
||||
import React from 'react'
|
||||
import PlayerPortrait from './PlayerPortrait'
|
||||
|
||||
const playNextModes = [
|
||||
'listLoop',
|
||||
'random',
|
||||
'list',
|
||||
'singleLoop',
|
||||
]
|
||||
// const playNextModes = [
|
||||
// 'listLoop',
|
||||
// 'random',
|
||||
// 'list',
|
||||
// 'singleLoop',
|
||||
// ]
|
||||
|
||||
export default () => <PlayerPortrait playNextModes={playNextModes} />
|
||||
export default () => <PlayerPortrait />
|
||||
|
@ -5,7 +5,7 @@ import { useGetter, useDispatch } from '@/store'
|
||||
import { STATUS } from '@/store/modules/player'
|
||||
|
||||
|
||||
export default ({ playNextModes }) => {
|
||||
export default () => {
|
||||
const playStatus = useGetter('player', 'status')
|
||||
const playNext = useDispatch('player', 'playNext')
|
||||
const playPrev = useDispatch('player', 'playPrev')
|
||||
|
@ -10,7 +10,7 @@ import PlayInfo from './components/PlayInfo'
|
||||
import ControlBtn from './components/ControlBtn'
|
||||
|
||||
|
||||
export default memo(({ playNextModes }) => {
|
||||
export default memo(() => {
|
||||
// const { onLayout, ...layout } = useLayout()
|
||||
const { keyboardShown } = useKeyboard()
|
||||
const theme = useGetter('common', 'theme')
|
||||
@ -28,10 +28,10 @@ export default memo(({ playNextModes }) => {
|
||||
{(componentIds.playDetail || componentIds.songlistDetail) ? null : <PlayInfo />}
|
||||
</View>
|
||||
<View style={styles.right}>
|
||||
<ControlBtn playNextModes={playNextModes} />
|
||||
<ControlBtn />
|
||||
</View>
|
||||
</View>
|
||||
), [theme, componentIds, playNextModes])
|
||||
), [theme, componentIds])
|
||||
|
||||
// console.log(layout)
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { useGetter, useDispatch } from '@/store'
|
||||
import { STATUS } from '@/store/modules/player'
|
||||
|
||||
|
||||
export default ({ playNextModes }) => {
|
||||
export default () => {
|
||||
const playStatus = useGetter('player', 'status')
|
||||
const playNext = useDispatch('player', 'playNext')
|
||||
const playPrev = useDispatch('player', 'playPrev')
|
||||
|
@ -10,7 +10,7 @@ import PlayInfo from './components/PlayInfo'
|
||||
import ControlBtn from './components/ControlBtn'
|
||||
|
||||
|
||||
export default memo(({ playNextModes }) => {
|
||||
export default memo(() => {
|
||||
// const { onLayout, ...layout } = useLayout()
|
||||
const { keyboardShown } = useKeyboard()
|
||||
const theme = useGetter('common', 'theme')
|
||||
@ -28,10 +28,10 @@ export default memo(({ playNextModes }) => {
|
||||
{componentIds.playDetail ? null : <PlayInfo />}
|
||||
</View>
|
||||
<View style={styles.right}>
|
||||
<ControlBtn playNextModes={playNextModes} />
|
||||
<ControlBtn />
|
||||
</View>
|
||||
</View>
|
||||
), [theme, componentIds, playNextModes])
|
||||
), [theme, componentIds])
|
||||
|
||||
// console.log(layout)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user