mirror of
https://git.um-react.app/um/um-react.git
synced 2026-11-27 23:56:59 +00:00
- Updated import paths for Kugou and Kuwo instructions to reflect new directory structure. - Introduced new key management functionalities for Kugou, including key import and selection logic. - Added comprehensive instructions for both Kugou and Kuwo key handling across various platforms. - Implemented Redux selectors for managing staging and production keys for Kugou and Kuwo. - Enhanced documentation and tests for new features and key management processes.
233 lines
6.6 KiB
TypeScript
233 lines
6.6 KiB
TypeScript
import { createSlice } from '@reduxjs/toolkit';
|
|
import type { PayloadAction } from '@reduxjs/toolkit';
|
|
import {
|
|
type ProductionQMCv2Keys,
|
|
type StagingQMCv2Key,
|
|
qmc2ProductionToStaging,
|
|
qmc2StagingToProductionKey,
|
|
qmc2StagingToProductionValue,
|
|
} from '~/features/qmc/types';
|
|
import {
|
|
type ProductionKWMv2Keys,
|
|
type StagingKWMv2Key,
|
|
kwm2ProductionToStaging,
|
|
kwm2StagingToProductionKey,
|
|
kwm2StagingToProductionValue,
|
|
} from '~/features/kwm/types';
|
|
import {
|
|
type ProductionKugouKey,
|
|
type StagingKugouKey,
|
|
kugouProductionToStaging,
|
|
kugouStagingToProductionKey,
|
|
kugouStagingToProductionValue,
|
|
} from '~/features/kugou/types';
|
|
import { EMPTY_QTFM_SETTINGS, type ProductionQtfmSettings, type StagingQtfmSettings } from '~/features/qtfm/types';
|
|
import { productionKeyToStaging, stagingKeyToProduction } from './keyFormats';
|
|
import { createKeyListReducers } from './createKeyListReducers';
|
|
|
|
export interface BatchDownloadSettings {
|
|
directoryPicker: boolean;
|
|
rememberDirectory: boolean;
|
|
streamingZip: boolean;
|
|
blobZip: boolean;
|
|
}
|
|
|
|
export interface StagingSettings {
|
|
general: {
|
|
batchDownload: BatchDownloadSettings;
|
|
};
|
|
qmc2: {
|
|
keys: StagingQMCv2Key[];
|
|
allowFuzzyNameSearch: boolean;
|
|
};
|
|
kwm2: {
|
|
keys: StagingKWMv2Key[];
|
|
};
|
|
/**
|
|
* KuGou / KGG keys.
|
|
* UI route tab id is `kgg`; Redux / production persist key remains `kugou`.
|
|
*/
|
|
kugou: {
|
|
keys: StagingKugouKey[];
|
|
};
|
|
qtfm: StagingQtfmSettings;
|
|
}
|
|
|
|
export interface ProductionSettings {
|
|
general: {
|
|
batchDownload: BatchDownloadSettings;
|
|
};
|
|
qmc2: {
|
|
keys: ProductionQMCv2Keys; // { [fileName]: ekey }
|
|
allowFuzzyNameSearch: boolean;
|
|
};
|
|
kwm2: {
|
|
keys: ProductionKWMv2Keys; // { [`${rid}-${quality}`]: ekey }
|
|
};
|
|
/**
|
|
* KuGou / KGG keys.
|
|
* UI route tab id is `kgg`; localStorage production shape key remains `kugou` (do not rename).
|
|
*/
|
|
kugou: {
|
|
keys: ProductionKugouKey; // { [fileName]: ekey }
|
|
};
|
|
qtfm: ProductionQtfmSettings;
|
|
}
|
|
|
|
export const DEFAULT_BATCH_DOWNLOAD_SETTINGS: BatchDownloadSettings = {
|
|
directoryPicker: true,
|
|
rememberDirectory: true,
|
|
streamingZip: true,
|
|
blobZip: true,
|
|
};
|
|
|
|
export interface SettingsState {
|
|
dirty: boolean;
|
|
staging: StagingSettings;
|
|
production: ProductionSettings;
|
|
}
|
|
|
|
const initialState: SettingsState = {
|
|
dirty: false,
|
|
staging: {
|
|
general: { batchDownload: { ...DEFAULT_BATCH_DOWNLOAD_SETTINGS } },
|
|
qmc2: { allowFuzzyNameSearch: true, keys: [] },
|
|
kwm2: { keys: [] },
|
|
qtfm: { ...EMPTY_QTFM_SETTINGS },
|
|
kugou: { keys: [] },
|
|
},
|
|
production: {
|
|
general: { batchDownload: { ...DEFAULT_BATCH_DOWNLOAD_SETTINGS } },
|
|
qmc2: { allowFuzzyNameSearch: true, keys: {} },
|
|
kwm2: { keys: {} },
|
|
kugou: { keys: {} },
|
|
qtfm: { ...EMPTY_QTFM_SETTINGS },
|
|
},
|
|
};
|
|
|
|
export const stagingToProduction = (staging: StagingSettings): ProductionSettings => ({
|
|
general: {
|
|
batchDownload: { ...staging.general.batchDownload },
|
|
},
|
|
qmc2: {
|
|
keys: stagingKeyToProduction(staging.qmc2.keys, qmc2StagingToProductionKey, qmc2StagingToProductionValue),
|
|
allowFuzzyNameSearch: staging.qmc2.allowFuzzyNameSearch,
|
|
},
|
|
kwm2: {
|
|
keys: stagingKeyToProduction(staging.kwm2.keys, kwm2StagingToProductionKey, kwm2StagingToProductionValue),
|
|
},
|
|
kugou: {
|
|
keys: stagingKeyToProduction(staging.kugou.keys, kugouStagingToProductionKey, kugouStagingToProductionValue),
|
|
},
|
|
qtfm: staging.qtfm,
|
|
});
|
|
|
|
export const productionToStaging = (production: ProductionSettings): StagingSettings => ({
|
|
general: {
|
|
batchDownload: { ...production.general.batchDownload },
|
|
},
|
|
qmc2: {
|
|
keys: productionKeyToStaging(production.qmc2.keys, qmc2ProductionToStaging),
|
|
allowFuzzyNameSearch: production.qmc2.allowFuzzyNameSearch,
|
|
},
|
|
kwm2: {
|
|
keys: productionKeyToStaging(production.kwm2.keys, kwm2ProductionToStaging),
|
|
},
|
|
kugou: {
|
|
keys: productionKeyToStaging(production.kugou.keys, kugouProductionToStaging),
|
|
},
|
|
qtfm: production.qtfm,
|
|
});
|
|
|
|
const qmc2KeyList = createKeyListReducers('qmc2', () => ({ name: '', ekey: '' }));
|
|
const kwm2KeyList = createKeyListReducers('kwm2', () => ({ ekey: '', quality: '', rid: '' }));
|
|
const kugouKeyList = createKeyListReducers('kugou', () => ({ audioHash: '', ekey: '' }));
|
|
|
|
export const settingsSlice = createSlice({
|
|
name: 'settings',
|
|
initialState,
|
|
reducers: {
|
|
setProductionChanges: (_state, { payload }: PayloadAction<ProductionSettings>) => {
|
|
return {
|
|
dirty: false,
|
|
production: payload,
|
|
staging: productionToStaging(payload),
|
|
};
|
|
},
|
|
qmc2AddKey: qmc2KeyList.addKey,
|
|
qmc2ImportKeys: qmc2KeyList.importKeys,
|
|
qmc2DeleteKey: qmc2KeyList.deleteKey,
|
|
qmc2UpdateKey: qmc2KeyList.updateKey,
|
|
qmc2ClearKeys: qmc2KeyList.clearKeys,
|
|
qmc2AllowFuzzyNameSearch(state, { payload: { enable } }: PayloadAction<{ enable: boolean }>) {
|
|
state.staging.qmc2.allowFuzzyNameSearch = enable;
|
|
state.dirty = true;
|
|
},
|
|
kwm2AddKey: kwm2KeyList.addKey,
|
|
kwm2ImportKeys: kwm2KeyList.importKeys,
|
|
kwm2DeleteKey: kwm2KeyList.deleteKey,
|
|
kwm2UpdateKey: kwm2KeyList.updateKey,
|
|
kwm2ClearKeys: kwm2KeyList.clearKeys,
|
|
kugouAddKey: kugouKeyList.addKey,
|
|
kugouImportKeys: kugouKeyList.importKeys,
|
|
kugouDeleteKey: kugouKeyList.deleteKey,
|
|
kugouUpdateKey: kugouKeyList.updateKey,
|
|
kugouClearKeys: kugouKeyList.clearKeys,
|
|
qtfmAndroidUpdateKey(state, { payload: { deviceKey } }: PayloadAction<{ deviceKey: string }>) {
|
|
state.staging.qtfm.android = deviceKey;
|
|
state.dirty = true;
|
|
},
|
|
updateBatchDownloadSetting(
|
|
state,
|
|
{ payload: { key, value } }: PayloadAction<{ key: keyof BatchDownloadSettings; value: boolean }>,
|
|
) {
|
|
state.staging.general.batchDownload[key] = value;
|
|
state.dirty = true;
|
|
},
|
|
discardStagingChanges: (state) => {
|
|
state.dirty = false;
|
|
state.staging = productionToStaging(state.production);
|
|
},
|
|
/** Apply staging → production. Staging list row `id`s are kept (no productionToStaging round-trip). */
|
|
commitStagingChange: (state) => {
|
|
state.production = stagingToProduction(state.staging);
|
|
state.dirty = false;
|
|
},
|
|
resetConfig: () => {
|
|
return initialState;
|
|
},
|
|
},
|
|
});
|
|
|
|
export const {
|
|
setProductionChanges,
|
|
resetConfig,
|
|
|
|
qmc2AddKey,
|
|
qmc2UpdateKey,
|
|
qmc2DeleteKey,
|
|
qmc2ClearKeys,
|
|
qmc2ImportKeys,
|
|
qmc2AllowFuzzyNameSearch,
|
|
|
|
kwm2AddKey,
|
|
kwm2UpdateKey,
|
|
kwm2DeleteKey,
|
|
kwm2ClearKeys,
|
|
kwm2ImportKeys,
|
|
|
|
kugouAddKey,
|
|
kugouUpdateKey,
|
|
kugouDeleteKey,
|
|
kugouClearKeys,
|
|
kugouImportKeys,
|
|
|
|
qtfmAndroidUpdateKey,
|
|
updateBatchDownloadSetting,
|
|
|
|
commitStagingChange,
|
|
discardStagingChanges,
|
|
} = settingsSlice.actions;
|
|
|
|
export default settingsSlice.reducer;
|