fix: resolve 422 error and undefined error in anime search endpoint

- Split search endpoint into separate GET and POST handlers
- Add SearchAnimeRequest Pydantic model for POST body validation
- Add 'link' field to AnimeSummary model for frontend compatibility
- Update frontend to handle both array and wrapped response formats
- Extract search logic into shared _perform_search() function

Fixes issue where POST requests with JSON body were failing with 422
Unprocessable Content error because the endpoint expected query params
instead of request body.

Also fixes frontend 'undefined' error by handling direct array responses
in addition to legacy wrapped format.
This commit is contained in:
2025-10-28 19:28:50 +01:00
parent 95b7059576
commit 02764f7e6f
2 changed files with 61 additions and 14 deletions

View File

@@ -834,10 +834,13 @@ class AniWorldApp {
if (!response) return;
const data = await response.json();
if (data.status === 'success') {
// Check if response is a direct array (new format) or wrapped object (legacy)
if (Array.isArray(data)) {
this.displaySearchResults(data);
} else if (data.status === 'success') {
this.displaySearchResults(data.results);
} else {
this.showToast(`Search error: ${data.message}`, 'error');
this.showToast(`Search error: ${data.message || 'Unknown error'}`, 'error');
}
} catch (error) {
console.error('Search error:', error);