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