mirror of
https://github.com/Lumither/nocturne.git
synced 2026-10-17 10:26:21 +00:00
20 lines
522 B
TypeScript
20 lines
522 B
TypeScript
import { Result } from '@/app/public/type/Result';
|
|
|
|
export default async function fetch_posts(url: string): Promise<Result<JSON[], Error>> {
|
|
const response = await fetch(`${ url }/posts/idx.json`);
|
|
if (!response.ok) {
|
|
return {
|
|
ok: false,
|
|
error: new Error(response.statusText)
|
|
};
|
|
}
|
|
const res = await response.json();
|
|
const posts = res['idx'].filter((posts: { type: string }) => posts.type === 'md');
|
|
return {
|
|
ok: true,
|
|
value: posts
|
|
};
|
|
}
|
|
|
|
|