重构数据同步功能,新增客户端模式
This commit is contained in:
@@ -75,3 +75,24 @@ export const DOWNLOAD_STATUS = {
|
||||
} as const
|
||||
|
||||
export const QUALITYS = ['flac24bit', 'flac', 'wav', 'ape', '320k', '192k', '128k'] as const
|
||||
|
||||
export const SYNC_CODE = {
|
||||
helloMsg: 'Hello~::^-^::~v3~',
|
||||
idPrefix: 'OjppZDo6',
|
||||
authMsg: 'lx-music auth::',
|
||||
authFailed: 'Auth failed',
|
||||
missingAuthCode: 'Missing auth code',
|
||||
getServiceIdFailed: 'Get service id failed',
|
||||
connectServiceFailed: 'Connect service failed',
|
||||
connecting: 'Connecting...',
|
||||
unknownServiceAddress: 'Unknown service address',
|
||||
msgBlockedIp: 'Blocked IP',
|
||||
msgConnect: 'lx-music connect',
|
||||
msgAuthFailed: 'Auth failed',
|
||||
} as const
|
||||
|
||||
export const SYNC_CLOSE_CODE = {
|
||||
normal: 1000,
|
||||
failed: 4100,
|
||||
} as const
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { join } from 'path'
|
||||
import { homedir } from 'os'
|
||||
|
||||
const defaultSetting: LX.AppSetting = {
|
||||
version: '2.0.0',
|
||||
version: '2.1.0',
|
||||
|
||||
'common.windowSizeId': 3,
|
||||
'common.fontSize': 16,
|
||||
@@ -108,8 +108,11 @@ const defaultSetting: LX.AppSetting = {
|
||||
// 'tray.isToTray': false,
|
||||
'tray.themeId': 0,
|
||||
|
||||
'sync.mode': 'server',
|
||||
'sync.enable': false,
|
||||
'sync.port': '23332',
|
||||
'sync.server.port': '23332',
|
||||
'sync.server.maxSsnapshotNum': 5,
|
||||
'sync.client.host': '',
|
||||
|
||||
'theme.id': 'blue_plus',
|
||||
// 'theme.id': 'green',
|
||||
|
||||
Vendored
+16
-1
@@ -499,6 +499,11 @@ declare global {
|
||||
*/
|
||||
'tray.themeId': number
|
||||
|
||||
/**
|
||||
* 同步服务模式
|
||||
*/
|
||||
'sync.mode': 'server' | 'client'
|
||||
|
||||
/**
|
||||
* 是否启用同步服务
|
||||
*/
|
||||
@@ -507,7 +512,17 @@ declare global {
|
||||
/**
|
||||
* 同步服务端口号
|
||||
*/
|
||||
'sync.port': '23332' | string
|
||||
'sync.server.port': '23332' | string
|
||||
|
||||
/**
|
||||
* 最大备份快照数
|
||||
*/
|
||||
'sync.server.maxSsnapshotNum': number
|
||||
|
||||
/**
|
||||
* 同步服务地址
|
||||
*/
|
||||
'sync.client.host': string
|
||||
|
||||
/**
|
||||
* 是否在离开搜索界面时自动清空搜索框
|
||||
|
||||
Vendored
+48
-10
@@ -1,10 +1,15 @@
|
||||
declare namespace LX {
|
||||
namespace Sync {
|
||||
|
||||
interface Enable {
|
||||
interface EnableServer {
|
||||
enable: boolean
|
||||
port: string
|
||||
}
|
||||
interface EnableClient {
|
||||
enable: boolean
|
||||
host: string
|
||||
authCode?: string
|
||||
}
|
||||
|
||||
interface SyncActionBase <A> {
|
||||
action: A
|
||||
@@ -14,14 +19,17 @@ declare namespace LX {
|
||||
}
|
||||
type SyncAction<A, D = undefined> = D extends undefined ? SyncActionBase<A> : SyncActionData<A, D>
|
||||
|
||||
type SyncMainWindowActions = SyncAction<'select_mode', KeyInfo>
|
||||
type SyncMainWindowActions = SyncAction<'select_mode', string>
|
||||
| SyncAction<'close_select_mode'>
|
||||
| SyncAction<'status', Status>
|
||||
| SyncAction<'client_status', ClientStatus>
|
||||
| SyncAction<'server_status', ServerStatus>
|
||||
|
||||
type SyncServiceActions = SyncAction<'select_mode', Mode>
|
||||
| SyncAction<'get_status'>
|
||||
| SyncAction<'get_server_status'>
|
||||
| SyncAction<'get_client_status'>
|
||||
| SyncAction<'generate_code'>
|
||||
| SyncAction<'enable', Enable>
|
||||
| SyncAction<'enable_server', EnableServer>
|
||||
| SyncAction<'enable_client', EnableClient>
|
||||
|
||||
type ActionList = SyncAction<'list_data_overwrite', LX.List.ListActionDataOverwrite>
|
||||
| SyncAction<'list_create', LX.List.ListActionAdd>
|
||||
@@ -36,25 +44,55 @@ declare namespace LX {
|
||||
| SyncAction<'list_music_overwrite', LX.List.ListActionMusicOverwrite>
|
||||
| SyncAction<'list_music_clear', LX.List.ListActionMusicClear>
|
||||
|
||||
type ActionSync = SyncAction<'list:sync:list_sync_get_md5', string>
|
||||
| SyncAction<'list:sync:list_sync_get_list_data', ListData>
|
||||
| SyncAction<'list:sync:list_sync_get_sync_mode', Mode>
|
||||
| SyncAction<'list:sync:action', ActionList>
|
||||
// | SyncAction<'finished'>
|
||||
|
||||
type ActionSyncType = Actions<ActionSync>
|
||||
|
||||
type ActionSyncSend = SyncAction<'list:sync:list_sync_get_md5'>
|
||||
| SyncAction<'list:sync:list_sync_get_list_data'>
|
||||
| SyncAction<'list:sync:list_sync_get_sync_mode'>
|
||||
| SyncAction<'list:sync:list_sync_set_data', LX.Sync.ListData>
|
||||
| SyncAction<'list:sync:action', ActionList>
|
||||
| SyncAction<'list:sync:finished'>
|
||||
|
||||
type ActionSyncSendType = Actions<ActionSyncSend>
|
||||
|
||||
interface List {
|
||||
action: string
|
||||
data: any
|
||||
}
|
||||
|
||||
interface Status {
|
||||
interface ServerStatus {
|
||||
status: boolean
|
||||
message: string
|
||||
address: string[]
|
||||
code: string
|
||||
devices: KeyInfo[]
|
||||
devices: ServerKeyInfo[]
|
||||
}
|
||||
|
||||
interface KeyInfo {
|
||||
interface ClientStatus {
|
||||
status: boolean
|
||||
message: string
|
||||
address: string[]
|
||||
}
|
||||
|
||||
interface ClientKeyInfo {
|
||||
clientId: string
|
||||
key: string
|
||||
serverName: string
|
||||
}
|
||||
|
||||
interface ServerKeyInfo {
|
||||
clientId: string
|
||||
key: string
|
||||
deviceName: string
|
||||
connectionTime?: number
|
||||
lastSyncDate?: number
|
||||
snapshotKey: string
|
||||
isMobile: boolean
|
||||
}
|
||||
|
||||
type ListData = Omit<LX.List.ListDataFull, 'tempList'>
|
||||
@@ -65,7 +103,7 @@ declare namespace LX {
|
||||
| 'overwrite_remote_local'
|
||||
| 'overwrite_local_remote_full'
|
||||
| 'overwrite_remote_local_full'
|
||||
| 'none'
|
||||
// | 'none'
|
||||
| 'cancel'
|
||||
|
||||
}
|
||||
|
||||
Vendored
+5
@@ -5,3 +5,8 @@ type DeepPartial<T> = {
|
||||
}
|
||||
|
||||
type Modify<T, R> = Omit<T, keyof R> & R
|
||||
|
||||
// type UndefinedOrNever = undefined
|
||||
type Actions<T extends { action: string, data?: any }> = {
|
||||
[U in T as U['action']]: 'data' extends keyof U ? U['data'] : undefined
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ const oldThemeMap = {
|
||||
export default (setting: any): Partial<LX.AppSetting> => {
|
||||
setting = { ...setting }
|
||||
|
||||
// 迁移 v2 之前的配置
|
||||
// 迁移 v2.0.0 之前的配置
|
||||
if (compareVer(setting.version, '2.0.0') < 0) {
|
||||
// 迁移列表滚动位置设置 ~0.18.3
|
||||
if (setting.list?.scroll) {
|
||||
@@ -133,7 +133,16 @@ export default (setting: any): Partial<LX.AppSetting> => {
|
||||
|
||||
setting['odc.isAutoClearSearchInput'] = setting.odc?.isAutoClearSearchInput
|
||||
setting['odc.isAutoClearSearchList'] = setting.odc?.isAutoClearSearchList
|
||||
|
||||
setting.version = '2.0.0'
|
||||
}
|
||||
|
||||
// 迁移 v2.2.0 之前的设置数据
|
||||
if (compareVer(setting.version, '2.1.0') < 0) {
|
||||
setting['sync.erver.port'] = setting['sync.port']
|
||||
setting.version = '2.1.0'
|
||||
}
|
||||
|
||||
|
||||
return setting
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user