made new client the default export

This commit is contained in:
June 2025-08-16 12:28:42 +12:00
parent b514655b5c
commit cf44f19310
Signed by: breadone
GPG Key ID: FDC19FE143200483
2 changed files with 10 additions and 10 deletions

View File

@ -7,16 +7,16 @@ import {
Collection Collection
} from './schema' } from './schema'
const client = new Pocketbase("http://localhost:4321") const raw_client = new Pocketbase("http://localhost:4321")
client.autoCancellation(false) raw_client.autoCancellation(false)
// Return a relative url for file instead of full path including localhost, which breaks external access // Return a relative url for file instead of full path including localhost, which breaks external access
client.files.getRelativeURL = (record: { [key: string]: any; }, filename: string, queryParams?: FileOptions | undefined) => { raw_client.files.getRelativeURL = (record: { [key: string]: any; }, filename: string, queryParams?: FileOptions | undefined) => {
const res = client.files.getURL(record, filename) const res = raw_client.files.getURL(record, filename)
return res.substring(21) return res.substring(21)
} }
export default client; export { raw_client };
class APIClient { class APIClient {
client: Pocketbase client: Pocketbase
@ -26,7 +26,7 @@ class APIClient {
this.client.autoCancellation(false) this.client.autoCancellation(false)
} }
async getRecipesPaginated(page: number, perPage: number = 30, options: RecordListOptions) { async getRecipesPage(page: number, perPage: number = 30, options: RecordListOptions) {
return await this.client.collection<Recipe>(Collection.RECIPES).getList(page, perPage, options) return await this.client.collection<Recipe>(Collection.RECIPES).getList(page, perPage, options)
} }
@ -38,5 +38,5 @@ class APIClient {
return await this.client.collection<Recipe>(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps' }) return await this.client.collection<Recipe>(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps' })
} }
} }
const client = new APIClient()
export const client2 = new APIClient() export default client;

View File

@ -1,5 +1,5 @@
--- ---
import client, { client2 } from "@/data/pocketbase"; import client from "@/data/pocketbase";
import SiteLayout from "@/layouts/base"; import SiteLayout from "@/layouts/base";
import ImageCarousel from "@/components/Detail/ImageCarousel"; import ImageCarousel from "@/components/Detail/ImageCarousel";
@ -9,7 +9,7 @@ import InfoView from "@/components/Detail/InfoView";
const { recipeid } = Astro.params; const { recipeid } = Astro.params;
const re = await client2.getRecipe(recipeid as string) const re = await client.getRecipe(recipeid as string)
--- ---
<SiteLayout> <SiteLayout>