Fix JSON parsing in NFO JavaScript modules
- Add response.json() calls in nfo-manager.js for all API calls - Add response.json() calls in nfo-config.js for all API calls - Fix createNFO, refreshNFO, viewNFO, getSeriesWithoutNFO functions - Fix load and testTMDBConnection functions - All API responses must be parsed before accessing properties
This commit is contained in:
@@ -18,7 +18,13 @@ AniWorld.NFOConfig = (function() {
|
||||
*/
|
||||
async function load() {
|
||||
try {
|
||||
const config = await AniWorld.ApiClient.request(API.CONFIG);
|
||||
const response = await AniWorld.ApiClient.request(API.CONFIG);
|
||||
|
||||
if (!response) {
|
||||
throw new Error('Failed to load configuration');
|
||||
}
|
||||
|
||||
const config = await response.json();
|
||||
|
||||
if (config && config.nfo) {
|
||||
const nfo = config.nfo;
|
||||
@@ -148,10 +154,16 @@ AniWorld.NFOConfig = (function() {
|
||||
}
|
||||
);
|
||||
|
||||
if (response && response.valid) {
|
||||
if (!response) {
|
||||
throw new Error('No response from server');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.valid) {
|
||||
AniWorld.UI.showToast('TMDB API key is valid!', 'success');
|
||||
} else {
|
||||
const message = response && response.message ? response.message : 'Invalid API key';
|
||||
const message = data && data.message ? data.message : 'Invalid API key';
|
||||
AniWorld.UI.showToast('TMDB validation failed: ' + message, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -32,9 +32,15 @@ AniWorld.NFOManager = (function() {
|
||||
}
|
||||
);
|
||||
|
||||
if (response && response.message) {
|
||||
AniWorld.UI.showToast(response.message || 'NFO created successfully', 'success');
|
||||
return response;
|
||||
if (!response) {
|
||||
throw new Error('Failed to create NFO');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.message) {
|
||||
AniWorld.UI.showToast(data.message || 'NFO created successfully', 'success');
|
||||
return data;
|
||||
} else {
|
||||
throw new Error('Failed to create NFO');
|
||||
}
|
||||
@@ -66,9 +72,15 @@ AniWorld.NFOManager = (function() {
|
||||
}
|
||||
);
|
||||
|
||||
if (response && response.message) {
|
||||
AniWorld.UI.showToast(response.message || 'NFO updated successfully', 'success');
|
||||
return response;
|
||||
if (!response) {
|
||||
throw new Error('Failed to refresh NFO');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.message) {
|
||||
AniWorld.UI.showToast(data.message || 'NFO updated successfully', 'success');
|
||||
return data;
|
||||
} else {
|
||||
throw new Error('Failed to refresh NFO');
|
||||
}
|
||||
@@ -97,8 +109,14 @@ AniWorld.NFOManager = (function() {
|
||||
`/api/nfo/${encodeURIComponent(seriesKey)}/content`
|
||||
);
|
||||
|
||||
if (response && response.content) {
|
||||
return response;
|
||||
if (!response) {
|
||||
throw new Error('No NFO data available');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.content) {
|
||||
return data;
|
||||
} else {
|
||||
throw new Error('No NFO data available');
|
||||
}
|
||||
@@ -200,8 +218,14 @@ AniWorld.NFOManager = (function() {
|
||||
try {
|
||||
const response = await AniWorld.ApiClient.request('/api/nfo/missing');
|
||||
|
||||
if (response && response.series) {
|
||||
return response;
|
||||
if (!response) {
|
||||
throw new Error('Failed to get series without NFO');
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (data && data.series) {
|
||||
return data;
|
||||
} else {
|
||||
throw new Error('Failed to get series without NFO');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user