Initial commit

This commit is contained in:
admin
2026-05-26 22:46:00 +02:00
commit 7e2c2ff89c
256 changed files with 51523 additions and 0 deletions
+22
View File
@@ -0,0 +1,22 @@
import "server-only";
import { cookies } from "next/headers";
import { isValidSort, SORT_COOKIE, type SortKey } from "./sort";
import { getAppSetting } from "./db/appSettings";
/**
* Resolution order: explicit URL ?sort= > server-persisted setting > cookie > default.
* The cookie is fallback only (e.g. before any setting is saved); the DB value
* survives anything short of deleting the database.
*/
export async function resolveSort(urlSort?: string): Promise<SortKey> {
if (isValidSort(urlSort)) return urlSort;
const stored = getAppSetting("defaultSort");
if (isValidSort(stored)) return stored;
const cookie = (await cookies()).get(SORT_COOKIE)?.value;
if (isValidSort(cookie)) return cookie;
return "newest";
}
export function getStoredDefaultSort(): SortKey {
return getAppSetting("defaultSort");
}