feat: daily motto

This commit is contained in:
Tony Yang
2025-04-15 12:01:53 +08:00
parent d227288d14
commit b8ae97e49b
5 changed files with 101 additions and 1 deletions
+25
View File
@@ -173,3 +173,28 @@ export async function uploadAvatar(avatar, jwt) {
const data = await response.json();
return data;
}
export async function generateMotto(jwt) {
try {
const response = await fetch('/api/motto', {
headers: {
'Authorization': `Bearer ${jwt}`,
},
});
if (!response.ok) {
if (response.status === 401) {
unauthRedirectToLogin();
return;
}
const error = await response.json();
throw new Error(error.error || 'Generating motto failed');
}
const data = await response.json();
return data.motto;
} catch {
console.error('Error generating motto:', error);
throw new Error('Failed to generate motto');
}
}