fix: PDF Preview (#3504)

This commit is contained in:
shaohuzhang1 2025-07-08 10:52:27 +08:00 committed by GitHub
parent 754c309b52
commit b40c76d3f3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 13 additions and 5 deletions

View File

@ -96,7 +96,7 @@ class FileSerializer(serializers.Serializer):
content_type = mime_types.get(file_type, 'application/octet-stream')
headers = {
'Content-Type': content_type,
'Content-Disposition': f'attachment; filename="{file.file_name}"'
'Content-Disposition': f'{"inline" if file_type == "pdf" else "attachment"}; filename="{file.file_name}"'
}
return HttpResponse(
file.get_bytes(),

View File

@ -20,14 +20,14 @@
<div
class="ml-4 ellipsis-1"
:title="item?.document_name"
v-if="!item.source_url"
v-if="showPDF(item)"
@click="openParagraphDocument(item)"
>
<p>{{ item && item?.document_name }}</p>
</div>
<div class="ml-8" v-else>
<a
:href="getNormalizedUrl(item?.source_url)"
:href="getFileUrl(item?.meta?.source_file_id)"
target="_blank"
class="ellipsis-1"
:title="item?.document_name?.trim()"
@ -89,7 +89,7 @@ import ExecutionDetailContent from './ExecutionDetailContent.vue'
import ParagraphDocumentContent from './ParagraphDocumentContent.vue'
import ParagraphSourceContent from './ParagraphSourceContent.vue'
import { arraySort } from '@/utils/array'
import { getImgUrl, getNormalizedUrl } from '@/utils/common'
import { getImgUrl, getFileUrl } from '@/utils/common'
import { t } from '@/locales'
const props = defineProps({
data: {
@ -107,7 +107,9 @@ const props = defineProps({
})
const emit = defineEmits(['openExecutionDetail', 'openParagraph', 'openParagraphDocument'])
const showPDF = (item: any) => {
return item.document_name.toLocaleLowerCase().endsWith('.pdf') && item.meta?.source_file_id
}
const dialogVisible = ref(false)
const dialogTitle = ref('')
const currentComponent = shallowRef<any>(null)

View File

@ -143,6 +143,12 @@ export function getNormalizedUrl(url: string) {
}
return url
}
export function getFileUrl(fileId?: string) {
if (fileId) {
return `${window.MaxKB.prefix}/oss/file/${fileId}`
}
return ''
}
export const resetUrl = (url: string, defaultUrl?: string) => {
if (url && url.startsWith('./')) {
return `${window.MaxKB.prefix}/${url.substring(2)}`