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 rest_framework import serializers
|
||||||
|
|
||||||
from common.exception.app_exception import NotFound404
|
from common.exception.app_exception import NotFound404
|
||||||
from knowledge.models import File
|
from knowledge.models import File, FileSourceType
|
||||||
from tools.serializers.tool import UploadedFileField
|
from tools.serializers.tool import UploadedFileField
|
||||||
|
|
||||||
mime_types = {
|
mime_types = {
|
||||||
@ -57,6 +57,13 @@ mime_types = {
|
|||||||
class FileSerializer(serializers.Serializer):
|
class FileSerializer(serializers.Serializer):
|
||||||
file = UploadedFileField(required=True, label=_('file'))
|
file = UploadedFileField(required=True, label=_('file'))
|
||||||
meta = serializers.JSONField(required=False, allow_null=True)
|
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):
|
def upload(self, with_valid=True):
|
||||||
if with_valid:
|
if with_valid:
|
||||||
@ -65,7 +72,13 @@ class FileSerializer(serializers.Serializer):
|
|||||||
if not meta:
|
if not meta:
|
||||||
meta = {'debug': True}
|
meta = {'debug': True}
|
||||||
file_id = meta.get('file_id', uuid.uuid7())
|
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())
|
file.save(self.data.get('file').read())
|
||||||
return f'./oss/file/{file_id}'
|
return f'./oss/file/{file_id}'
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,11 @@ class FileView(APIView):
|
|||||||
)
|
)
|
||||||
@log(menu='file', operate='Upload file')
|
@log(menu='file', operate='Upload file')
|
||||||
def post(self, request: Request):
|
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):
|
class Operate(APIView):
|
||||||
authentication_classes = [TokenAuth]
|
authentication_classes = [TokenAuth]
|
||||||
|
|||||||
@ -112,7 +112,7 @@
|
|||||||
<div v-loading="loading">
|
<div v-loading="loading">
|
||||||
<h4 class="title-decoration-1 mb-8">{{ $t('views.document.setRules.title.preview') }}</h4>
|
<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>
|
</div>
|
||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
>
|
>
|
||||||
<el-row v-if="isConnect">
|
<el-row v-if="isConnect">
|
||||||
<el-col :span="18" class="p-24">
|
<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>
|
||||||
<el-col :span="6" class="border-l" style="width: 300px">
|
<el-col :span="6" class="border-l" style="width: 300px">
|
||||||
<p class="bold title p-24" style="padding-bottom: 0">
|
<p class="bold title p-24" style="padding-bottom: 0">
|
||||||
@ -52,7 +52,7 @@
|
|||||||
</el-col>
|
</el-col>
|
||||||
</el-row>
|
</el-row>
|
||||||
<div v-else class="p-24">
|
<div v-else class="p-24">
|
||||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
|
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" :knowledge-id="knowledgeId"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
@ -69,7 +69,8 @@ import { cloneDeep } from 'lodash'
|
|||||||
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
|
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
isConnect: Boolean
|
isConnect: Boolean,
|
||||||
|
knowledgeId: String
|
||||||
})
|
})
|
||||||
|
|
||||||
const emit = defineEmits(['updateContent'])
|
const emit = defineEmits(['updateContent'])
|
||||||
|
|||||||
@ -42,6 +42,7 @@
|
|||||||
ref="EditParagraphDialogRef"
|
ref="EditParagraphDialogRef"
|
||||||
@updateContent="updateContent"
|
@updateContent="updateContent"
|
||||||
:isConnect="isConnect"
|
:isConnect="isConnect"
|
||||||
|
:knowledge-id="knowledgeId"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@ -62,7 +63,14 @@ const editHandle = (item: any, cIndex: number) => {
|
|||||||
EditParagraphDialogRef.value.open(item)
|
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(() => {
|
const paragraph_list = computed(() => {
|
||||||
return props.modelValue.slice(0, page_size.value * (current_page.value - 1) + page_size.value)
|
return props.modelValue.slice(0, page_size.value * (current_page.value - 1) + page_size.value)
|
||||||
|
|||||||
@ -15,7 +15,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="paragraph-list" v-if="activeName == index">
|
<div class="paragraph-list" v-if="activeName == index">
|
||||||
<el-scrollbar>
|
<el-scrollbar>
|
||||||
<ParagraphList v-model="item.content" :isConnect="isConnect"> </ParagraphList>
|
<ParagraphList v-model="item.content" :isConnect="isConnect" :knowledge-id="knowledgeId"/>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
</div>
|
</div>
|
||||||
</el-tab-pane>
|
</el-tab-pane>
|
||||||
@ -32,7 +32,8 @@ defineProps({
|
|||||||
type: Array<any>,
|
type: Array<any>,
|
||||||
default: () => []
|
default: () => []
|
||||||
},
|
},
|
||||||
isConnect: Boolean
|
isConnect: Boolean,
|
||||||
|
knowledgeId: String
|
||||||
})
|
})
|
||||||
|
|
||||||
const activeName = ref(0)
|
const activeName = ref(0)
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
</el-button>
|
</el-button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" />
|
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" :knowledge-id="dataset_id"/>
|
||||||
</div>
|
</div>
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">
|
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">
|
||||||
|
|||||||
@ -54,7 +54,8 @@ const props = defineProps({
|
|||||||
type: Object,
|
type: Object,
|
||||||
default: () => {}
|
default: () => {}
|
||||||
},
|
},
|
||||||
isEdit: Boolean
|
isEdit: Boolean,
|
||||||
|
knowledgeId: String
|
||||||
})
|
})
|
||||||
|
|
||||||
const toolbars = [
|
const toolbars = [
|
||||||
@ -120,6 +121,7 @@ watch(
|
|||||||
watch(
|
watch(
|
||||||
() => props.isEdit,
|
() => props.isEdit,
|
||||||
(value) => {
|
(value) => {
|
||||||
|
console.log(props.data, props.knowledgeId)
|
||||||
if (!value) {
|
if (!value) {
|
||||||
paragraphFormRef.value?.clearValidate()
|
paragraphFormRef.value?.clearValidate()
|
||||||
}
|
}
|
||||||
@ -145,6 +147,8 @@ const onUploadImg = async (files: any, callback: any) => {
|
|||||||
return new Promise((rev, rej) => {
|
return new Promise((rev, rej) => {
|
||||||
const fd = new FormData()
|
const fd = new FormData()
|
||||||
fd.append('file', file)
|
fd.append('file', file)
|
||||||
|
fd.append('source_id', props.knowledgeId as string)
|
||||||
|
fd.append('source_type', 'KNOWLEDGE')
|
||||||
|
|
||||||
imageApi
|
imageApi
|
||||||
.postImage(fd)
|
.postImage(fd)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user