Skip to content

Commit 51a29a9

Browse files
committed
fix: Knowledge source redirection failed
1 parent afaf3d6 commit 51a29a9

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
lines changed

ui/src/components/ai-chat/KnowledgeSource.vue

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,7 @@
2121
</div>
2222
<div class="ml-8" v-else>
2323
<a
24-
:href="
25-
item.source_url && !item.source_url.endsWith('/')
26-
? item.source_url + '/'
27-
: item.source_url
28-
"
24+
:href="getNormalizedUrl(item?.source_url)"
2925
target="_blank"
3026
class="ellipsis"
3127
:title="item?.document_name?.trim()"
@@ -43,7 +39,9 @@
4339

4440
<div class="border-t color-secondary flex-between mt-12" style="padding-top: 12px">
4541
<div>
46-
<span class="mr-8"> {{ $t('chat.KnowledgeSource.consume') }}: {{ data?.message_tokens + data?.answer_tokens }} </span>
42+
<span class="mr-8">
43+
{{ $t('chat.KnowledgeSource.consume') }}: {{ data?.message_tokens + data?.answer_tokens }}
44+
</span>
4745
<span> {{ $t('chat.KnowledgeSource.consumeTime') }}: {{ data?.run_time?.toFixed(2) }} s</span>
4846
</div>
4947
<el-button
@@ -66,7 +64,7 @@ import { computed, ref } from 'vue'
6664
import ParagraphSourceDialog from './ParagraphSourceDialog.vue'
6765
import ExecutionDetailDialog from './ExecutionDetailDialog.vue'
6866
import { isWorkFlow } from '@/utils/application'
69-
import { getImgUrl } from '@/utils/utils'
67+
import { getImgUrl, getNormalizedUrl } from '@/utils/utils'
7068
const props = defineProps({
7169
data: {
7270
type: Object,

ui/src/components/ai-chat/component/ParagraphCard.vue

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,7 @@
2222

2323
<template v-if="meta?.source_url">
2424
<a
25-
:href="
26-
meta?.source_url && !meta?.source_url.endsWith('/')
27-
? meta?.source_url + '/'
28-
: meta?.source_url
29-
"
25+
:href="getNormalizedUrl(meta?.source_url)"
3026
target="_blank"
3127
class="ellipsis-1 break-all"
3228
:title="data?.document_name?.trim()"
@@ -54,7 +50,7 @@
5450
</CardBox>
5551
</template>
5652
<script setup lang="ts">
57-
import { getImgUrl } from '@/utils/utils'
53+
import { getImgUrl, getNormalizedUrl } from '@/utils/utils'
5854
import { computed } from 'vue'
5955
6056
const props = defineProps({
@@ -94,6 +90,7 @@ const meta = computed(() => (isMetaObject.value ? props.data.meta : parsedMeta.v
9490
}
9591
}
9692
}
93+
9794
.paragraph-source-card-height {
9895
height: 260px;
9996
}
@@ -105,6 +102,7 @@ const meta = computed(() => (isMetaObject.value ? props.data.meta : parsedMeta.v
105102
.paragraph-source-card {
106103
.footer-content {
107104
display: block;
105+
108106
.item {
109107
max-width: 100%;
110108
}

ui/src/utils/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,10 @@ export function cutFilename(filename: string, num: number) {
106106
const suffix = lastIndex === -1 ? '' : filename.substring(lastIndex + 1)
107107
return filename.substring(0, num - suffix.length - 1) + '.' + suffix
108108
}
109+
110+
export function getNormalizedUrl(url: string) {
111+
if (url && !url.endsWith('/') && !/\.[^/]+$/.test(url)) {
112+
return url + '/'
113+
}
114+
return url
115+
}

0 commit comments

Comments
 (0)