47 lines
1.2 KiB
TypeScript
47 lines
1.2 KiB
TypeScript
|
|
import { API_URL, APP_URL } from "./site";
|
||
|
|
|
||
|
|
export interface SiteLinks {
|
||
|
|
bazaarUrl: string;
|
||
|
|
bazaarEnabled: boolean;
|
||
|
|
myketUrl: string;
|
||
|
|
myketEnabled: boolean;
|
||
|
|
directApkUrl: string;
|
||
|
|
directApkEnabled: boolean;
|
||
|
|
webPlayUrl: string;
|
||
|
|
iosPwaEnabled: boolean;
|
||
|
|
instagram: string;
|
||
|
|
telegram: string;
|
||
|
|
supportEmail: string;
|
||
|
|
supportPhone: string;
|
||
|
|
appVersion: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
// Safe defaults used until the API responds (or if it's unreachable).
|
||
|
|
export const FALLBACK_LINKS: SiteLinks = {
|
||
|
|
bazaarUrl: "",
|
||
|
|
bazaarEnabled: false,
|
||
|
|
myketUrl: "",
|
||
|
|
myketEnabled: false,
|
||
|
|
directApkUrl: "",
|
||
|
|
directApkEnabled: false,
|
||
|
|
webPlayUrl: APP_URL,
|
||
|
|
iosPwaEnabled: true,
|
||
|
|
instagram: "",
|
||
|
|
telegram: "",
|
||
|
|
supportEmail: "support@bargevasat.ir",
|
||
|
|
supportPhone: "",
|
||
|
|
appVersion: "",
|
||
|
|
};
|
||
|
|
|
||
|
|
/** Fetch admin-editable links at runtime (client-side). Falls back gracefully. */
|
||
|
|
export async function fetchLinks(): Promise<SiteLinks> {
|
||
|
|
try {
|
||
|
|
const res = await fetch(`${API_URL}/api/site/links`, { cache: "no-store" });
|
||
|
|
if (!res.ok) return FALLBACK_LINKS;
|
||
|
|
const data = (await res.json()) as Partial<SiteLinks>;
|
||
|
|
return { ...FALLBACK_LINKS, ...data };
|
||
|
|
} catch {
|
||
|
|
return FALLBACK_LINKS;
|
||
|
|
}
|
||
|
|
}
|