Skip to content

Commit be2e1c3

Browse files
author
dterefe
committed
Cleanup output file name adressing.
1 parent bcb6933 commit be2e1c3

File tree

1 file changed

+55
-21
lines changed

1 file changed

+55
-21
lines changed

DUUIWeb/src/lib/svelte/components/Drawer/DocumentDrawer.svelte

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,55 @@
4949
let annotationFilter: Map<string, number> = new Map(Object.entries(_document.annotations || {}))
5050
let downloading: boolean = false
5151
52+
function getOutputName(
53+
name: string,
54+
inputExtension: string,
55+
outputExtension: string
56+
): string {
57+
if (!name) return name
58+
59+
const inExt = inputExtension ?? ''
60+
const outExt = outputExtension ?? ''
61+
62+
// If it already ends with the desired extension, keep it.
63+
if (outExt && name.endsWith(outExt)) return name
64+
65+
// If it ends with the input extension, swap just that suffix.
66+
if (inExt && name.endsWith(inExt)) {
67+
return name.slice(0, -inExt.length) + outExt
68+
}
69+
70+
// Fallback: replace the last extension segment, if any.
71+
if (outExt) {
72+
const dotIndex = name.lastIndexOf('.')
73+
if (dotIndex > 0) {
74+
return name.slice(0, dotIndex) + outExt
75+
}
76+
}
77+
78+
return name
79+
}
80+
81+
// Reactive full output path for display in the top bar
82+
$: fullOutputPath = (() => {
83+
const outputName = getOutputName(_document.name, input.file_extension, output.file_extension)
84+
85+
// If we have an output path, append the (possibly rewritten) name
86+
if (output.path && outputName) {
87+
const extraSlash = output.path.endsWith('/') ? '' : '/'
88+
return `${output.path}${extraSlash}${outputName}`
89+
}
90+
91+
// Fallbacks: use document path or name as stored
92+
return _document.path || outputName || _document.name
93+
})()
94+
5295
const download = async () => {
5396
downloading = true
54-
const extraSlash = output.path.endsWith("/") ? "" : "/"
97+
const extraSlash = output.path.endsWith('/') ? '' : '/'
98+
const outputName = getOutputName(_document.name, input.file_extension, output.file_extension)
5599
const response = await fetch(
56-
`/api/files/download?provider=${output.provider}}&provider_id=${output.provider_id}&path=${output.path + extraSlash}${_document.name.replace(
57-
input.file_extension,
58-
output.file_extension
59-
)}`,
100+
`/api/files/download?provider=${output.provider}}&provider_id=${output.provider_id}&path=${output.path + extraSlash}${outputName}`,
60101
{
61102
method: 'GET'
62103
}
@@ -67,7 +108,7 @@
67108
const url = URL.createObjectURL(blob)
68109
const anchor = document.createElement('a')
69110
anchor.href = url
70-
anchor.download = _document.name.replace(input.file_extension, output.file_extension)
111+
anchor.download = outputName
71112
document.body.appendChild(anchor)
72113
anchor.click()
73114
document.body.removeChild(anchor)
@@ -160,12 +201,9 @@
160201
161202
const preprocessDocument = async () => {
162203
processingText = true
163-
164-
const extraSlash = output.path.endsWith("/") ? "" : "/"
165-
const filePath = `/api/files/preprocess?provider=${output.provider}&provider_id=${output.provider_id}&path=${output.path + extraSlash}${_document.name.replace(
166-
input.file_extension,
167-
output.file_extension
168-
)}&pipeline_id=${pipeline.oid}`
204+
const extraSlash = output.path.endsWith('/') ? '' : '/'
205+
const outputName = getOutputName(_document.name, input.file_extension, output.file_extension)
206+
const filePath = `/api/files/preprocess?provider=${output.provider}&provider_id=${output.provider_id}&path=${output.path + extraSlash}${outputName}&pipeline_id=${pipeline.oid}`
169207
170208
let json: {
171209
text: string
@@ -297,16 +335,12 @@
297335
class="w-full z-50 grid
298336
font-bold text-2xl p-4 border-surface-200 dark:border-surface-500 sm:flex items-center justify-start gap-4 sticky top-0 bg-surface-100-800-token border-b border-color"
299337
>
300-
<div class="flex-center-4">
301-
<Fa icon={getStatusIcon(_document.status)} size="lg" class="dimmed" />
302-
{#if input.provider === IO.File}
303-
<p class="text-sm md:text-base max-w-[10ch]">
304-
{_document.name}
338+
<div class="flex-center-4">
339+
<Fa icon={getStatusIcon(_document.status)} size="lg" class="dimmed" />
340+
<p class="text-sm md:text-base break-all">
341+
{fullOutputPath}
305342
</p>
306-
{:else}
307-
<p class="text-sm md:text-base">{_document.path}</p>
308-
{/if}
309-
</div>
343+
</div>
310344
<div class="ml-auto justify-start items-center gap-4 flex">
311345
{#if output.provider !== IO.None && _document.status === Status.Completed}
312346
{#if downloading}

0 commit comments

Comments
 (0)