diff --git a/apps/common/init/init_doc.py b/apps/common/init/init_doc.py index e77a52cbf..156275e4a 100644 --- a/apps/common/init/init_doc.py +++ b/apps/common/init/init_doc.py @@ -18,21 +18,34 @@ chat_api_prefix = CONFIG.get_chat_path()[1:] + '/api/' def init_app_doc(system_urlpatterns): system_urlpatterns += [ - path('doc/schema/', SpectacularAPIView.as_view(), name='schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的 - path('doc/', SpectacularSwaggerView.as_view(url_name='schema'), name='swagger-ui'), # swagger-ui的路由 + path(f'{CONFIG.get_admin_path()[1:]}/api-doc/schema/', SpectacularAPIView.as_view(), name='schema'), + # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的 + path(f'{CONFIG.get_admin_path()[1:]}/api-doc/', SpectacularSwaggerView.as_view(url_name='schema'), + name='swagger-ui'), # swagger-ui的路由 ] +class ChatSpectacularSwaggerView(SpectacularSwaggerView): + @staticmethod + def _swagger_ui_resource(filename): + return f'{CONFIG.get_chat_path()}/api-doc/swagger-ui-dist/{filename}' + + @staticmethod + def _swagger_ui_favicon(): + return f'{CONFIG.get_chat_path()}/api-doc/swagger-ui-dist/favicon-32x32.png' + + def init_chat_doc(system_urlpatterns, chat_urlpatterns): system_urlpatterns += [ - path('doc_chat/schema/', + path(f'{CONFIG.get_chat_path()[1:]}/api-doc/schema/', SpectacularAPIView.as_view(patterns=[ URLPattern(pattern=f'{chat_api_prefix}{str(url.pattern)}', callback=url.callback, default_args=url.default_args, name=url.name) for url in chat_urlpatterns if ['chat', 'open', 'profile'].__contains__(url.name)]), name='chat_schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的 - path('doc_chat/', SpectacularSwaggerView.as_view(url_name='chat_schema'), name='swagger-ui'), # swagger-ui的路由 + path(f'{CONFIG.get_chat_path()[1:]}/api-doc/', ChatSpectacularSwaggerView.as_view(url_name='chat_schema'), + name='swagger-ui'), # swagger-ui的路由 ] diff --git a/apps/maxkb/settings/base.py b/apps/maxkb/settings/base.py index cb127ef91..4d884a72b 100644 --- a/apps/maxkb/settings/base.py +++ b/apps/maxkb/settings/base.py @@ -120,9 +120,9 @@ SPECTACULAR_SETTINGS = { 'VERSION': 'v2', 'SERVE_INCLUDE_SCHEMA': False, # OTHER SETTINGS - 'SWAGGER_UI_DIST': '/doc/swagger-ui-dist', # shorthand to use the sidecar instead - 'SWAGGER_UI_FAVICON_HREF': '/doc/swagger-ui-dist/favicon-32x32.png', - 'REDOC_DIST': '/doc/redoc', + 'SWAGGER_UI_DIST': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist', # shorthand to use the sidecar instead + 'SWAGGER_UI_FAVICON_HREF': f'{CONFIG.get_admin_path()}/api-doc/swagger-ui-dist/favicon-32x32.png', + 'REDOC_DIST': f'{CONFIG.get_admin_path()}/api-doc/redoc', 'SECURITY_DEFINITIONS': { 'Bearer': { 'type': 'apiKey', diff --git a/apps/maxkb/urls.py b/apps/maxkb/urls.py index 166ea574a..e0ce8c78d 100644 --- a/apps/maxkb/urls.py +++ b/apps/maxkb/urls.py @@ -52,9 +52,14 @@ init_doc(urlpatterns, chat_urlpatterns) def pro(): urlpatterns.append( - re_path(r'^doc/(?P.*)$', static.serve, + re_path(rf'^{CONFIG.get_admin_path()[1:]}/api-doc/(?P.*)$', static.serve, {'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar")}, name='doc'), ) + + urlpatterns.append( + re_path(rf'^{CONFIG.get_chat_path()[1:]}/api-doc/(?P.*)$', static.serve, + {'document_root': os.path.join(settings.STATIC_ROOT, "drf_spectacular_sidecar")}, name='doc_chat'), + ) # 暴露ui静态资源 urlpatterns.append( re_path(rf"^{CONFIG.get_admin_path()[1:]}/(?P.*)$", static.serve, diff --git a/ui/src/layout/layout-header/avatar/APIKeyDialog.vue b/ui/src/layout/layout-header/avatar/APIKeyDialog.vue index 24ea5378e..2bf45bac0 100644 --- a/ui/src/layout/layout-header/avatar/APIKeyDialog.vue +++ b/ui/src/layout/layout-header/avatar/APIKeyDialog.vue @@ -49,7 +49,7 @@ - + @@ -87,7 +87,7 @@ const props = defineProps({ }) const emit = defineEmits(['addData']) -const apiUrl = window.location.origin + '/doc/' +const apiUrl = window.location.origin + +`${window.MaxKB.prefix}/api-doc/` const SettingAPIKeyDialogRef = ref() const dialogVisible = ref(false) const loading = ref(false) @@ -126,9 +126,7 @@ function changeState(bool: boolean, row: any) { const obj = { is_active: bool, } - const str = bool - ? t('common.enabled') - : t('common.disabled') + const str = bool ? t('common.enabled') : t('common.disabled') systemKeyApi.putAPIKey(row.id, obj, loading).then((res) => { MsgSuccess(str) getApiKeyList() diff --git a/ui/src/views/application-overview/index.vue b/ui/src/views/application-overview/index.vue index 1315a24a3..e8d260cbc 100644 --- a/ui/src/views/application-overview/index.vue +++ b/ui/src/views/application-overview/index.vue @@ -229,7 +229,7 @@ const permissionPrecise = computed(() => { return permissionMap['application'][apiType.value] }) -const apiUrl = window.location.origin + '/doc_chat/' +const apiUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api-doc/` const baseUrl = window.location.origin + `${window.MaxKB.chatPrefix}/api/`