build ok,

This commit is contained in:
louiscklaw
2025-04-14 09:26:24 +08:00
commit 6c931c1fe8
770 changed files with 63959 additions and 0 deletions

View File

@@ -0,0 +1,13 @@
import type { Settings } from '@/types/settings';
import { config } from '@/config';
export function applyDefaultSettings(settings: Partial<Settings>): Settings {
return {
colorScheme: config.site.colorScheme,
primaryColor: config.site.primaryColor,
direction: 'ltr',
navColor: 'evident',
layout: 'vertical',
...settings,
};
}

View File

@@ -0,0 +1,29 @@
'use server';
import { cookies } from 'next/headers';
import type { Settings } from '@/types/settings';
import { logger } from '@/lib/default-logger';
/**
* Retrieve the settings from client's cookies.
* This should be used in Server Components.
*/
export async function getSettings(): Promise<Partial<Settings>> {
const cookieStore = cookies();
const settingsStr = cookieStore.get('app.settings')?.value;
let settings: Partial<Settings>;
if (settingsStr) {
try {
settings = JSON.parse(settingsStr) as Partial<Settings>;
} catch {
logger.error('Unable to parse the settings');
}
}
settings ||= {};
return settings;
}

View File

@@ -0,0 +1,16 @@
'use server';
import { cookies } from 'next/headers';
import type { Settings } from '@/types/settings';
/**
* Store settings (partial patch) in client's cookies.
* This should be used as Server Action.
*
* To remove a specific key, set its value to `null`.
*/
export async function setSettings(settings: Partial<Settings>): Promise<void> {
const cookieStore = cookies();
cookieStore.set('app.settings', JSON.stringify(settings));
}