mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: File URL adaptation (#3459)
This commit is contained in:
parent
471ac59f29
commit
9166528504
|
|
@ -73,7 +73,7 @@ class Application(AppModelMixin):
|
|||
model_params_setting = models.JSONField(verbose_name="模型参数相关设置", default=dict)
|
||||
tts_model_params_setting = models.JSONField(verbose_name="模型参数相关设置", default=dict)
|
||||
problem_optimization = models.BooleanField(verbose_name="问题优化", default=False)
|
||||
icon = models.CharField(max_length=256, verbose_name="应用icon", default="/ui/favicon.ico")
|
||||
icon = models.CharField(max_length=256, verbose_name="应用icon", default="./favicon.ico")
|
||||
work_flow = models.JSONField(verbose_name="工作流数据", default=dict)
|
||||
type = models.CharField(verbose_name="应用类型", choices=ApplicationTypeChoices.choices,
|
||||
default=ApplicationTypeChoices.SIMPLE, max_length=256)
|
||||
|
|
|
|||
|
|
@ -41,8 +41,10 @@ urlpatterns = [
|
|||
path(admin_api_prefix, include("knowledge.urls")),
|
||||
path(admin_api_prefix, include("system_manage.urls")),
|
||||
path(admin_api_prefix, include("application.urls")),
|
||||
path(admin_api_prefix, include("oss.urls")),
|
||||
path(chat_api_prefix, include("chat.urls")),
|
||||
path('oss/', include('oss.urls')),
|
||||
path(f'{admin_ui_prefix[1:]}/', include('oss.retrieval_urls')),
|
||||
path(f'{chat_ui_prefix[1:]}/', include('oss.retrieval_urls')),
|
||||
]
|
||||
urlpatterns += [
|
||||
path('schema/', SpectacularAPIView.as_view(), name='schema'), # schema的配置文件的路由,下面两个ui也是根据这个配置文件来生成的
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
# coding=utf-8
|
||||
"""
|
||||
@project: MaxKB
|
||||
@Author:虎虎
|
||||
@file: retrieval_urls.py
|
||||
@date:2025/7/2 19:01
|
||||
@desc:
|
||||
"""
|
||||
from django.urls import re_path
|
||||
|
||||
from . import views
|
||||
|
||||
app_name = 'oss'
|
||||
|
||||
urlpatterns = [
|
||||
re_path(rf'^(.*)/oss/file/(?P<file_id>[\w-]+)/?$',
|
||||
views.FileRetrievalView.as_view()),
|
||||
re_path(rf'oss/file/(?P<file_id>[\w-]+)/?$',
|
||||
views.FileRetrievalView.as_view()),
|
||||
|
||||
]
|
||||
|
|
@ -67,7 +67,7 @@ class FileSerializer(serializers.Serializer):
|
|||
file_id = meta.get('file_id', uuid.uuid7())
|
||||
file = File(id=file_id, file_name=self.data.get('file').name, meta=meta)
|
||||
file.save(self.data.get('file').read())
|
||||
return f'/oss/file/{file_id}'
|
||||
return f'./oss/file/{file_id}'
|
||||
|
||||
class Operate(serializers.Serializer):
|
||||
id = serializers.UUIDField(required=True)
|
||||
|
|
|
|||
|
|
@ -5,6 +5,5 @@ from . import views
|
|||
app_name = 'oss'
|
||||
|
||||
urlpatterns = [
|
||||
path('file', views.FileView.as_view()),
|
||||
path('file/<str:file_id>', views.FileView.Operate.as_view()),
|
||||
path('oss/file', views.FileView.as_view()),
|
||||
]
|
||||
|
|
|
|||
|
|
@ -12,6 +12,20 @@ from knowledge.api.file import FileUploadAPI, FileGetAPI
|
|||
from oss.serializers.file import FileSerializer
|
||||
|
||||
|
||||
class FileRetrievalView(APIView):
|
||||
@extend_schema(
|
||||
methods=['GET'],
|
||||
summary=_('Get file'),
|
||||
description=_('Get file'),
|
||||
operation_id=_('Get file'), # type: ignore
|
||||
parameters=FileGetAPI.get_parameters(),
|
||||
responses=FileGetAPI.get_response(),
|
||||
tags=[_('File')] # type: ignore
|
||||
)
|
||||
def get(self, request: Request, file_id: str):
|
||||
return FileSerializer.Operate(data={'id': file_id}).get()
|
||||
|
||||
|
||||
class FileView(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
parser_classes = [MultiPartParser]
|
||||
|
|
@ -31,17 +45,7 @@ class FileView(APIView):
|
|||
return result.success(FileSerializer(data={'file': request.FILES.get('file')}).upload())
|
||||
|
||||
class Operate(APIView):
|
||||
@extend_schema(
|
||||
methods=['GET'],
|
||||
summary=_('Get file'),
|
||||
description=_('Get file'),
|
||||
operation_id=_('Get file'), # type: ignore
|
||||
parameters=FileGetAPI.get_parameters(),
|
||||
responses=FileGetAPI.get_response(),
|
||||
tags=[_('File')] # type: ignore
|
||||
)
|
||||
def get(self, request: Request, file_id: str):
|
||||
return FileSerializer.Operate(data={'id': file_id}).get()
|
||||
authentication_classes = [TokenAuth]
|
||||
|
||||
@extend_schema(
|
||||
methods=['DELETE'],
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Result } from '@/request/Result'
|
||||
import { get, post, del, put } from '@/request/index'
|
||||
|
||||
const prefix = '/image'
|
||||
const prefix = '/oss/file'
|
||||
/**
|
||||
* 上传图片
|
||||
* @param 参数 file:file
|
||||
|
|
@ -11,5 +11,5 @@ const postImage: (data: any) => Promise<Result<any>> = (data) => {
|
|||
}
|
||||
|
||||
export default {
|
||||
postImage
|
||||
postImage,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,11 +40,6 @@ export default defineConfig((conf: any) => {
|
|||
target: 'http://127.0.0.1:8080',
|
||||
changeOrigin: true,
|
||||
}
|
||||
proxyConf['/oss'] = {
|
||||
target: 'http://127.0.0.1:8080',
|
||||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
||||
}
|
||||
proxyConf['/chat/api'] = {
|
||||
// target: 'http://47.92.195.88:8080/',
|
||||
target: 'http://127.0.0.1:8080',
|
||||
|
|
@ -65,6 +60,17 @@ export default defineConfig((conf: any) => {
|
|||
changeOrigin: true,
|
||||
rewrite: (path: string) => path.replace(ENV.VITE_BASE_PATH, '/'),
|
||||
}
|
||||
|
||||
// 前端静态资源转发到本身
|
||||
proxyConf[`^${ENV.VITE_BASE_PATH}.+\/oss\/file\/.*$`] = {
|
||||
target: `http://127.0.0.1:8080`,
|
||||
changeOrigin: true,
|
||||
}
|
||||
// 前端静态资源转发到本身
|
||||
proxyConf[`^${ENV.VITE_BASE_PATH}oss\/file\/.*$`] = {
|
||||
target: `http://127.0.0.1:8080`,
|
||||
changeOrigin: true,
|
||||
}
|
||||
// 前端静态资源转发到本身
|
||||
proxyConf[ENV.VITE_BASE_PATH] = {
|
||||
target: `http://127.0.0.1:${ENV.VITE_APP_PORT}`,
|
||||
|
|
|
|||
Loading…
Reference in New Issue