feat: fit DICOM previews and show searchable file metadata
This commit is contained in:
1 parent
7a1d18dfc6
commit
a69fdf2e09
17 files changed
+471
-221
No files matched your search
@@ -1,5 +1,10 @@
|
||||
<template>
|
||||
<div class="document-viewer" @wheel.stop @touchmove.stop @keydown.stop>
|
||||
<div
|
||||
class="document-viewer dicom-viewer"
|
||||
@wheel.stop
|
||||
@touchmove.stop
|
||||
@keydown.stop
|
||||
>
|
||||
<div class="document-tools">
|
||||
<strong>DICOM</strong>
|
||||
<template v-if="ready">
|
||||
@@ -39,6 +44,7 @@
|
||||
import { nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import DicomWorker from "@/utils/dicom.worker?worker";
|
||||
import { readDicomFile } from "@/utils/dicom-file";
|
||||
const props = defineProps<{ source: string }>();
|
||||
const { t } = useI18n();
|
||||
const canvas = ref<HTMLCanvasElement>();
|
||||
@@ -100,35 +106,8 @@ watch(
|
||||
controller = new AbortController();
|
||||
const signal = controller.signal;
|
||||
try {
|
||||
const response = await fetch(source, {
|
||||
credentials: "same-origin",
|
||||
signal,
|
||||
});
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const limit = 64 * 1024 * 1024;
|
||||
if (Number(response.headers.get("Content-Length")) > limit)
|
||||
throw new Error(t("documents.tooLarge"));
|
||||
const reader = response.body?.getReader();
|
||||
if (!reader) throw new Error(t("documents.loadFailed"));
|
||||
const chunks: Uint8Array[] = [];
|
||||
let length = 0;
|
||||
while (true) {
|
||||
const chunk = await reader.read();
|
||||
if (chunk.done) break;
|
||||
length += chunk.value.length;
|
||||
if (length > limit) {
|
||||
await reader.cancel();
|
||||
throw new Error(t("documents.tooLarge"));
|
||||
}
|
||||
chunks.push(chunk.value);
|
||||
}
|
||||
const buffer = await readDicomFile(source, signal);
|
||||
if (signal.aborted || id !== sequence) return;
|
||||
const data = new Uint8Array(length);
|
||||
let offset = 0;
|
||||
for (const chunk of chunks) {
|
||||
data.set(chunk, offset);
|
||||
offset += chunk.length;
|
||||
}
|
||||
worker = new DicomWorker();
|
||||
timeout = setTimeout(() => {
|
||||
error.value = t("documents.loadFailed");
|
||||
@@ -167,11 +146,15 @@ watch(
|
||||
0
|
||||
);
|
||||
};
|
||||
worker.postMessage({ id, buffer: data.buffer }, [data.buffer]);
|
||||
worker.postMessage({ id, buffer }, [buffer]);
|
||||
} catch (e) {
|
||||
if (!signal.aborted && id === sequence)
|
||||
error.value =
|
||||
e instanceof Error ? e.message : t("documents.loadFailed");
|
||||
e instanceof Error && e.message === "DICOM_TOO_LARGE"
|
||||
? t("documents.tooLarge")
|
||||
: e instanceof Error
|
||||
? e.message
|
||||
: t("documents.loadFailed");
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
|
||||
Reference in new issue
Block a user