Repository navigation
feat: pdf download #7918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: pdf download #7918
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ import { computed } from 'vue' | |
| import ImageUploadCard from '@/components/mk-drag-upload/ImageUploadCard.vue' | ||
| import DetailContainer from '@/workflow-canvas/execution-details/DetailContainer.vue' | ||
| import BaseHeader from '@/workflow-canvas/execution-details/BaseHeader.vue' | ||
| import { getFileUrl } from '@/utils/common' | ||
| import { downloadByURL, getFileUrl } from '@/utils/common' | ||
| import { getFileIconUrl } from '@/utils/icon' | ||
| import { DOCUMENT_RESOURCE_TYPE, KNOWLEDGE_HIT_UNIT_TYPE } from '@/api/enums' | ||
| import type { DocumentResourceType, KnowledgeHitTestAsset, KnowledgeType } from '@/api/types' | ||
|
|
@@ -56,6 +56,12 @@ function getParagraphImageUrl(paragraph: SearchParagraph) { | |
| if (!fileId || paragraph.content?.includes(`/oss/file/${fileId}`)) return '' | ||
| return getFileUrl(fileId) | ||
| } | ||
|
|
||
| // 来源文件按原文件名下载,网页来源打开原网址。 | ||
| function openSourceDocument(name: string, fileId?: string, sourceUrl?: string) { | ||
| if (fileId) downloadByURL(getFileUrl(fileId), name.trim()) | ||
| else if (sourceUrl && /^https?:\/\//i.test(sourceUrl.trim())) window.open(sourceUrl.trim(), '_blank', 'noopener,noreferrer') | ||
| } | ||
| </script> | ||
|
|
||
| <template> | ||
|
|
@@ -120,32 +126,27 @@ function getParagraphImageUrl(paragraph: SearchParagraph) { | |
| <MdPreview :model-value="paragraph.content" no-img-zoom-in /> | ||
|
|
||
| <!-- 打开来源文档 --> | ||
|
|
||
| <a | ||
| <el-card | ||
| v-if="paragraph.document_name?.trim()" | ||
| :href="paragraph.meta?.source_file_id || paragraph.meta?.source_url || undefined" | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| :download="paragraph.document_name.trim()" | ||
| class="mt-2 block min-w-0" | ||
| shadow="never" | ||
| class="small cursor-pointer mt-2 min-w-0" | ||
| @click="openSourceDocument(paragraph.document_name, paragraph.meta?.source_file_id, paragraph.meta?.source_url)" | ||
| > | ||
| <el-card shadow="never" class="small cursor-pointer"> | ||
| <div class="flex-align-center gap-2"> | ||
| <img | ||
| :src=" | ||
| getFileIconUrl( | ||
| paragraph.document_name.trim(), | ||
| paragraph.knowledge_type, | ||
| paragraph.document_resource_type === DOCUMENT_RESOURCE_TYPE.IMAGE, | ||
| ) | ||
| " | ||
| alt="" | ||
| class="size-6 shrink-0" | ||
| /> | ||
| <span class="min-w-0 truncate" :title="paragraph.document_name.trim()">{{ paragraph.document_name.trim() }}</span> | ||
| </div> | ||
| </el-card> | ||
| </a> | ||
| <div class="flex-align-center gap-2"> | ||
| <img | ||
| :src=" | ||
| getFileIconUrl( | ||
| paragraph.document_name.trim(), | ||
| paragraph.knowledge_type, | ||
| paragraph.document_resource_type === DOCUMENT_RESOURCE_TYPE.IMAGE, | ||
| ) | ||
| " | ||
| alt="" | ||
| class="size-6 shrink-0" | ||
| /> | ||
| <span class="min-w-0 truncate" :title="paragraph.document_name.trim()">{{ paragraph.document_name.trim() }}</span> | ||
| </div> | ||
| </el-card> | ||
|
|
||
| <template #footer> | ||
| <div class="flex-align-center w-full gap-2 border-t pt-2"> | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the code review with identified irregularities, potential issues, and optimization suggestions: 1. Critical Logic/Performance Issue: Repeated
|
||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is an analysis of the code changes, covering irregularities, potential issues, and optimization suggestions.
1. Functional Behavior Change
a[download]) to explicitly triggering a download via a utility functiondownloadByURL.2. Potential Issues & Risks
Implementation Dependency (
downloadByURL):downloadByURLhandles cross-origin URLs correctly. Modern browsers block thedownloadattribute on cross-origin anchor tags. A common approach is fetch + Blob or navigating to a dedicated backend endpoint. IfdownloadByURLjust uses a hidden<a>tag similar to the previous code but forced via JS, it will fail for cross-origin files.downloadByURLusesfetch()to get a Blob, large document lists will consume significant memory and bandwidth simultaneously if clicked rapidly. There is no apparent debouncing or loading state shown.Security/Logic Gap:
@click="f.url && downloadByURL(...)".f.urlis undefined/falsy, nothing happens when clicked.cursor-pointer) was inside the card, implying interactivity even if the link was broken. Now, you applycursor-pointerto the wrapper unconditionally, creating a "dead zone" where the UI looks clickable but does nothing if the data is malformed. Consider adding a condition to disable interaction if!f.url.3. Irregularities / Code Style
Repeated Logic & Duplication:
data.document_listanddata.other_list) with identical markup and logic.Semantic HTML Loss:
<a>with adiv-based element (insideel-card) removes native accessibility semantics related to links. While less critical since the action isn't navigation (it's a download), it breaks right-click functionality ("Open link in tabs") if the user expects standard web behaviors.4. Optimization Suggestions
1. Extract a Component
Since both sections render exactly the same component structure: create a reusable functional component or simple SFC.
Before: Two nearly identical template blocks.
After:
2. Better Event Handling
Instead of complex expressions in the template
@click, define a handler in the script for cleaner separation of concerns and easier debugging (e.g., error handling if download fails).Template:
Script:
3. Conditional Rendering Improvement
Fix the "Dead Zone" issue by conditionally binding classes or rendering:
Current (Problematic):
Suggested: