|
49 | 49 | let annotationFilter: Map<string, number> = new Map(Object.entries(_document.annotations || {})) |
50 | 50 | let downloading: boolean = false |
51 | 51 |
|
| 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 | +
|
52 | 95 | const download = async () => { |
53 | 96 | 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) |
55 | 99 | 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}`, |
60 | 101 | { |
61 | 102 | method: 'GET' |
62 | 103 | } |
|
67 | 108 | const url = URL.createObjectURL(blob) |
68 | 109 | const anchor = document.createElement('a') |
69 | 110 | anchor.href = url |
70 | | - anchor.download = _document.name.replace(input.file_extension, output.file_extension) |
| 111 | + anchor.download = outputName |
71 | 112 | document.body.appendChild(anchor) |
72 | 113 | anchor.click() |
73 | 114 | document.body.removeChild(anchor) |
|
160 | 201 |
|
161 | 202 | const preprocessDocument = async () => { |
162 | 203 | 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}` |
169 | 207 |
|
170 | 208 | let json: { |
171 | 209 | text: string |
|
297 | 335 | class="w-full z-50 grid |
298 | 336 | 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" |
299 | 337 | > |
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} |
305 | 342 | </p> |
306 | | - {:else} |
307 | | - <p class="text-sm md:text-base">{_document.path}</p> |
308 | | - {/if} |
309 | | - </div> |
| 343 | + </div> |
310 | 344 | <div class="ml-auto justify-start items-center gap-4 flex"> |
311 | 345 | {#if output.provider !== IO.None && _document.status === Status.Completed} |
312 | 346 | {#if downloading} |
|
0 commit comments