diff --git a/app/scripts/page.tsx b/app/scripts/page.tsx index 24753ab..91ae00c 100644 --- a/app/scripts/page.tsx +++ b/app/scripts/page.tsx @@ -2,7 +2,7 @@ import ScriptItem from "@/components/Script"; import ScriptBrowser from "@/components/ScriptBrowser"; import Particles from "@/components/ui/particles"; -import { pb } from "@/lib/pocketbase"; +import { pb, pbBackup } from "@/lib/pocketbase"; import { Category } from "@/lib/types"; import { useEffect, useState } from "react"; @@ -13,17 +13,27 @@ export default function Page() { const fetchLinks = async () => { try { - setIsLoading(true) - const res = await pb.collection("categories").getFullList({ - expand: "items", - sort: "order", - requestKey: "desktop", - }); + setIsLoading(true); + let res; + try { + res = await pb.collection("categories").getFullList({ + expand: "items", + sort: "order", + requestKey: "desktop", + }); + } catch (error) { + console.error("Error fetching links from pb:", error); + res = await pbBackup.collection("categories").getFullList({ + expand: "items", + sort: "order", + requestKey: "desktop", + }); + } setLinks(res as unknown as Category[]); - setIsLoading(false) + setIsLoading(false); } catch (error) { console.error("Error fetching links:", error); - setIsLoading(false) + setIsLoading(false); } }; diff --git a/lib/pocketbase.ts b/lib/pocketbase.ts index 1f1ccbb..2bfa71a 100644 --- a/lib/pocketbase.ts +++ b/lib/pocketbase.ts @@ -1,6 +1,7 @@ import PocketBase from "pocketbase"; export const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL); +export const pbBackup = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL_BACKUP); export const getImageURL = (recordId: String, fileName: String) => { return `${process.env.NEXT_PUBLIC_POCKETBASE_URL}/${recordId}/${fileName}`;