mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
feat: add KWMv2 support
This commit is contained in:
@@ -1,30 +1,47 @@
|
||||
import type { DecryptCommandOptions } from '~/decrypt-worker/types';
|
||||
import { parseKuwoHeader } from '~/crypto/pasreKuwo';
|
||||
import type { RootState } from '~/store';
|
||||
import { closestByLevenshtein } from '~/util/levenshtein';
|
||||
import { hasOwn } from '~/util/objects';
|
||||
import { kwm2StagingToProductionKey } from './keyFormats';
|
||||
|
||||
export const selectStagingQMCv2Settings = (state: RootState) => state.settings.staging.qmc2;
|
||||
export const selectFinalQMCv2Settings = (state: RootState) => state.settings.production.qmc2;
|
||||
|
||||
export const selectStagingKWMv2Keys = (state: RootState) => state.settings.staging.kwm2.keys;
|
||||
export const selectFinalKWMv2Keys = (state: RootState) => state.settings.production.kwm2.keys;
|
||||
|
||||
export const selectDecryptOptionByFile = (state: RootState, name: string): DecryptCommandOptions => {
|
||||
export const selectQMCv2KeyByFileName = (state: RootState, name: string): string | undefined => {
|
||||
const normalizedName = name.normalize();
|
||||
|
||||
let qmc2Key: string | undefined;
|
||||
const { keys: qmc2Keys, allowFuzzyNameSearch } = selectFinalQMCv2Settings(state);
|
||||
if (hasOwn(qmc2Keys, normalizedName)) {
|
||||
qmc2Key = qmc2Keys[normalizedName];
|
||||
let ekey: string | undefined;
|
||||
const { keys, allowFuzzyNameSearch } = selectFinalQMCv2Settings(state);
|
||||
if (hasOwn(keys, normalizedName)) {
|
||||
ekey = keys[normalizedName];
|
||||
} else if (allowFuzzyNameSearch) {
|
||||
const qmc2KeyStoreNames = Object.keys(qmc2Keys);
|
||||
const qmc2KeyStoreNames = Object.keys(keys);
|
||||
if (qmc2KeyStoreNames.length > 0) {
|
||||
const closestName = closestByLevenshtein(normalizedName, qmc2KeyStoreNames);
|
||||
console.debug('qmc2: key db could not find %o, using closest %o instead.', normalizedName, closestName);
|
||||
qmc2Key = qmc2Keys[closestName];
|
||||
ekey = keys[closestName];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
qmc2Key,
|
||||
};
|
||||
return ekey;
|
||||
};
|
||||
|
||||
export const selectKWMv2Key = (state: RootState, headerView: DataView): string | undefined => {
|
||||
const hdr = parseKuwoHeader(headerView);
|
||||
if (!hdr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const keys = selectFinalKWMv2Keys(state);
|
||||
const lookupKey = kwm2StagingToProductionKey({ id: '', ekey: '', quality: hdr.quality, rid: hdr.rid });
|
||||
|
||||
let ekey: string | undefined;
|
||||
if (hasOwn(keys, lookupKey)) {
|
||||
ekey = keys[lookupKey];
|
||||
}
|
||||
|
||||
return ekey;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user