105 lines
5.1 KiB
Python
105 lines
5.1 KiB
Python
"""
|
|
URL patterns for system module.
|
|
"""
|
|
from django.urls import path, include
|
|
from rest_framework.routers import DefaultRouter
|
|
from .views import AIPromptViewSet, AuthorProfileViewSet, StrategyViewSet, system_status, get_request_metrics, gitea_webhook, ping
|
|
from .integration_views import IntegrationSettingsViewSet
|
|
from .settings_views import (
|
|
SystemSettingsViewSet, AccountSettingsViewSet, UserSettingsViewSet,
|
|
ModuleSettingsViewSet, ModuleEnableSettingsViewSet, AISettingsViewSet,
|
|
ContentSettingsViewSet
|
|
)
|
|
router = DefaultRouter()
|
|
router.register(r'prompts', AIPromptViewSet, basename='prompts')
|
|
router.register(r'author-profiles', AuthorProfileViewSet, basename='author-profile')
|
|
router.register(r'strategies', StrategyViewSet, basename='strategy')
|
|
router.register(r'settings/system', SystemSettingsViewSet, basename='system-settings')
|
|
router.register(r'settings/account', AccountSettingsViewSet, basename='account-settings')
|
|
router.register(r'settings/user', UserSettingsViewSet, basename='user-settings')
|
|
# Register ModuleSettingsViewSet first
|
|
router.register(r'settings/modules', ModuleSettingsViewSet, basename='module-settings')
|
|
router.register(r'settings/ai', AISettingsViewSet, basename='ai-settings')
|
|
|
|
# Custom URL patterns for integration settings - matching reference plugin structure
|
|
# Reference: WordPress uses settings_fields('igny8_api_settings') -> options.php which calls update_option()
|
|
# We use REST endpoints: /api/v1/system/settings/integrations/{type}/save/
|
|
# Use as_view with proper method mapping
|
|
|
|
integration_detail_viewset = IntegrationSettingsViewSet.as_view({
|
|
'get': 'retrieve',
|
|
})
|
|
|
|
integration_save_viewset = IntegrationSettingsViewSet.as_view({
|
|
'post': 'save_post',
|
|
'put': 'update',
|
|
})
|
|
|
|
integration_test_viewset = IntegrationSettingsViewSet.as_view({
|
|
'post': 'test_connection',
|
|
})
|
|
|
|
integration_generate_viewset = IntegrationSettingsViewSet.as_view({
|
|
'post': 'generate_image',
|
|
})
|
|
|
|
integration_task_progress_viewset = IntegrationSettingsViewSet.as_view({
|
|
'get': 'task_progress',
|
|
})
|
|
|
|
integration_image_gen_settings_viewset = IntegrationSettingsViewSet.as_view({
|
|
'get': 'get_image_generation_settings',
|
|
})
|
|
|
|
# Custom view for module enable settings to avoid URL routing conflict with ModuleSettingsViewSet
|
|
# This must be defined as a custom path BEFORE router.urls to ensure it matches first
|
|
# Read-only viewset - only GET is supported (modification via Django Admin only)
|
|
module_enable_viewset = ModuleEnableSettingsViewSet.as_view({
|
|
'get': 'list',
|
|
})
|
|
|
|
# Content settings viewsets for Content Generation and Publishing settings
|
|
content_settings_detail_viewset = ContentSettingsViewSet.as_view({
|
|
'get': 'retrieve',
|
|
})
|
|
|
|
content_settings_save_viewset = ContentSettingsViewSet.as_view({
|
|
'post': 'save_settings',
|
|
'put': 'update',
|
|
})
|
|
urlpatterns = [
|
|
# Module enable settings endpoint - MUST come before router.urls to avoid conflict
|
|
# When /settings/modules/enable/ is called, it would match ModuleSettingsViewSet with pk='enable'
|
|
# So we define it as a custom path first
|
|
path('settings/modules/enable/', module_enable_viewset, name='module-enable-settings'),
|
|
path('', include(router.urls)),
|
|
# Public health check endpoint (API Standard v1.0 requirement)
|
|
path('ping/', ping, name='system-ping'),
|
|
# System status endpoint
|
|
path('status/', system_status, name='system-status'),
|
|
# Request metrics endpoint
|
|
path('request-metrics/<str:request_id>/', get_request_metrics, name='request-metrics'),
|
|
# Gitea webhook endpoint
|
|
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
|
|
path('settings/integrations/<str:pk>/generate/', integration_generate_viewset, name='integration-settings-generate'),
|
|
# POST: Test connection - MUST come before base path
|
|
path('settings/integrations/<str:pk>/test/', integration_test_viewset, name='integration-settings-test'),
|
|
# POST/PUT: Save settings (matches frontend call to /save/) - MUST come before base path
|
|
path('settings/integrations/<str:pk>/save/', integration_save_viewset, name='integration-settings-save'),
|
|
# GET: Retrieve settings - Base path comes last
|
|
path('settings/integrations/<str:pk>/', integration_detail_viewset, name='integration-settings-detail'),
|
|
# Content settings routes for Content Generation and Publishing
|
|
# POST/PUT: Save content settings - must come before GET
|
|
path('settings/content/<str:pk>/save/', content_settings_save_viewset, name='content-settings-save'),
|
|
# GET: Retrieve content settings
|
|
path('settings/content/<str:pk>/', content_settings_detail_viewset, name='content-settings-detail'),
|
|
]
|
|
|