mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 10:12:51 +00:00
fix: PDF Preview (#3504)
This commit is contained in:
parent
754c309b52
commit
b40c76d3f3
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)}`
|
||||
|
|
|
|||
Loading…
Reference in New Issue