mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-07-09 03:04:20 -04:00
v5 api: Random sort query parameter cannot be reversed
This commit is contained in:
parent
2afccaa813
commit
67ea86a955
@ -177,11 +177,7 @@ export const movies = new Elysia({ prefix: "/movies", tags: ["movies"] })
|
|||||||
.where(and(filter, keysetPaginate({ table: shows, after, sort })))
|
.where(and(filter, keysetPaginate({ table: shows, after, sort })))
|
||||||
.orderBy(
|
.orderBy(
|
||||||
...(sort.random !== undefined
|
...(sort.random !== undefined
|
||||||
? [
|
? [sql`md5(${sort.random.seed} || ${shows.pk})`]
|
||||||
sort.random.desc
|
|
||||||
? sql`md5(${sort.random.seed} || ${shows.pk}) desc`
|
|
||||||
: sql`md5(${sort.random.seed} || ${shows.pk})`,
|
|
||||||
]
|
|
||||||
: []),
|
: []),
|
||||||
...sort.sort.map((x) =>
|
...sort.sort.map((x) =>
|
||||||
x.desc ? sql`${shows[x.key]} desc nulls last` : shows[x.key],
|
x.desc ? sql`${shows[x.key]} desc nulls last` : shows[x.key],
|
||||||
|
@ -9,7 +9,7 @@ export type Sort<
|
|||||||
remmapedKey?: keyof Remap;
|
remmapedKey?: keyof Remap;
|
||||||
desc: boolean;
|
desc: boolean;
|
||||||
}[];
|
}[];
|
||||||
random?: { desc: boolean; seed: number };
|
random?: { seed: number };
|
||||||
};
|
};
|
||||||
|
|
||||||
export type NonEmptyArray<T> = [T, ...T[]];
|
export type NonEmptyArray<T> = [T, ...T[]];
|
||||||
@ -33,14 +33,12 @@ export const Sort = <
|
|||||||
.Transform(
|
.Transform(
|
||||||
t.Array(
|
t.Array(
|
||||||
t.Union([
|
t.Union([
|
||||||
|
t.Literal("random"),
|
||||||
|
t.TemplateLiteral("random:${number}"),
|
||||||
t.UnionEnum([
|
t.UnionEnum([
|
||||||
...values,
|
...values,
|
||||||
...values.map((x: T[number]) => `-${x}` as const),
|
...values.map((x: T[number]) => `-${x}` as const),
|
||||||
]),
|
]),
|
||||||
t.Union([
|
|
||||||
t.TemplateLiteral("random:${number}"),
|
|
||||||
t.TemplateLiteral("-random:${number}"),
|
|
||||||
]),
|
|
||||||
]),
|
]),
|
||||||
{
|
{
|
||||||
// TODO: support explode: true (allow sort=slug,-createdAt). needs a pr to elysia
|
// TODO: support explode: true (allow sort=slug,-createdAt). needs a pr to elysia
|
||||||
@ -59,14 +57,12 @@ export const Sort = <
|
|||||||
if (key == "random") {
|
if (key == "random") {
|
||||||
random = {
|
random = {
|
||||||
seed: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
|
seed: Math.floor(Math.random() * Number.MAX_SAFE_INTEGER),
|
||||||
desc,
|
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
} else if (key.startsWith("random:")) {
|
} else if (key.startsWith("random:")) {
|
||||||
const strSeed = key.replace("random:", "");
|
const strSeed = key.replace("random:", "");
|
||||||
random = {
|
random = {
|
||||||
seed: parseInt(strSeed),
|
seed: parseInt(strSeed),
|
||||||
desc,
|
|
||||||
};
|
};
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user