mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
feat: add source_id and source_type fields to FileSerializer and update related components
This commit is contained in:
parent
50cc851f4f
commit
79dc3e4909
|
|
@ -7,7 +7,7 @@ from django.utils.translation import gettext_lazy as _
|
|||
from rest_framework import serializers
|
||||
|
||||
from common.exception.app_exception import NotFound404
|
||||
from knowledge.models import File
|
||||
from knowledge.models import File, FileSourceType
|
||||
from tools.serializers.tool import UploadedFileField
|
||||
|
||||
mime_types = {
|
||||
|
|
@ -57,6 +57,13 @@ mime_types = {
|
|||
class FileSerializer(serializers.Serializer):
|
||||
file = UploadedFileField(required=True, label=_('file'))
|
||||
meta = serializers.JSONField(required=False, allow_null=True)
|
||||
source_id = serializers.CharField(
|
||||
required=False, allow_null=True, label=_('source id'), default=FileSourceType.TEMPORARY_120_MINUTE.value
|
||||
)
|
||||
source_type = serializers.ChoiceField(
|
||||
choices=FileSourceType.choices, required=False, allow_null=True, label=_('source type'),
|
||||
default=FileSourceType.TEMPORARY_120_MINUTE
|
||||
)
|
||||
|
||||
def upload(self, with_valid=True):
|
||||
if with_valid:
|
||||
|
|
@ -65,7 +72,13 @@ class FileSerializer(serializers.Serializer):
|
|||
if not meta:
|
||||
meta = {'debug': True}
|
||||
file_id = meta.get('file_id', uuid.uuid7())
|
||||
file = File(id=file_id, file_name=self.data.get('file').name, meta=meta)
|
||||
file = File(
|
||||
id=file_id,
|
||||
file_name=self.data.get('file').name,
|
||||
meta=meta,
|
||||
source_id=self.data.get('source_id') or FileSourceType.TEMPORARY_120_MINUTE.value,
|
||||
source_type=self.data.get('source_type') or FileSourceType.TEMPORARY_120_MINUTE
|
||||
)
|
||||
file.save(self.data.get('file').read())
|
||||
return f'./oss/file/{file_id}'
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,11 @@ class FileView(APIView):
|
|||
)
|
||||
@log(menu='file', operate='Upload file')
|
||||
def post(self, request: Request):
|
||||
return result.success(FileSerializer(data={'file': request.FILES.get('file')}).upload())
|
||||
return result.success(FileSerializer(data={
|
||||
'file': request.FILES.get('file'),
|
||||
'source_id': request.data.get('source_id'),
|
||||
'source_type': request.data.get('source_type'),
|
||||
}).upload())
|
||||
|
||||
class Operate(APIView):
|
||||
authentication_classes = [TokenAuth]
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@
|
|||
<div v-loading="loading">
|
||||
<h4 class="title-decoration-1 mb-8">{{ $t('views.document.setRules.title.preview') }}</h4>
|
||||
|
||||
<ParagraphPreview v-model:data="paragraphList" :isConnect="checkedConnect" />
|
||||
<ParagraphPreview v-model:data="paragraphList" :isConnect="checkedConnect" :knowledge-id="id"/>
|
||||
</div>
|
||||
</el-col>
|
||||
</el-row>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
>
|
||||
<el-row v-if="isConnect">
|
||||
<el-col :span="18" class="p-24">
|
||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
|
||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" :knowledge-id="knowledgeId"/>
|
||||
</el-col>
|
||||
<el-col :span="6" class="border-l" style="width: 300px">
|
||||
<p class="bold title p-24" style="padding-bottom: 0">
|
||||
|
|
@ -52,7 +52,7 @@
|
|||
</el-col>
|
||||
</el-row>
|
||||
<div v-else class="p-24">
|
||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
|
||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" :knowledge-id="knowledgeId"/>
|
||||
</div>
|
||||
|
||||
<template #footer>
|
||||
|
|
@ -69,7 +69,8 @@ import { cloneDeep } from 'lodash'
|
|||
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
|
||||
|
||||
const props = defineProps({
|
||||
isConnect: Boolean
|
||||
isConnect: Boolean,
|
||||
knowledgeId: String
|
||||
})
|
||||
|
||||
const emit = defineEmits(['updateContent'])
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@
|
|||
ref="EditParagraphDialogRef"
|
||||
@updateContent="updateContent"
|
||||
:isConnect="isConnect"
|
||||
:knowledge-id="knowledgeId"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
|
@ -62,7 +63,14 @@ const editHandle = (item: any, cIndex: number) => {
|
|||
EditParagraphDialogRef.value.open(item)
|
||||
}
|
||||
|
||||
const props = defineProps<{ modelValue: Array<any>; isConnect: boolean }>()
|
||||
const props = defineProps({
|
||||
modelValue: {
|
||||
type: Array<any>,
|
||||
default: () => []
|
||||
},
|
||||
isConnect: Boolean,
|
||||
knowledgeId: String
|
||||
})
|
||||
|
||||
const paragraph_list = computed(() => {
|
||||
return props.modelValue.slice(0, page_size.value * (current_page.value - 1) + page_size.value)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@
|
|||
</div>
|
||||
<div class="paragraph-list" v-if="activeName == index">
|
||||
<el-scrollbar>
|
||||
<ParagraphList v-model="item.content" :isConnect="isConnect"> </ParagraphList>
|
||||
<ParagraphList v-model="item.content" :isConnect="isConnect" :knowledge-id="knowledgeId"/>
|
||||
</el-scrollbar>
|
||||
</div>
|
||||
</el-tab-pane>
|
||||
|
|
@ -32,7 +32,8 @@ defineProps({
|
|||
type: Array<any>,
|
||||
default: () => []
|
||||
},
|
||||
isConnect: Boolean
|
||||
isConnect: Boolean,
|
||||
knowledgeId: String
|
||||
})
|
||||
|
||||
const activeName = ref(0)
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
</el-button>
|
||||
</div>
|
||||
|
||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" />
|
||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" :knowledge-id="dataset_id"/>
|
||||
</div>
|
||||
</el-scrollbar>
|
||||
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">
|
||||
|
|
|
|||
|
|
@ -54,7 +54,8 @@ const props = defineProps({
|
|||
type: Object,
|
||||
default: () => {}
|
||||
},
|
||||
isEdit: Boolean
|
||||
isEdit: Boolean,
|
||||
knowledgeId: String
|
||||
})
|
||||
|
||||
const toolbars = [
|
||||
|
|
@ -120,6 +121,7 @@ watch(
|
|||
watch(
|
||||
() => props.isEdit,
|
||||
(value) => {
|
||||
console.log(props.data, props.knowledgeId)
|
||||
if (!value) {
|
||||
paragraphFormRef.value?.clearValidate()
|
||||
}
|
||||
|
|
@ -145,6 +147,8 @@ const onUploadImg = async (files: any, callback: any) => {
|
|||
return new Promise((rev, rej) => {
|
||||
const fd = new FormData()
|
||||
fd.append('file', file)
|
||||
fd.append('source_id', props.knowledgeId as string)
|
||||
fd.append('source_type', 'KNOWLEDGE')
|
||||
|
||||
imageApi
|
||||
.postImage(fd)
|
||||
|
|
|
|||
Loading…
Reference in New Issue