Новые изменения в коде проекта
This commit is contained in:
parent
0777fc201f
commit
aef12e853d
12 changed files with 159 additions and 15 deletions
|
|
@ -1,9 +1,11 @@
|
|||
import type { APIRoute } from 'astro';
|
||||
import PocketBase from 'pocketbase';
|
||||
|
||||
const PB_URL = import.meta.env.POCKETBASE_URL || 'http://127.0.0.1:8090';
|
||||
|
||||
export const GET: APIRoute = async ({ url }) => {
|
||||
try {
|
||||
const pb = new PocketBase(import.meta.env.POCKETBASE_URL);
|
||||
const pb = new PocketBase(PB_URL);
|
||||
|
||||
const page = parseInt(url.searchParams.get('page') || '1');
|
||||
const perPage = parseInt(url.searchParams.get('per_page') || '10');
|
||||
|
|
@ -25,6 +27,15 @@ export const GET: APIRoute = async ({ url }) => {
|
|||
sort: '-date',
|
||||
});
|
||||
|
||||
const getImageUrl = (post: any) => {
|
||||
if (!post.image) return null;
|
||||
const fileUrl = pb.files.getUrl(post, post.image);
|
||||
if (fileUrl.startsWith('/')) {
|
||||
return `${PB_URL}${fileUrl}`;
|
||||
}
|
||||
return fileUrl;
|
||||
};
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
posts: result.items.map(post => ({
|
||||
id: post.id,
|
||||
|
|
@ -36,7 +47,7 @@ export const GET: APIRoute = async ({ url }) => {
|
|||
categoryColor: post.categoryColor,
|
||||
date: post.date,
|
||||
readTime: post.readTime,
|
||||
imageUrl: post.imageUrl,
|
||||
image: getImageUrl(post),
|
||||
})),
|
||||
total: result.totalItems,
|
||||
page: result.pageInfo.page,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue