From 1daaf067d9102a37a3dd9cc878e57f8267c8ef04 Mon Sep 17 00:00:00 2001 From: Tola Leng Date: Tue, 17 Jun 2025 21:50:34 +0800 Subject: [PATCH] Refactor: Split settings API into modules --- application/src/api/settings/types.ts | 25 +++++++++++++++++++++++++ application/src/api/settings/utils.ts | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 application/src/api/settings/types.ts create mode 100644 application/src/api/settings/utils.ts diff --git a/application/src/api/settings/types.ts b/application/src/api/settings/types.ts new file mode 100644 index 0000000..01ef5f1 --- /dev/null +++ b/application/src/api/settings/types.ts @@ -0,0 +1,25 @@ + +export interface SettingsApiRequest { + action: string; + data?: any; +} + +export interface SettingsApiResponse { + status: number; + json: { + success: boolean; + data?: any; + message?: string; + }; +} + +export interface SmtpSettings { + enabled?: boolean; + host?: string; + port?: number; + username?: string; + password?: string; + authMethod?: string; + tls?: boolean; + localName?: string; +} \ No newline at end of file diff --git a/application/src/api/settings/utils.ts b/application/src/api/settings/utils.ts new file mode 100644 index 0000000..0039a1b --- /dev/null +++ b/application/src/api/settings/utils.ts @@ -0,0 +1,24 @@ + +import { pb, getCurrentEndpoint } from '@/lib/pocketbase'; + +export const getAuthHeaders = (): Record => { + const authToken = pb.authStore.token; + const headers: Record = { + 'Content-Type': 'application/json', + }; + + if (authToken) { + headers['Authorization'] = `Bearer ${authToken}`; + } + + return headers; +}; + +export const getBaseUrl = (): string => { + return getCurrentEndpoint(); +}; + +export const validateEmail = (email: string): boolean => { + const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; + return emailRegex.test(email); +}; \ No newline at end of file