asd
This commit is contained in:
@@ -791,8 +791,13 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
|||||||
integration_type=integration_type,
|
integration_type=integration_type,
|
||||||
account=account
|
account=account
|
||||||
)
|
)
|
||||||
|
response_data = {
|
||||||
|
'id': integration_settings.integration_type,
|
||||||
|
'enabled': integration_settings.is_active,
|
||||||
|
**integration_settings.config
|
||||||
|
}
|
||||||
return success_response(
|
return success_response(
|
||||||
data=integration_settings.config,
|
data=response_data,
|
||||||
request=request
|
request=request
|
||||||
)
|
)
|
||||||
except IntegrationSettings.DoesNotExist:
|
except IntegrationSettings.DoesNotExist:
|
||||||
|
|||||||
@@ -162,21 +162,12 @@ export default function Integration() {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const response = await fetch(
|
const data = await fetchAPI(`/v1/system/settings/integrations/${integrationId}/test/`, {
|
||||||
`${API_BASE_URL}/v1/system/settings/integrations/${integrationId}/test/`,
|
|
||||||
{
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
credentials: 'include',
|
|
||||||
body: JSON.stringify(requestBody),
|
body: JSON.stringify(requestBody),
|
||||||
}
|
});
|
||||||
);
|
|
||||||
|
|
||||||
const data = await response.json();
|
if (data.success) {
|
||||||
|
|
||||||
if (response.ok && data.success) {
|
|
||||||
// Validation successful
|
// Validation successful
|
||||||
setValidationStatuses(prev => ({
|
setValidationStatuses(prev => ({
|
||||||
...prev,
|
...prev,
|
||||||
@@ -248,21 +239,14 @@ export default function Integration() {
|
|||||||
|
|
||||||
const loadIntegrationSettings = async () => {
|
const loadIntegrationSettings = async () => {
|
||||||
try {
|
try {
|
||||||
const API_BASE_URL = import.meta.env.VITE_BACKEND_URL || 'https://api.igny8.com/api';
|
|
||||||
const integrationIds = ['openai', 'runware', 'image_generation'];
|
const integrationIds = ['openai', 'runware', 'image_generation'];
|
||||||
|
|
||||||
const promises = integrationIds.map(async (id) => {
|
const promises = integrationIds.map(async (id) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const data = await fetchAPI(`/v1/system/settings/integrations/${id}/`);
|
||||||
`${API_BASE_URL}/v1/system/settings/integrations/${id}/`,
|
|
||||||
{ credentials: 'include' }
|
|
||||||
);
|
|
||||||
if (response.ok) {
|
|
||||||
const data = await response.json();
|
|
||||||
if (data.success && data.data) {
|
if (data.success && data.data) {
|
||||||
return { id, config: data.data };
|
return { id, config: data.data };
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return { id, config: null };
|
return { id, config: null };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(`Error loading ${id} settings:`, error);
|
console.error(`Error loading ${id} settings:`, 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 data = await fetchAPI(`/v1/system/settings/integrations/${selectedIntegration}/save/`, {
|
||||||
const endpoint = `${API_BASE_URL}/v1/system/settings/integrations/${selectedIntegration}/save/`;
|
|
||||||
|
|
||||||
const response = await fetch(endpoint, {
|
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
credentials: 'include',
|
|
||||||
body: JSON.stringify(configToSave),
|
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) {
|
if (data.success) {
|
||||||
toast.success(data.message || 'Settings saved successfully');
|
toast.success(data.message || 'Settings saved successfully');
|
||||||
setShowSettingsModal(false);
|
setShowSettingsModal(false);
|
||||||
|
|||||||
Reference in New Issue
Block a user