实现投稿ui
This commit is contained in:
@@ -48,3 +48,36 @@ export const getAbout = async (): Promise<string> => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export interface StaticsData {
|
||||
posts: number;
|
||||
comments: number;
|
||||
images: number;
|
||||
}
|
||||
|
||||
export const testApiStatus = async (): Promise<boolean> => {
|
||||
try {
|
||||
const response = await fetch('/api/test');
|
||||
return response.ok;
|
||||
} catch (error) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
export const getStatics = async (): Promise<StaticsData> => {
|
||||
try {
|
||||
const response = await fetch('/api/statics');
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const json = await response.json();
|
||||
if (json.code === 1000) {
|
||||
return json.data;
|
||||
} else {
|
||||
throw new Error('Invalid response code');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch statics:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user