first commit

This commit is contained in:
LeonspaceX
2026-01-22 18:52:07 +08:00
commit d5ab09c9dc
32 changed files with 6295 additions and 0 deletions

50
front/src/api.ts Normal file
View 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;
}
};