Skip to content

Commit 79dc3e4

Browse files
committed
feat: add source_id and source_type fields to FileSerializer and update related components
1 parent 50cc851 commit 79dc3e4

File tree

8 files changed

+43
-12
lines changed

8 files changed

+43
-12
lines changed

apps/oss/serializers/file.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from rest_framework import serializers
88

99
from common.exception.app_exception import NotFound404
10-
from knowledge.models import File
10+
from knowledge.models import File, FileSourceType
1111
from tools.serializers.tool import UploadedFileField
1212

1313
mime_types = {
@@ -57,6 +57,13 @@
5757
class FileSerializer(serializers.Serializer):
5858
file = UploadedFileField(required=True, label=_('file'))
5959
meta = serializers.JSONField(required=False, allow_null=True)
60+
source_id = serializers.CharField(
61+
required=False, allow_null=True, label=_('source id'), default=FileSourceType.TEMPORARY_120_MINUTE.value
62+
)
63+
source_type = serializers.ChoiceField(
64+
choices=FileSourceType.choices, required=False, allow_null=True, label=_('source type'),
65+
default=FileSourceType.TEMPORARY_120_MINUTE
66+
)
6067

6168
def upload(self, with_valid=True):
6269
if with_valid:
@@ -65,7 +72,13 @@ def upload(self, with_valid=True):
6572
if not meta:
6673
meta = {'debug': True}
6774
file_id = meta.get('file_id', uuid.uuid7())
68-
file = File(id=file_id, file_name=self.data.get('file').name, meta=meta)
75+
file = File(
76+
id=file_id,
77+
file_name=self.data.get('file').name,
78+
meta=meta,
79+
source_id=self.data.get('source_id') or FileSourceType.TEMPORARY_120_MINUTE.value,
80+
source_type=self.data.get('source_type') or FileSourceType.TEMPORARY_120_MINUTE
81+
)
6982
file.save(self.data.get('file').read())
7083
return f'./oss/file/{file_id}'
7184

apps/oss/views/file.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ class FileView(APIView):
4242
)
4343
@log(menu='file', operate='Upload file')
4444
def post(self, request: Request):
45-
return result.success(FileSerializer(data={'file': request.FILES.get('file')}).upload())
45+
return result.success(FileSerializer(data={
46+
'file': request.FILES.get('file'),
47+
'source_id': request.data.get('source_id'),
48+
'source_type': request.data.get('source_type'),
49+
}).upload())
4650

4751
class Operate(APIView):
4852
authentication_classes = [TokenAuth]

ui/src/views/document/upload/SetRules.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
<div v-loading="loading">
113113
<h4 class="title-decoration-1 mb-8">{{ $t('views.document.setRules.title.preview') }}</h4>
114114

115-
<ParagraphPreview v-model:data="paragraphList" :isConnect="checkedConnect" />
115+
<ParagraphPreview v-model:data="paragraphList" :isConnect="checkedConnect" :knowledge-id="id"/>
116116
</div>
117117
</el-col>
118118
</el-row>

ui/src/views/knowledge/component/EditParagraphDialog.vue

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
>
1111
<el-row v-if="isConnect">
1212
<el-col :span="18" class="p-24">
13-
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
13+
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" :knowledge-id="knowledgeId"/>
1414
</el-col>
1515
<el-col :span="6" class="border-l" style="width: 300px">
1616
<p class="bold title p-24" style="padding-bottom: 0">
@@ -52,7 +52,7 @@
5252
</el-col>
5353
</el-row>
5454
<div v-else class="p-24">
55-
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" />
55+
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="true" :knowledge-id="knowledgeId"/>
5656
</div>
5757

5858
<template #footer>
@@ -69,7 +69,8 @@ import { cloneDeep } from 'lodash'
6969
import ParagraphForm from '@/views/paragraph/component/ParagraphForm.vue'
7070
7171
const props = defineProps({
72-
isConnect: Boolean
72+
isConnect: Boolean,
73+
knowledgeId: String
7374
})
7475
7576
const emit = defineEmits(['updateContent'])

ui/src/views/knowledge/component/ParagraphList.vue

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
ref="EditParagraphDialogRef"
4343
@updateContent="updateContent"
4444
:isConnect="isConnect"
45+
:knowledge-id="knowledgeId"
4546
/>
4647
</div>
4748
</template>
@@ -62,7 +63,14 @@ const editHandle = (item: any, cIndex: number) => {
6263
EditParagraphDialogRef.value.open(item)
6364
}
6465
65-
const props = defineProps<{ modelValue: Array<any>; isConnect: boolean }>()
66+
const props = defineProps({
67+
modelValue: {
68+
type: Array<any>,
69+
default: () => []
70+
},
71+
isConnect: Boolean,
72+
knowledgeId: String
73+
})
6674
6775
const paragraph_list = computed(() => {
6876
return props.modelValue.slice(0, page_size.value * (current_page.value - 1) + page_size.value)

ui/src/views/knowledge/component/ParagraphPreview.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
</div>
1616
<div class="paragraph-list" v-if="activeName == index">
1717
<el-scrollbar>
18-
<ParagraphList v-model="item.content" :isConnect="isConnect"> </ParagraphList>
18+
<ParagraphList v-model="item.content" :isConnect="isConnect" :knowledge-id="knowledgeId"/>
1919
</el-scrollbar>
2020
</div>
2121
</el-tab-pane>
@@ -32,7 +32,8 @@ defineProps({
3232
type: Array<any>,
3333
default: () => []
3434
},
35-
isConnect: Boolean
35+
isConnect: Boolean,
36+
knowledgeId: String
3637
})
3738
3839
const activeName = ref(0)

ui/src/views/paragraph/component/ParagraphDialog.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</el-button>
2020
</div>
2121

22-
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" />
22+
<ParagraphForm ref="paragraphFormRef" :data="detail" :isEdit="isEdit" :knowledge-id="dataset_id"/>
2323
</div>
2424
</el-scrollbar>
2525
<div class="text-right p-24 pt-0" v-if="paragraphId && isEdit">

ui/src/views/paragraph/component/ParagraphForm.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ const props = defineProps({
5454
type: Object,
5555
default: () => {}
5656
},
57-
isEdit: Boolean
57+
isEdit: Boolean,
58+
knowledgeId: String
5859
})
5960
6061
const toolbars = [
@@ -120,6 +121,7 @@ watch(
120121
watch(
121122
() => props.isEdit,
122123
(value) => {
124+
console.log(props.data, props.knowledgeId)
123125
if (!value) {
124126
paragraphFormRef.value?.clearValidate()
125127
}
@@ -145,6 +147,8 @@ const onUploadImg = async (files: any, callback: any) => {
145147
return new Promise((rev, rej) => {
146148
const fd = new FormData()
147149
fd.append('file', file)
150+
fd.append('source_id', props.knowledgeId as string)
151+
fd.append('source_type', 'KNOWLEDGE')
148152
149153
imageApi
150154
.postImage(fd)

0 commit comments

Comments
 (0)