Add Image Generation Settings Endpoint and Update Frontend Modal: Implement a new API endpoint to fetch image generation settings, enhance the ImageQueueModal to display progress and status, and integrate the settings into the image generation workflow.
This commit is contained in:
@@ -731,6 +731,72 @@ class IntegrationSettingsViewSet(viewsets.ViewSet):
|
||||
'error': f'Failed to get settings: {str(e)}'
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='image_generation', url_name='image_generation_settings')
|
||||
def get_image_generation_settings(self, request):
|
||||
"""Get image generation settings for current account"""
|
||||
account = getattr(request, 'account', None)
|
||||
|
||||
if not account:
|
||||
# Fallback to user's account
|
||||
user = getattr(request, 'user', None)
|
||||
if user and hasattr(user, 'is_authenticated') and user.is_authenticated:
|
||||
account = getattr(user, 'account', None)
|
||||
# Fallback to default account
|
||||
if not account:
|
||||
from igny8_core.auth.models import Account
|
||||
try:
|
||||
account = Account.objects.first()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
if not account:
|
||||
return Response({
|
||||
'error': 'Account not found',
|
||||
'type': 'AuthenticationError'
|
||||
}, status=status.HTTP_401_UNAUTHORIZED)
|
||||
|
||||
try:
|
||||
from .models import IntegrationSettings
|
||||
integration = IntegrationSettings.objects.get(
|
||||
account=account,
|
||||
integration_type='image_generation',
|
||||
is_active=True
|
||||
)
|
||||
|
||||
config = integration.config or {}
|
||||
|
||||
return Response({
|
||||
'success': True,
|
||||
'config': {
|
||||
'provider': config.get('provider', 'openai'),
|
||||
'model': config.get('model', 'dall-e-3'),
|
||||
'image_type': config.get('image_type', 'realistic'),
|
||||
'max_in_article_images': config.get('max_in_article_images', 2),
|
||||
'image_format': config.get('image_format', 'webp'),
|
||||
'desktop_enabled': config.get('desktop_enabled', True),
|
||||
'mobile_enabled': config.get('mobile_enabled', True),
|
||||
}
|
||||
}, status=status.HTTP_200_OK)
|
||||
except IntegrationSettings.DoesNotExist:
|
||||
return Response({
|
||||
'success': True,
|
||||
'config': {
|
||||
'provider': 'openai',
|
||||
'model': 'dall-e-3',
|
||||
'image_type': 'realistic',
|
||||
'max_in_article_images': 2,
|
||||
'image_format': 'webp',
|
||||
'desktop_enabled': True,
|
||||
'mobile_enabled': True,
|
||||
}
|
||||
}, status=status.HTTP_200_OK)
|
||||
except Exception as e:
|
||||
logger.error(f"[get_image_generation_settings] Error: {str(e)}", exc_info=True)
|
||||
return Response({
|
||||
'error': str(e),
|
||||
'type': 'ServerError'
|
||||
}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
|
||||
|
||||
@action(detail=False, methods=['get'], url_path='task_progress/(?P<task_id>[^/.]+)', url_name='task-progress')
|
||||
def task_progress(self, request, task_id=None):
|
||||
"""
|
||||
|
||||
@@ -45,6 +45,10 @@ integration_task_progress_viewset = IntegrationSettingsViewSet.as_view({
|
||||
'get': 'task_progress',
|
||||
})
|
||||
|
||||
integration_image_gen_settings_viewset = IntegrationSettingsViewSet.as_view({
|
||||
'get': 'get_image_generation_settings',
|
||||
})
|
||||
|
||||
urlpatterns = [
|
||||
path('', include(router.urls)),
|
||||
# System status endpoint
|
||||
@@ -55,6 +59,8 @@ urlpatterns = [
|
||||
path('webhook/', gitea_webhook, name='gitea-webhook'),
|
||||
# Integration settings routes - exact match to reference plugin workflow
|
||||
# IMPORTANT: More specific paths must come BEFORE less specific ones
|
||||
# GET: Image generation settings - MUST come before other settings paths
|
||||
path('integrations/image_generation/', integration_image_gen_settings_viewset, name='integration-image-gen-settings'),
|
||||
# GET: Task progress - MUST come before other settings paths
|
||||
path('settings/task_progress/<str:task_id>/', integration_task_progress_viewset, name='integration-task-progress'),
|
||||
# POST: Generate image (for image_generation integration) - MUST come before base path
|
||||
|
||||
Reference in New Issue
Block a user