Skip to content

Commit b40c76d

Browse files
authored
fix: PDF Preview (#3504)
1 parent 754c309 commit b40c76d

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

apps/oss/serializers/file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def get(self, with_valid=True):
9696
content_type = mime_types.get(file_type, 'application/octet-stream')
9797
headers = {
9898
'Content-Type': content_type,
99-
'Content-Disposition': f'attachment; filename="{file.file_name}"'
99+
'Content-Disposition': f'{"inline" if file_type == "pdf" else "attachment"}; filename="{file.file_name}"'
100100
}
101101
return HttpResponse(
102102
file.get_bytes(),

ui/src/components/ai-chat/component/knowledge-source-component/index.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
<div
2121
class="ml-4 ellipsis-1"
2222
:title="item?.document_name"
23-
v-if="!item.source_url"
23+
v-if="showPDF(item)"
2424
@click="openParagraphDocument(item)"
2525
>
2626
<p>{{ item && item?.document_name }}</p>
2727
</div>
2828
<div class="ml-8" v-else>
2929
<a
30-
:href="getNormalizedUrl(item?.source_url)"
30+
:href="getFileUrl(item?.meta?.source_file_id)"
3131
target="_blank"
3232
class="ellipsis-1"
3333
:title="item?.document_name?.trim()"
@@ -89,7 +89,7 @@ import ExecutionDetailContent from './ExecutionDetailContent.vue'
8989
import ParagraphDocumentContent from './ParagraphDocumentContent.vue'
9090
import ParagraphSourceContent from './ParagraphSourceContent.vue'
9191
import { arraySort } from '@/utils/array'
92-
import { getImgUrl, getNormalizedUrl } from '@/utils/common'
92+
import { getImgUrl, getFileUrl } from '@/utils/common'
9393
import { t } from '@/locales'
9494
const props = defineProps({
9595
data: {
@@ -107,7 +107,9 @@ const props = defineProps({
107107
})
108108
109109
const emit = defineEmits(['openExecutionDetail', 'openParagraph', 'openParagraphDocument'])
110-
110+
const showPDF = (item: any) => {
111+
return item.document_name.toLocaleLowerCase().endsWith('.pdf') && item.meta?.source_file_id
112+
}
111113
const dialogVisible = ref(false)
112114
const dialogTitle = ref('')
113115
const currentComponent = shallowRef<any>(null)

ui/src/utils/common.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ export function getNormalizedUrl(url: string) {
143143
}
144144
return url
145145
}
146+
export function getFileUrl(fileId?: string) {
147+
if (fileId) {
148+
return `${window.MaxKB.prefix}/oss/file/${fileId}`
149+
}
150+
return ''
151+
}
146152
export const resetUrl = (url: string, defaultUrl?: string) => {
147153
if (url && url.startsWith('./')) {
148154
return `${window.MaxKB.prefix}/${url.substring(2)}`

0 commit comments

Comments
 (0)