asd
This commit is contained in:
@@ -791,8 +791,13 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
||||
integration_type=integration_type,
|
||||
account=account
|
||||
)
|
||||
response_data = {
|
||||
'id': integration_settings.integration_type,
|
||||
'enabled': integration_settings.is_active,
|
||||
**integration_settings.config
|
||||
}
|
||||
return success_response(
|
||||
data=integration_settings.config,
|
||||
data=response_data,
|
||||
request=request
|
||||
)
|
||||
except IntegrationSettings.DoesNotExist:
|
||||
|
||||
@@ -162,21 +162,12 @@ export default function Integration() {
|
||||
};
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/v1/system/settings/integrations/${integrationId}/test/`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(requestBody),
|
||||
}
|
||||
);
|
||||
const data = await fetchAPI(`/v1/system/settings/integrations/${integrationId}/test/`, {
|
||||
method: 'POST',
|
||||
body: JSON.stringify(requestBody),
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
if (response.ok && data.success) {
|
||||
if (data.success) {
|
||||
// Validation successful
|
||||
setValidationStatuses(prev => ({
|
||||
...prev,
|
||||
@@ -248,20 +239,13 @@ export default function Integration() {
|
||||
|
||||
const loadIntegrationSettings = async () => {
|
||||
try {
|
||||
const API_BASE_URL = import.meta.env.VITE_BACKEND_URL || 'https://api.igny8.com/api';
|
||||
const integrationIds = ['openai', 'runware', 'image_generation'];
|
||||
|
||||
const promises = integrationIds.map(async (id) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`${API_BASE_URL}/v1/system/settings/integrations/${id}/`,
|
||||
{ credentials: 'include' }
|
||||
);
|
||||
if (response.ok) {
|
||||
const data = await response.json();
|
||||
if (data.success && data.data) {
|
||||
return { id, config: data.data };
|
||||
}
|
||||
const data = await fetchAPI(`/v1/system/settings/integrations/${id}/`);
|
||||
if (data.success && data.data) {
|
||||
return { id, config: data.data };
|
||||
}
|
||||
return { id, config: null };
|
||||
} catch (error) {
|
||||
@@ -414,40 +398,11 @@ export default function Integration() {
|
||||
};
|
||||
}
|
||||
|
||||
const API_BASE_URL = import.meta.env.VITE_BACKEND_URL || 'https://api.igny8.com/api';
|
||||
const endpoint = `${API_BASE_URL}/v1/system/settings/integrations/${selectedIntegration}/save/`;
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
const data = await fetchAPI(`/v1/system/settings/integrations/${selectedIntegration}/save/`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
credentials: 'include',
|
||||
body: JSON.stringify(configToSave),
|
||||
});
|
||||
|
||||
// Check if response is HTML (error page)
|
||||
const contentType = response.headers.get('content-type') || '';
|
||||
if (!contentType.includes('application/json')) {
|
||||
const text = await response.text();
|
||||
if (text.trim().startsWith('<!DOCTYPE') || text.trim().startsWith('<html')) {
|
||||
throw new Error(`Server returned HTML instead of JSON. This usually means the endpoint doesn't exist (404). Response: ${text.substring(0, 200)}`);
|
||||
}
|
||||
}
|
||||
|
||||
let data;
|
||||
try {
|
||||
const responseText = await response.text();
|
||||
data = responseText ? JSON.parse(responseText) : {};
|
||||
} catch (parseError: any) {
|
||||
const text = await response.text();
|
||||
throw new Error(`Failed to parse response as JSON. Response was: ${text.substring(0, 200)}`);
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || `HTTP ${response.status}: ${response.statusText}`);
|
||||
}
|
||||
|
||||
if (data.success) {
|
||||
toast.success(data.message || 'Settings saved successfully');
|
||||
setShowSettingsModal(false);
|
||||
|
||||
Reference in New Issue
Block a user