[PIE-28] Switch to type-safe API #12
@ -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;
|
@ -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>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user