2023-02-15 01:19:54 +00:00
|
|
|
import { error } from '@sveltejs/kit';
|
2023-02-12 21:15:50 +00:00
|
|
|
import type { PageServerLoad } from './$types';
|
2023-02-15 01:19:54 +00:00
|
|
|
import { WALLABAG_MAX_PAGES } from '$env/static/private';
|
|
|
|
|
import type { Article } from '$lib/types/article';
|
2023-02-12 21:15:50 +00:00
|
|
|
|
2023-02-12 21:28:40 +00:00
|
|
|
export type ArticlePageLoad = {
|
|
|
|
|
articles: Article[];
|
|
|
|
|
currentPage: number;
|
|
|
|
|
totalPages: number;
|
|
|
|
|
limit: number;
|
|
|
|
|
totalArticles: number;
|
|
|
|
|
};
|
|
|
|
|
|
2023-02-12 21:15:50 +00:00
|
|
|
export const load: PageServerLoad = async ({ fetch, params }) => {
|
|
|
|
|
const { page } = params;
|
2023-02-15 01:19:54 +00:00
|
|
|
if (+page > WALLABAG_MAX_PAGES) {
|
|
|
|
|
throw error(404, {
|
|
|
|
|
message: 'Not found'
|
|
|
|
|
});
|
|
|
|
|
}
|
2023-02-12 21:15:50 +00:00
|
|
|
const resp = await fetch(`/api/articles?page=${page}`);
|
2023-02-12 21:28:40 +00:00
|
|
|
const { articles, currentPage, totalPages, limit, totalArticles }: ArticlePageLoad =
|
|
|
|
|
await resp.json();
|
2023-02-12 21:15:50 +00:00
|
|
|
return {
|
|
|
|
|
articles,
|
|
|
|
|
currentPage,
|
|
|
|
|
totalPages,
|
|
|
|
|
limit,
|
|
|
|
|
totalArticles
|
|
|
|
|
};
|
|
|
|
|
};
|