| |
| |
| |
| |
| |
|
|
| const API_BASE = ''; |
|
|
| export interface CNTopic { |
| id: string; |
| chapter_no: number; |
| chapter_name: string; |
| subtitle: string; |
| level: string; |
| topics: string[]; |
| } |
|
|
| export interface CNTopicContent extends CNTopic { |
| content: any; |
| } |
|
|
| |
| |
| |
| export async function fetchCNTopics(): Promise<CNTopic[]> { |
| const res = await fetch(`${API_BASE}/api/cn/topics`, { |
| method: 'GET', |
| headers: { 'Content-Type': 'application/json' }, |
| }); |
|
|
| if (!res.ok) { |
| throw new Error(`API error ${res.status}: ${res.statusText}`); |
| } |
|
|
| const data = await res.json() as { topics: CNTopic[] }; |
| return data.topics ?? []; |
| } |
|
|
| |
| |
| |
| export async function fetchCNTopicContent(chapterNo: number): Promise<CNTopicContent> { |
| const res = await fetch(`${API_BASE}/api/cn/topics/${chapterNo}`, { |
| method: 'GET', |
| headers: { 'Content-Type': 'application/json' }, |
| }); |
|
|
| if (!res.ok) { |
| throw new Error(`API error ${res.status}: ${res.statusText}`); |
| } |
|
|
| return await res.json() as CNTopicContent; |
| } |
|
|