[PIE-28] Switch to type-safe API #12

Merged
breadone merged 9 commits from PIE-28-2 into main 2025-08-16 13:17:10 +12:00
2 changed files with 10 additions and 10 deletions
Showing only changes of commit cf44f19310 - Show all commits

View File

@ -7,16 +7,16 @@ import {
Collection
} from './schema'
const client = new Pocketbase("http://localhost:4321")
client.autoCancellation(false)
const raw_client = new Pocketbase("http://localhost:4321")
raw_client.autoCancellation(false)
// 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) => {
const res = client.files.getURL(record, filename)
raw_client.files.getRelativeURL = (record: { [key: string]: any; }, filename: string, queryParams?: FileOptions | undefined) => {
const res = raw_client.files.getURL(record, filename)
return res.substring(21)
}
export default client;
export { raw_client };
class APIClient {
client: Pocketbase
@ -26,7 +26,7 @@ class APIClient {
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)
}
@ -38,5 +38,5 @@ class APIClient {
return await this.client.collection<Recipe>(Collection.RECIPES).getOne(id, { expand: 'ingredients,tags,steps' })
}
}
export const client2 = new APIClient()
const client = 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 ImageCarousel from "@/components/Detail/ImageCarousel";
@ -9,7 +9,7 @@ import InfoView from "@/components/Detail/InfoView";
const { recipeid } = Astro.params;
const re = await client2.getRecipe(recipeid as string)
const re = await client.getRecipe(recipeid as string)
---
<SiteLayout>