mirror of
https://git.um-react.app/um/um-react.git
synced 2025-11-28 11:33:02 +00:00
feat: added option to search closest ekey
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { DecryptCommandOptions } from '~/decrypt-worker/types';
|
||||
import type { RootState } from '~/store';
|
||||
import { closestByLevenshtein } from '~/util/levenshtein';
|
||||
import { hasOwn } from '~/util/objects';
|
||||
|
||||
export const selectStagingQMCv2Settings = (state: RootState) => state.settings.staging.qmc2;
|
||||
@@ -7,9 +8,21 @@ export const selectFinalQMCv2Settings = (state: RootState) => state.settings.pro
|
||||
|
||||
export const selectDecryptOptionByFile = (state: RootState, name: string): DecryptCommandOptions => {
|
||||
const normalizedName = name.normalize();
|
||||
const qmc2Keys = selectFinalQMCv2Settings(state).keys;
|
||||
|
||||
let qmc2Key: string | undefined;
|
||||
const { keys: qmc2Keys, allowFuzzyNameSearch } = selectFinalQMCv2Settings(state);
|
||||
if (hasOwn(qmc2Keys, normalizedName)) {
|
||||
qmc2Key = qmc2Keys[normalizedName];
|
||||
} else if (allowFuzzyNameSearch) {
|
||||
const qmc2KeyStoreNames = Object.keys(qmc2Keys);
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
qmc2Key: hasOwn(qmc2Keys, normalizedName) ? qmc2Keys[normalizedName] : undefined,
|
||||
qmc2Key,
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user