ファイル
btrc-hub/frontend/src/lib/wiki.ts
T
2026-10-12 14:46:19 +09:00

33 行
845 B
TypeScript

import { isAxiosError } from 'axios'
import { apiGet } from '@/lib/api'
import type { WikiPage } from '@/types'
export const fetchWikiPages = async (
{ title }: { title?: string }): Promise<WikiPage[]> =>
await apiGet ('/wiki', { params: { title } })
export const fetchWikiPage = async (
id: string,
{ version }: { version?: string }): Promise<WikiPage> =>
await apiGet (`/wiki/${ id }`, { params: version ? { version } : { } })
export const fetchWikiPageByTitle = async (
title: string,
{ version }: { version?: string }): Promise<WikiPage | null> => {
try
{
return await apiGet (`/wiki/title/${ encodeURIComponent (title) }`, { params: { version } })
}
catch (error)
{
if (isAxiosError (error) && error.response?.status === 404)
return null
throw error
}
}