40 行
1016 B
TypeScript
40 行
1016 B
TypeScript
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<WikiPage[]> =>
|
|
await apiGet ('/wiki', { locale, params: { title } })
|
|
|
|
|
|
export const fetchWikiPage = async (
|
|
id: string,
|
|
{ version }: { version?: string },
|
|
locale: LocaleCode = 'ja',
|
|
): Promise<WikiPage> =>
|
|
await apiGet (`/wiki/${ id }`, { locale, params: version ? { version } : { } })
|
|
|
|
|
|
export const fetchWikiPageByTitle = async (
|
|
title: string,
|
|
{ version }: { version?: string },
|
|
locale: LocaleCode = 'ja',
|
|
): Promise<WikiPage | null> => {
|
|
try
|
|
{
|
|
return await apiGet (`/wiki/title/${ encodeURIComponent (title) }`, { locale, params: { version } })
|
|
}
|
|
catch (error)
|
|
{
|
|
if (isAxiosError (error) && error.response?.status === 404)
|
|
return null
|
|
throw error
|
|
}
|
|
}
|