mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-05-31 20:24:27 -04:00
Cleanup sort parsing
This commit is contained in:
parent
86d37514dc
commit
8b7e109be3
@ -49,36 +49,20 @@ export const Sort = <
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
.Decode((sort): Sort<T, Remap> => {
|
.Decode((sort): Sort<T, Remap> => {
|
||||||
const sortItems: Sort<T, Remap>["sort"] = [];
|
const random = sort.find((x) => x.startsWith("random"));
|
||||||
let random: Sort<T, Remap>["random"] = undefined;
|
if (random) {
|
||||||
for (const x of sort) {
|
const seed = random.includes(":")
|
||||||
const desc = x[0] === "-";
|
? Number.parseInt(random.substring("random:".length))
|
||||||
const key = (desc ? x.substring(1) : x) as T[number];
|
: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER);
|
||||||
if (key == "random") {
|
return { random: { seed }, sort: [] };
|
||||||
random = {
|
|
||||||
seed: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
|
|
||||||
};
|
|
||||||
continue;
|
|
||||||
} else if (key.startsWith("random:")) {
|
|
||||||
const strSeed = key.replace("random:", "");
|
|
||||||
random = {
|
|
||||||
seed: parseInt(strSeed),
|
|
||||||
};
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key in remap) {
|
|
||||||
sortItems.push({ key: remap[key]!, remmapedKey: key, desc });
|
|
||||||
} else {
|
|
||||||
sortItems.push({
|
|
||||||
key: key as Exclude<typeof key, keyof Remap>,
|
|
||||||
desc,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
sort: sortItems,
|
sort: sort.map((x) => {
|
||||||
random,
|
const desc = x[0] === "-";
|
||||||
|
const key = (desc ? x.substring(1) : x) as T[number];
|
||||||
|
if (key in remap) return { key: remap[key]!, remmapedKey: key, desc };
|
||||||
|
return { key: key as Exclude<typeof key, keyof Remap>, desc };
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
.Encode(() => {
|
.Encode(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user