first commit
This commit is contained in:
50
front/src/api.ts
Normal file
50
front/src/api.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
export interface SiteSettings {
|
||||
siteTitle: string;
|
||||
siteFooter: string;
|
||||
enableCodeIcon: boolean;
|
||||
repoUrl: string;
|
||||
favicon: string;
|
||||
}
|
||||
|
||||
export const getSettings = async (): Promise<SiteSettings> => {
|
||||
try {
|
||||
const response = await fetch('/api/settings');
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const json = await response.json();
|
||||
if (json.code === 1000 && json.data) {
|
||||
const data = json.data;
|
||||
return {
|
||||
siteTitle: data.title,
|
||||
siteFooter: data.footer_text,
|
||||
enableCodeIcon: data.enable_repo_button ?? true,
|
||||
repoUrl: data.repo_link,
|
||||
favicon: data.icon,
|
||||
};
|
||||
} else {
|
||||
throw new Error('Invalid response code or missing data');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch settings:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const getAbout = async (): Promise<string> => {
|
||||
try {
|
||||
const response = await fetch('/api/about');
|
||||
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 about content:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user