feat: polish workspace transfers and verify Craft server file workflows
This commit is contained in:
1 parent
7fd7ae6733
commit
c209f1effc
49 files changed
+1459
-670
No files matched your search
@@ -3,6 +3,10 @@ import { baseURL } from "@/utils/constants";
|
||||
import { upload as postTus, useTus } from "./tus";
|
||||
import { createURL, fetchURL, removePrefix, StatusError } from "./utils";
|
||||
import { isEncodableResponse, makeRawResource } from "@/utils/encodings";
|
||||
const resourceUploads = new Set<XMLHttpRequest>();
|
||||
export function abortResourceUploads() {
|
||||
for (const request of resourceUploads) request.abort();
|
||||
}
|
||||
|
||||
export async function fetch(url: string, signal?: AbortSignal) {
|
||||
const encoding = isEncodableResponse(url);
|
||||
@@ -140,6 +144,9 @@ async function postResources(
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
const request = new XMLHttpRequest();
|
||||
resourceUploads.add(request);
|
||||
request.onloadend = () => resourceUploads.delete(request);
|
||||
request.onabort = () => reject(new Error("Upload aborted"));
|
||||
request.open(
|
||||
"POST",
|
||||
`${baseURL}/api/resources${url}?override=${overwrite}`,
|
||||
|
||||
@@ -29,7 +29,10 @@ const tools = computed(() =>
|
||||
auth.user?.perm.modify
|
||||
? store.items.filter(
|
||||
(item) =>
|
||||
item.enabled && item.build && addonAccepts(item, props.file!.name)
|
||||
item.enabled &&
|
||||
!item.compatibilityIssue &&
|
||||
item.build &&
|
||||
addonAccepts(item, props.file!.name)
|
||||
)
|
||||
: []
|
||||
);
|
||||
|
||||
@@ -177,7 +177,7 @@ watch(selectedEncoding, () => {
|
||||
background-color: var(--surfacePrimary);
|
||||
color: var(--textSecondary);
|
||||
padding: 1rem;
|
||||
padding-top: 4em;
|
||||
padding-top: 1rem;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
|
||||
@@ -80,6 +80,7 @@ import { readDicomFile } from "@/utils/dicom-file";
|
||||
import { findDicomSeries } from "@/utils/dicom-context";
|
||||
import { loadDicomVolume } from "@/utils/dicom-volume";
|
||||
import type { DicomSource, DicomVolume } from "@/utils/dicom-series";
|
||||
import { DICOM_3D_ENABLED } from "@/utils/dicom-series";
|
||||
const DicomVolumeViewer = defineAsyncComponent({
|
||||
loader: () => import("./DicomVolumeViewer.vue"),
|
||||
onError: (_error, _retry, fail) => {
|
||||
@@ -108,6 +109,7 @@ function volumeFailed() {
|
||||
volumeError.value = t("documents.volumeUnavailable");
|
||||
}
|
||||
async function openVolume() {
|
||||
if (!DICOM_3D_ENABLED) return;
|
||||
closeVolume();
|
||||
volumeError.value = "";
|
||||
const probe = document.createElement("canvas");
|
||||
@@ -149,7 +151,7 @@ watch(
|
||||
closeVolume();
|
||||
volumeError.value = "";
|
||||
series.value = [];
|
||||
if (!resource) return;
|
||||
if (!resource || !DICOM_3D_ENABLED) return;
|
||||
const request = (seriesController = new AbortController());
|
||||
try {
|
||||
const found = await findDicomSeries(resource, request.signal);
|
||||
|
||||
@@ -0,0 +1,319 @@
|
||||
<template>
|
||||
<div
|
||||
class="server-picker-backdrop"
|
||||
@keydown.esc.stop.prevent="$emit('cancel')"
|
||||
@keydown.tab="trapFocus"
|
||||
@click.self="$emit('cancel')"
|
||||
>
|
||||
<section
|
||||
class="server-picker"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
:aria-label="t('addons.serverOpen')"
|
||||
ref="dialog"
|
||||
tabindex="-1"
|
||||
>
|
||||
<div class="picker-header">
|
||||
<div>
|
||||
<h2>{{ t("addons.serverOpen") }}</h2>
|
||||
<p>{{ t("addons.serverOpenHint") }}</p>
|
||||
</div>
|
||||
<button
|
||||
class="action"
|
||||
:aria-label="t('buttons.close')"
|
||||
@click="$emit('cancel')"
|
||||
>
|
||||
<AppIcon name="close" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="picker-toolbar">
|
||||
<button class="action" :disabled="path === '/' || busy" @click="parent">
|
||||
<AppIcon name="arrow_upward" /></button
|
||||
><span :title="path">{{ path }}</span
|
||||
><input
|
||||
v-model="query"
|
||||
class="input"
|
||||
:placeholder="t('search.search')"
|
||||
:aria-label="t('search.search')"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="error || externalError" role="alert" class="document-error">
|
||||
{{ error || externalError }}
|
||||
</p>
|
||||
<p v-if="busy" class="picker-status">{{ t("files.loading") }}</p>
|
||||
<ul v-else>
|
||||
<li v-for="item in visible" :key="item.path">
|
||||
<button
|
||||
:class="{ selected: selected?.path === item.path }"
|
||||
@click="item.isDir ? load(item.path) : (selected = item)"
|
||||
@dblclick="!item.isDir && open(item)"
|
||||
>
|
||||
<FileIcon :name="item.name" :directory="item.isDir" /><span>{{
|
||||
item.name
|
||||
}}</span
|
||||
><small>{{ item.isDir ? "" : filesize(item.size) }}</small>
|
||||
</button>
|
||||
</li>
|
||||
<li v-if="!visible.length" class="picker-status">
|
||||
{{ t("files.noItems") }}
|
||||
</li>
|
||||
</ul>
|
||||
<footer>
|
||||
<span :title="selected?.name">{{ selected?.name }}</span
|
||||
><button class="button button--flat" @click="$emit('cancel')">
|
||||
{{ t("buttons.cancel") }}</button
|
||||
><button
|
||||
v-if="selected && canOpen(selected)"
|
||||
class="button"
|
||||
:disabled="busy"
|
||||
@click="open(selected)"
|
||||
>
|
||||
{{ t("buttons.open") }}</button
|
||||
><button
|
||||
v-if="selected && intent !== 'open'"
|
||||
class="button button--flat"
|
||||
:disabled="busy"
|
||||
@click="$emit('import', selected)"
|
||||
>
|
||||
{{ t("addons.importServerFile") }}
|
||||
</button>
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, onBeforeUnmount, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import * as api from "@/api/files";
|
||||
import { encodePath } from "@/utils/url";
|
||||
import { filesize } from "filesize";
|
||||
import FileIcon from "./FileIcon.vue";
|
||||
const props = defineProps<{
|
||||
initialPath: string;
|
||||
extensions: string[];
|
||||
intent: string;
|
||||
externalError?: string;
|
||||
}>();
|
||||
const emit = defineEmits<{
|
||||
open: [item: ResourceItem];
|
||||
import: [item: ResourceItem];
|
||||
cancel: [];
|
||||
}>();
|
||||
const { t } = useI18n();
|
||||
const path = ref("/"),
|
||||
query = ref(""),
|
||||
items = ref<ResourceItem[]>([]),
|
||||
selected = ref<ResourceItem>(),
|
||||
busy = ref(false),
|
||||
error = ref(""),
|
||||
dialog = ref<HTMLElement>();
|
||||
let controller: AbortController | undefined;
|
||||
const canOpen = (item: ResourceItem) =>
|
||||
props.extensions.some((ext) => item.name.toLowerCase().endsWith(ext));
|
||||
const visible = computed(() =>
|
||||
items.value
|
||||
.filter(
|
||||
(i) =>
|
||||
i.isDir ||
|
||||
(i.name.toLowerCase().includes(query.value.toLowerCase()) &&
|
||||
(props.intent !== "open" || canOpen(i)))
|
||||
)
|
||||
.sort(
|
||||
(a, b) =>
|
||||
Number(b.isDir) - Number(a.isDir) || a.name.localeCompare(b.name)
|
||||
)
|
||||
);
|
||||
async function load(directory: string) {
|
||||
controller?.abort();
|
||||
const request = (controller = new AbortController());
|
||||
busy.value = true;
|
||||
error.value = "";
|
||||
selected.value = undefined;
|
||||
try {
|
||||
const data = await api.fetch(
|
||||
"/files" + encodePath(directory),
|
||||
request.signal
|
||||
);
|
||||
if (request.signal.aborted) return;
|
||||
if (!data.isDir) throw new Error("Not a directory");
|
||||
path.value = directory;
|
||||
items.value = data.items;
|
||||
query.value = "";
|
||||
} catch (e) {
|
||||
if (!request.signal.aborted) error.value = String(e);
|
||||
} finally {
|
||||
if (controller === request) busy.value = false;
|
||||
}
|
||||
}
|
||||
function parent() {
|
||||
load(
|
||||
path.value
|
||||
.replace(/\/$/, "")
|
||||
.slice(0, path.value.replace(/\/$/, "").lastIndexOf("/") + 1) || "/"
|
||||
);
|
||||
}
|
||||
function open(item: ResourceItem) {
|
||||
if (canOpen(item)) emit("open", item);
|
||||
}
|
||||
const previousFocus = document.activeElement as HTMLElement | null;
|
||||
function trapFocus(event: KeyboardEvent) {
|
||||
const elements = [
|
||||
...(dialog.value?.querySelectorAll<HTMLElement>(
|
||||
'button:not(:disabled), input, [tabindex="0"]'
|
||||
) || []),
|
||||
];
|
||||
if (!elements.length) return;
|
||||
const next = event.shiftKey ? elements[0] : elements.at(-1);
|
||||
if (
|
||||
document.activeElement === next ||
|
||||
document.activeElement === dialog.value
|
||||
) {
|
||||
event.preventDefault();
|
||||
(event.shiftKey ? elements.at(-1) : elements[0])?.focus();
|
||||
}
|
||||
}
|
||||
onMounted(() => {
|
||||
dialog.value?.focus();
|
||||
load(props.initialPath);
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
controller?.abort();
|
||||
previousFocus?.focus();
|
||||
});
|
||||
</script>
|
||||
<style scoped>
|
||||
.server-picker-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: #0008;
|
||||
z-index: 10020;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
padding: 20px;
|
||||
}
|
||||
.server-picker {
|
||||
width: min(900px, 100%);
|
||||
max-height: min(700px, calc(100dvh - 40px));
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: var(--surfacePrimary);
|
||||
color: var(--textSecondary);
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: 16px;
|
||||
overflow: hidden;
|
||||
box-shadow: 0 20px 70px #0005;
|
||||
}
|
||||
.server-picker .picker-header,
|
||||
.server-picker footer,
|
||||
.server-picker .picker-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
padding: 16px 20px;
|
||||
}
|
||||
.server-picker .picker-header {
|
||||
justify-content: space-between;
|
||||
border-bottom: 1px solid var(--borderPrimary);
|
||||
}
|
||||
.server-picker h2 {
|
||||
font-size: 18px;
|
||||
margin: 0 0 6px;
|
||||
}
|
||||
.server-picker p {
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
}
|
||||
.server-picker .picker-toolbar span {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 13px;
|
||||
}
|
||||
.server-picker .picker-toolbar input {
|
||||
width: 200px;
|
||||
margin: 0;
|
||||
}
|
||||
.server-picker ul {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 12px;
|
||||
overflow: auto;
|
||||
flex: 1;
|
||||
min-height: 180px;
|
||||
}
|
||||
.server-picker li button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
width: 100%;
|
||||
padding: 12px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
text-align: left;
|
||||
color: inherit;
|
||||
border-radius: 9px;
|
||||
}
|
||||
.server-picker li button:hover,
|
||||
.server-picker li button.selected {
|
||||
background: var(--surfaceSecondary);
|
||||
}
|
||||
.server-picker li .file-icon {
|
||||
width: 28px;
|
||||
height: 32px;
|
||||
flex: none;
|
||||
}
|
||||
.server-picker li span {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.server-picker small {
|
||||
font-size: 12px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.server-picker footer {
|
||||
border-top: 1px solid var(--borderPrimary);
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.server-picker footer > span {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.picker-status {
|
||||
padding: 20px;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.server-picker-backdrop {
|
||||
padding: 10px;
|
||||
}
|
||||
.server-picker {
|
||||
max-height: calc(100dvh - 20px);
|
||||
}
|
||||
.server-picker .picker-header,
|
||||
.server-picker footer,
|
||||
.server-picker .picker-toolbar {
|
||||
padding: 12px;
|
||||
gap: 8px;
|
||||
}
|
||||
.server-picker .picker-toolbar {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.server-picker .picker-toolbar input {
|
||||
width: 100%;
|
||||
}
|
||||
.server-picker footer > span {
|
||||
flex-basis: 100%;
|
||||
}
|
||||
.server-picker footer .button {
|
||||
padding: 10px;
|
||||
}
|
||||
.server-picker li span {
|
||||
font-size: 13px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -1,58 +0,0 @@
|
||||
<template>
|
||||
<div class="card floating">
|
||||
<div class="card-title">
|
||||
<h2>{{ $t("prompts.currentPassword") }}</h2>
|
||||
</div>
|
||||
|
||||
<div class="card-content">
|
||||
<p>
|
||||
{{ $t("prompts.currentPasswordMessage") }}
|
||||
</p>
|
||||
<input
|
||||
id="focus-prompt"
|
||||
class="input input--block"
|
||||
type="password"
|
||||
@keyup.enter="submit"
|
||||
v-model="password"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
<button
|
||||
class="button button--flat button--grey"
|
||||
@click="cancel"
|
||||
:aria-label="$t('buttons.cancel')"
|
||||
:title="$t('buttons.cancel')"
|
||||
>
|
||||
{{ $t("buttons.cancel") }}
|
||||
</button>
|
||||
<button
|
||||
@click="submit"
|
||||
class="button button--flat"
|
||||
type="submit"
|
||||
:aria-label="$t('buttons.ok')"
|
||||
:title="$t('buttons.ok')"
|
||||
>
|
||||
{{ $t("buttons.ok") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref } from "vue";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
const layoutStore = useLayoutStore();
|
||||
|
||||
const { currentPrompt } = layoutStore;
|
||||
|
||||
const password = ref("");
|
||||
|
||||
const submit = (event: Event) => {
|
||||
currentPrompt?.confirm(event, password.value);
|
||||
};
|
||||
|
||||
const cancel = () => {
|
||||
layoutStore.closeHovers();
|
||||
};
|
||||
</script>
|
||||
@@ -1,40 +0,0 @@
|
||||
<template>
|
||||
<div class="card floating">
|
||||
<div class="card-content">
|
||||
<p>{{ t("prompts.deleteUser") }}</p>
|
||||
</div>
|
||||
|
||||
<div class="card-action">
|
||||
<button
|
||||
id="focus-prompt"
|
||||
class="button button--flat button--grey"
|
||||
@click="layoutStore.closeHovers"
|
||||
:aria-label="t('buttons.cancel')"
|
||||
:title="t('buttons.cancel')"
|
||||
tabindex="1"
|
||||
>
|
||||
{{ t("buttons.cancel") }}
|
||||
</button>
|
||||
<button
|
||||
class="button button--flat"
|
||||
@click="layoutStore.currentPrompt?.confirm"
|
||||
tabindex="2"
|
||||
>
|
||||
{{ t("buttons.delete") }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
const layoutStore = useLayoutStore();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
// const emit = defineEmits<{
|
||||
// (e: "confirm"): void;
|
||||
// }>();
|
||||
</script>
|
||||
@@ -15,7 +15,6 @@ import BaseModal from "./BaseModal.vue";
|
||||
const Help = defineAsyncComponent(() => import("./Help.vue"));
|
||||
const Info = defineAsyncComponent(() => import("./Info.vue"));
|
||||
const Delete = defineAsyncComponent(() => import("./Delete.vue"));
|
||||
const DeleteUser = defineAsyncComponent(() => import("./DeleteUser.vue"));
|
||||
const Rename = defineAsyncComponent(() => import("./Rename.vue"));
|
||||
const Move = defineAsyncComponent(() => import("./Move.vue"));
|
||||
const Copy = defineAsyncComponent(() => import("./Copy.vue"));
|
||||
@@ -35,9 +34,6 @@ const DiscardEditorChanges = defineAsyncComponent(
|
||||
const ResolveConflict = defineAsyncComponent(
|
||||
() => import("./ResolveConflict.vue")
|
||||
);
|
||||
const CurrentPassword = defineAsyncComponent(
|
||||
() => import("./CurrentPassword.vue")
|
||||
);
|
||||
|
||||
const layoutStore = useLayoutStore();
|
||||
|
||||
@@ -58,10 +54,8 @@ const components = new Map<string, any>([
|
||||
["share", Share],
|
||||
["upload", Upload],
|
||||
["share-delete", ShareDelete],
|
||||
["deleteUser", DeleteUser],
|
||||
["discardEditorChanges", DiscardEditorChanges],
|
||||
["resolve-conflict", ResolveConflict],
|
||||
["current-password", CurrentPassword],
|
||||
]);
|
||||
|
||||
const modal = computed(() => {
|
||||
|
||||
@@ -1,218 +1,126 @@
|
||||
<template>
|
||||
<div
|
||||
v-if="uploadStore.activeUploads.size > 0"
|
||||
<aside
|
||||
v-if="uploadStore.activeUploads.size"
|
||||
class="upload-files"
|
||||
v-bind:class="{ closed: !open }"
|
||||
:class="{ closed: !open }"
|
||||
:aria-label="t('transfer.title')"
|
||||
>
|
||||
<div class="card floating">
|
||||
<div class="card-title">
|
||||
<h2>
|
||||
{{
|
||||
$t("prompts.uploadFiles", {
|
||||
files: uploadStore.pendingUploadCount,
|
||||
})
|
||||
}}
|
||||
</h2>
|
||||
<div class="upload-info">
|
||||
<div class="upload-speed">{{ speedText }}/s</div>
|
||||
<div class="upload-eta">{{ formattedETA }} remaining</div>
|
||||
<div class="upload-percentage">{{ sentPercent }}% Completed</div>
|
||||
<div class="upload-fraction">
|
||||
{{ sentMbytes }} /
|
||||
{{ totalMbytes }}
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
class="action"
|
||||
@click="abortAll"
|
||||
aria-label="Abort upload"
|
||||
title="Abort upload"
|
||||
>
|
||||
<AppIcon :name="'cancel'" />
|
||||
</button>
|
||||
<button
|
||||
class="action"
|
||||
@click="toggle"
|
||||
aria-label="Toggle file upload list"
|
||||
title="Toggle file upload list"
|
||||
>
|
||||
<AppIcon :name="open ? 'keyboard_arrow_down' : 'keyboard_arrow_up'" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="card-content file-icons">
|
||||
<div
|
||||
class="file"
|
||||
v-for="upload in uploadStore.activeUploads"
|
||||
:key="upload.path"
|
||||
:data-dir="upload.type === 'dir'"
|
||||
:data-type="upload.type"
|
||||
:aria-label="upload.name"
|
||||
>
|
||||
<div class="file-name"><AppIcon name="file" /> {{ upload.name }}</div>
|
||||
<div class="file-progress">
|
||||
<div
|
||||
v-bind:style="{
|
||||
width: (upload.sentBytes / upload.totalBytes) * 100 + '%',
|
||||
}"
|
||||
></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="transfer-header">
|
||||
<span class="transfer-symbol"><AppIcon name="upload" /></span>
|
||||
<div class="transfer-heading">
|
||||
<strong>{{ t("transfer.title") }}</strong
|
||||
><span>{{
|
||||
t("transfer.remainingFiles", {
|
||||
count: uploadStore.pendingUploadCount,
|
||||
})
|
||||
}}</span>
|
||||
</div>
|
||||
<strong class="transfer-percent">{{ percent }}%</strong>
|
||||
<button
|
||||
class="action"
|
||||
:aria-expanded="open"
|
||||
:aria-label="t('transfer.toggle')"
|
||||
@click="open = !open"
|
||||
>
|
||||
<AppIcon :name="open ? 'expand_more' : 'expand_less'" />
|
||||
</button>
|
||||
<button
|
||||
class="action"
|
||||
:aria-label="t('transfer.cancel')"
|
||||
@click="abortAll"
|
||||
>
|
||||
<AppIcon name="close" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div
|
||||
class="transfer-progress"
|
||||
role="progressbar"
|
||||
:aria-label="t('transfer.title')"
|
||||
:aria-valuenow="percent"
|
||||
aria-valuemin="0"
|
||||
aria-valuemax="100"
|
||||
>
|
||||
<span :style="{ width: percent + '%' }" />
|
||||
</div>
|
||||
<div class="transfer-stats">
|
||||
<span
|
||||
>{{ bytes(uploadStore.sentBytes) }} /
|
||||
{{ bytes(uploadStore.totalBytes) }}</span
|
||||
><span>{{ bytes(rate) }}/s</span><span>{{ remaining }}</span>
|
||||
</div>
|
||||
<ul v-if="open" class="transfer-list">
|
||||
<li v-for="file in uploadStore.activeUploads" :key="file.path">
|
||||
<FileIcon :name="file.name" :directory="file.type === 'dir'" />
|
||||
<div class="transfer-file">
|
||||
<span :title="file.name">{{ file.name }}</span>
|
||||
<div class="transfer-progress">
|
||||
<span
|
||||
:style="{
|
||||
width: progress(file.sentBytes, file.totalBytes) + '%',
|
||||
}"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<small>{{ progress(file.sentBytes, file.totalBytes) }}%</small>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useUploadStore } from "@/stores/upload";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { computed, ref, watch } from "vue";
|
||||
import buttons from "@/utils/buttons";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { partial } from "filesize";
|
||||
|
||||
const { t } = useI18n({});
|
||||
|
||||
const open = ref<boolean>(false);
|
||||
const speed = ref<number>(0);
|
||||
const eta = ref<number>(Infinity);
|
||||
|
||||
const fileStore = useFileStore();
|
||||
const uploadStore = useUploadStore();
|
||||
|
||||
const { sentBytes, totalBytes } = storeToRefs(uploadStore);
|
||||
|
||||
const byteToMbyte = partial({ exponent: 2 });
|
||||
const byteToKbyte = partial({ exponent: 1 });
|
||||
|
||||
const sentPercent = computed(() =>
|
||||
((uploadStore.sentBytes / uploadStore.totalBytes) * 100).toFixed(2)
|
||||
import { filesize } from "filesize";
|
||||
import FileIcon from "@/components/files/FileIcon.vue";
|
||||
import { transferProgress, transferSample } from "@/utils/transfer";
|
||||
const { t } = useI18n();
|
||||
const uploadStore = useUploadStore(),
|
||||
fileStore = useFileStore();
|
||||
const open = ref(false),
|
||||
rate = ref(0);
|
||||
const bytes = (value: number) =>
|
||||
filesize(Math.max(0, value), { base: 2, round: 1 });
|
||||
const progress = transferProgress;
|
||||
const percent = computed(() =>
|
||||
progress(uploadStore.sentBytes, uploadStore.totalBytes)
|
||||
);
|
||||
|
||||
const sentMbytes = computed(() => byteToMbyte(uploadStore.sentBytes));
|
||||
const totalMbytes = computed(() => byteToMbyte(uploadStore.totalBytes));
|
||||
const speedText = computed(() => {
|
||||
const bytes = speed.value;
|
||||
|
||||
if (bytes < 1024 * 1024) {
|
||||
const kb = parseFloat(byteToKbyte(bytes));
|
||||
return `${kb.toFixed(2)} KB`;
|
||||
} else {
|
||||
const mb = parseFloat(byteToMbyte(bytes));
|
||||
return `${mb.toFixed(2)} MB`;
|
||||
let previous = { bytes: 0, time: performance.now(), rate: 0 };
|
||||
watch(
|
||||
() => uploadStore.sentBytes,
|
||||
(value) => {
|
||||
previous = transferSample(previous, value, performance.now());
|
||||
rate.value = previous.rate;
|
||||
}
|
||||
);
|
||||
watch(
|
||||
() => uploadStore.totalBytes,
|
||||
(value, old) => {
|
||||
if (!old || !value) {
|
||||
previous = {
|
||||
bytes: uploadStore.sentBytes,
|
||||
time: performance.now(),
|
||||
rate: 0,
|
||||
};
|
||||
rate.value = 0;
|
||||
}
|
||||
}
|
||||
);
|
||||
const remaining = computed(() => {
|
||||
if (rate.value <= 0) return t("transfer.estimating");
|
||||
const seconds = Math.ceil(
|
||||
Math.max(0, uploadStore.totalBytes - uploadStore.sentBytes) / rate.value
|
||||
);
|
||||
return t("transfer.remaining", {
|
||||
time:
|
||||
seconds < 60
|
||||
? `${seconds} ${t("transfer.seconds")}`
|
||||
: `${Math.ceil(seconds / 60)} ${t("transfer.minutes")}`,
|
||||
});
|
||||
});
|
||||
|
||||
let lastSpeedUpdate: number = 0;
|
||||
let recentSpeeds: number[] = [];
|
||||
|
||||
let lastThrottleTime = 0;
|
||||
|
||||
const throttledCalculateSpeed = (sentBytes: number, oldSentBytes: number) => {
|
||||
const now = Date.now();
|
||||
if (now - lastThrottleTime < 100) {
|
||||
return;
|
||||
}
|
||||
|
||||
lastThrottleTime = now;
|
||||
calculateSpeed(sentBytes, oldSentBytes);
|
||||
};
|
||||
|
||||
const calculateSpeed = (sentBytes: number, oldSentBytes: number) => {
|
||||
// Reset the state when the uploads batch is complete
|
||||
if (sentBytes === 0) {
|
||||
lastSpeedUpdate = 0;
|
||||
recentSpeeds = [];
|
||||
|
||||
eta.value = Infinity;
|
||||
speed.value = 0;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const elapsedTime = (Date.now() - (lastSpeedUpdate ?? 0)) / 1000;
|
||||
const bytesSinceLastUpdate = sentBytes - oldSentBytes;
|
||||
const currentSpeed = bytesSinceLastUpdate / elapsedTime;
|
||||
|
||||
recentSpeeds.push(currentSpeed);
|
||||
if (recentSpeeds.length > 5) {
|
||||
recentSpeeds.shift();
|
||||
}
|
||||
|
||||
const recentSpeedsAverage =
|
||||
recentSpeeds.reduce((acc, curr) => acc + curr) / recentSpeeds.length;
|
||||
|
||||
// Use the current speed for the first update to avoid smoothing lag
|
||||
if (recentSpeeds.length === 1) {
|
||||
speed.value = currentSpeed;
|
||||
}
|
||||
|
||||
speed.value = recentSpeedsAverage * 0.2 + speed.value * 0.8;
|
||||
|
||||
lastSpeedUpdate = Date.now();
|
||||
|
||||
calculateEta();
|
||||
};
|
||||
|
||||
const calculateEta = () => {
|
||||
if (speed.value === 0) {
|
||||
eta.value = Infinity;
|
||||
|
||||
return Infinity;
|
||||
}
|
||||
|
||||
const remainingSize = uploadStore.totalBytes - uploadStore.sentBytes;
|
||||
const speedBytesPerSecond = speed.value;
|
||||
|
||||
eta.value = remainingSize / speedBytesPerSecond;
|
||||
};
|
||||
|
||||
watch(sentBytes, throttledCalculateSpeed);
|
||||
|
||||
watch(totalBytes, (totalBytes, oldTotalBytes) => {
|
||||
if (oldTotalBytes !== 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Mark the start time of a new upload batch
|
||||
lastSpeedUpdate = Date.now();
|
||||
});
|
||||
|
||||
const formattedETA = computed(() => {
|
||||
if (!eta.value || eta.value === Infinity) {
|
||||
return "--:--:--";
|
||||
}
|
||||
|
||||
let totalSeconds = eta.value;
|
||||
const hours = Math.floor(totalSeconds / 3600);
|
||||
totalSeconds %= 3600;
|
||||
const minutes = Math.floor(totalSeconds / 60);
|
||||
const seconds = Math.round(totalSeconds % 60);
|
||||
|
||||
return `${hours.toString().padStart(2, "0")}:${minutes
|
||||
.toString()
|
||||
.padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
||||
});
|
||||
|
||||
const toggle = () => {
|
||||
open.value = !open.value;
|
||||
};
|
||||
|
||||
const abortAll = () => {
|
||||
if (confirm(t("upload.abortUpload"))) {
|
||||
buttons.done("upload");
|
||||
open.value = false;
|
||||
uploadStore.abort();
|
||||
fileStore.reload = true; // Trigger reload in the file store
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.upload-info {
|
||||
min-width: 19ch;
|
||||
width: auto;
|
||||
text-align: left;
|
||||
function abortAll() {
|
||||
if (!confirm(t("upload.abortUpload"))) return;
|
||||
uploadStore.abort();
|
||||
fileStore.reload = true;
|
||||
}
|
||||
</style>
|
||||
</script>
|
||||
@@ -27,6 +27,10 @@
|
||||
}}</small>
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="addon.compatibilityIssue" class="addon-incompatible">
|
||||
<strong>{{ t("addons.incompatible") }}</strong> ·
|
||||
{{ t("addons.compatibility." + addon.compatibilityIssue) }}
|
||||
</p>
|
||||
<p v-if="addon.id === 'deckcraft'" class="field-hint">
|
||||
{{ t("addons.deckcraftFormat") }}
|
||||
</p>
|
||||
@@ -39,7 +43,7 @@
|
||||
><input
|
||||
type="checkbox"
|
||||
:checked="addon.enabled"
|
||||
:disabled="changing === addon.id"
|
||||
:disabled="changing === addon.id || !!addon.compatibilityIssue"
|
||||
@change="
|
||||
toggle(addon, ($event.target as HTMLInputElement).checked)
|
||||
"
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
.epub-reader .container {
|
||||
width: 100%;
|
||||
max-width: 100%;
|
||||
height: calc(100% - 64px);
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
* button instead of opening the table of contents. Push it just below the
|
||||
* header, tracking the header's height so it stays clear if that changes.
|
||||
*/
|
||||
top: calc(4em + 10px);
|
||||
top: 10px;
|
||||
}
|
||||
|
||||
.epub-reader .tocButton.tocButtonExpanded {
|
||||
@@ -67,7 +67,7 @@
|
||||
right: 25px;
|
||||
outline: none;
|
||||
position: absolute;
|
||||
top: 78px;
|
||||
top: 12px;
|
||||
}
|
||||
|
||||
.epub-reader .size span {
|
||||
|
||||
@@ -184,27 +184,27 @@ main .spinner .bounce2 {
|
||||
}
|
||||
|
||||
#previewer header {
|
||||
background: none;
|
||||
color: #fff;
|
||||
background: var(--surfacePrimary);
|
||||
color: var(--textPrimary);
|
||||
border-bottom: 0px;
|
||||
box-shadow: 0px 0px 0px;
|
||||
z-index: 19999;
|
||||
}
|
||||
|
||||
#previewer header > .action .app-icon {
|
||||
color: #fff;
|
||||
text-shadow: 1px 1px 1px #000000;
|
||||
color: var(--textPrimary);
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
#previewer header > title {
|
||||
white-space: nowrap;
|
||||
text-shadow: 1px 1px 1px #000000;
|
||||
text-shadow: none;
|
||||
}
|
||||
|
||||
@media (min-width: 738px) {
|
||||
#previewer header #dropdown .action .app-icon {
|
||||
color: #fff;
|
||||
text-shadow: 1px 1px 1px #000000;
|
||||
color: var(--textPrimary);
|
||||
text-shadow: none;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,61 +1,141 @@
|
||||
.upload-files .card.floating {
|
||||
left: auto;
|
||||
top: auto;
|
||||
.upload-files {
|
||||
position: fixed;
|
||||
z-index: 1005;
|
||||
right: 20px;
|
||||
bottom: 20px;
|
||||
width: min(440px, calc(100vw - 32px));
|
||||
border: 1px solid var(--borderPrimary);
|
||||
border-radius: 16px;
|
||||
background: var(--surfacePrimary);
|
||||
color: var(--textSecondary);
|
||||
box-shadow: 0 8px 28px #0003;
|
||||
overflow: hidden;
|
||||
}
|
||||
.transfer-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
padding: 16px 14px 12px;
|
||||
}
|
||||
.transfer-symbol {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 38px;
|
||||
height: 38px;
|
||||
flex: none;
|
||||
border-radius: 12px;
|
||||
background: var(--surfaceSecondary);
|
||||
color: var(--blue);
|
||||
}
|
||||
.transfer-heading {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
gap: 4px;
|
||||
}
|
||||
.transfer-heading strong {
|
||||
font-size: 14px;
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
.transfer-heading span,
|
||||
.transfer-stats {
|
||||
font-size: 12px;
|
||||
color: var(--textSecondary);
|
||||
}
|
||||
.transfer-percent {
|
||||
font-variant-numeric: tabular-nums;
|
||||
font-size: 14px;
|
||||
}
|
||||
.transfer-header .action {
|
||||
margin: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
transform: none;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
min-width: 32px;
|
||||
padding: 6px;
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.upload-files .file {
|
||||
margin-bottom: 8px;
|
||||
.transfer-header .app-icon {
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
}
|
||||
|
||||
.upload-files .file .file-name {
|
||||
font-size: 1.1em;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
.transfer-progress {
|
||||
height: 4px;
|
||||
background: var(--surfaceSecondary);
|
||||
overflow: hidden;
|
||||
border-radius: 9px;
|
||||
}
|
||||
|
||||
.upload-files .file .file-name .app-icon {
|
||||
margin-right: 5px;
|
||||
.upload-files > .transfer-progress {
|
||||
margin: 0 16px;
|
||||
}
|
||||
|
||||
.upload-files .file .file-progress {
|
||||
margin-top: 2px;
|
||||
width: 100%;
|
||||
height: 5px;
|
||||
}
|
||||
|
||||
.upload-files .file .file-progress div {
|
||||
.transfer-progress > span {
|
||||
display: block;
|
||||
height: 100%;
|
||||
background-color: #40c4ff;
|
||||
width: 0;
|
||||
transition: 0.2s ease width;
|
||||
border-radius: 10px;
|
||||
background: var(--blue);
|
||||
transition: width 0.2s;
|
||||
}
|
||||
|
||||
.upload-files.closed .card-content {
|
||||
display: none;
|
||||
padding: 0em 1em 1em 1em;
|
||||
.transfer-stats {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 6px 12px;
|
||||
padding: 12px 16px;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.upload-files .card .card-title {
|
||||
.transfer-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0 16px 12px;
|
||||
max-height: min(260px, 40vh);
|
||||
overflow: auto;
|
||||
}
|
||||
.transfer-list li {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 0.8em;
|
||||
padding: 1em 1em 0em;
|
||||
gap: 10px;
|
||||
padding: 12px 0;
|
||||
border-top: 1px solid var(--borderPrimary);
|
||||
}
|
||||
|
||||
.upload-files.closed .card-title {
|
||||
font-size: 0.7em;
|
||||
padding: 0.5em 1em;
|
||||
.transfer-list .file-icon {
|
||||
width: 28px;
|
||||
height: 32px;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
@media (max-width: 450px) {
|
||||
.upload-files .card.floating {
|
||||
max-width: 100%;
|
||||
width: 100%;
|
||||
.transfer-file {
|
||||
min-width: 0;
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
.transfer-file > span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
font-size: 13px;
|
||||
}
|
||||
.transfer-list small {
|
||||
font-size: 11px;
|
||||
width: 32px;
|
||||
text-align: right;
|
||||
}
|
||||
@media (max-width: 600px) {
|
||||
.upload-files {
|
||||
right: 10px;
|
||||
bottom: max(10px, env(safe-area-inset-bottom));
|
||||
width: calc(100vw - 20px);
|
||||
border-radius: 14px;
|
||||
}
|
||||
.transfer-header {
|
||||
gap: 7px;
|
||||
padding: 12px 10px;
|
||||
}
|
||||
.transfer-symbol {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
}
|
||||
.transfer-stats {
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
@@ -52,6 +52,8 @@
|
||||
min-height: 0;
|
||||
}
|
||||
#previewer .preview.document-preview {
|
||||
background: var(--background);
|
||||
color: var(--textPrimary);
|
||||
position: absolute;
|
||||
top: 4em;
|
||||
bottom: 0;
|
||||
@@ -963,3 +965,12 @@ select:focus {
|
||||
scroll-behavior: auto !important;
|
||||
}
|
||||
}
|
||||
|
||||
.addon-incompatible {
|
||||
margin: 0;
|
||||
font-size: 12px;
|
||||
color: var(--textPrimary);
|
||||
padding: 10px;
|
||||
border-radius: 8px;
|
||||
background: var(--surfaceSecondary);
|
||||
}
|
||||
@@ -54,7 +54,8 @@
|
||||
"overrideAll": "Replace all files in destination folder",
|
||||
"skipAll": "Skip all conflicting files",
|
||||
"renameAll": "Rename all files (create a copy)",
|
||||
"singleDecision": "Decide for each conflicting file"
|
||||
"singleDecision": "Decide for each conflicting file",
|
||||
"open": "Open"
|
||||
},
|
||||
"download": {
|
||||
"downloadFile": "Download File",
|
||||
@@ -470,6 +471,24 @@
|
||||
"verifying": "Verifying SHA-256",
|
||||
"extracting": "Installing"
|
||||
},
|
||||
"sessionExpired": "Session expired. Sign in in another tab, then retry saving."
|
||||
"sessionExpired": "Session expired. Sign in in another tab, then retry saving.",
|
||||
"serverOpen": "Open from server",
|
||||
"serverOpenHint": "Choose a document or an import file from your accessible folders.",
|
||||
"importServerFile": "Insert / import",
|
||||
"incompatible": "Not compatible",
|
||||
"compatibility": {
|
||||
"demoOnly": "This web release only opens its demo project and cannot load or save server files.",
|
||||
"serverSave": "Loading and saving server projects could not be verified in this web build. The tool is temporarily disabled."
|
||||
}
|
||||
},
|
||||
"transfer": {
|
||||
"title": "Uploading files",
|
||||
"remainingFiles": "Files remaining: {count}",
|
||||
"toggle": "Show or hide upload queue",
|
||||
"cancel": "Cancel uploads",
|
||||
"estimating": "Estimating…",
|
||||
"remaining": "{time} remaining",
|
||||
"seconds": "s",
|
||||
"minutes": "min"
|
||||
}
|
||||
}
|
||||
@@ -54,7 +54,8 @@
|
||||
"overrideAll": "Replace all files in destination folder",
|
||||
"skipAll": "Skip all conflicting files",
|
||||
"renameAll": "Rename all files (create a copy)",
|
||||
"singleDecision": "Decide for each conflicting file"
|
||||
"singleDecision": "Decide for each conflicting file",
|
||||
"open": "Открыть"
|
||||
},
|
||||
"download": {
|
||||
"downloadFile": "Скачать файл",
|
||||
@@ -250,7 +251,7 @@
|
||||
"permissions": "Права доступа",
|
||||
"permissionsHelp": "Права на работу с файлами. Администраторы определяются ролями SSO.",
|
||||
"profileSettings": "Интерфейс",
|
||||
"redirectAfterCopyMove": "Redirect to destination after copy/move",
|
||||
"redirectAfterCopyMove": "Переходить в папку назначения после копирования или перемещения",
|
||||
"ruleExample1": "предотвратить доступ к любому скрытому файлу (например: .git, .gitignore) в каждой папке.\n",
|
||||
"ruleExample2": "блокирует доступ к файлу с именем Caddyfile в корневой области.",
|
||||
"rules": "Права",
|
||||
@@ -467,6 +468,24 @@
|
||||
"verifying": "Проверка SHA-256",
|
||||
"extracting": "Установка"
|
||||
},
|
||||
"sessionExpired": "Сессия истекла. Войдите в соседней вкладке, затем повторите сохранение."
|
||||
"sessionExpired": "Сессия истекла. Войдите в соседней вкладке, затем повторите сохранение.",
|
||||
"serverOpen": "Открыть с сервера",
|
||||
"serverOpenHint": "Выберите документ или файл для импорта из доступных папок.",
|
||||
"importServerFile": "Вставить / импортировать",
|
||||
"incompatible": "Не совместимо",
|
||||
"compatibility": {
|
||||
"demoOnly": "Эта веб-версия открывает только демопроект и не поддерживает загрузку и сохранение файлов сервера.",
|
||||
"serverSave": "В этой веб-сборке не удалось подтвердить загрузку и сохранение проекта на сервер. Инструмент временно отключён."
|
||||
}
|
||||
},
|
||||
"transfer": {
|
||||
"title": "Загрузка файлов",
|
||||
"remainingFiles": "Осталось файлов: {count}",
|
||||
"toggle": "Показать или скрыть очередь",
|
||||
"cancel": "Отменить загрузку",
|
||||
"estimating": "Расчёт времени…",
|
||||
"remaining": "Осталось {time}",
|
||||
"seconds": "с",
|
||||
"minutes": "мин"
|
||||
}
|
||||
}
|
||||
@@ -12,6 +12,7 @@ export interface Addon {
|
||||
enabled: boolean;
|
||||
state: string;
|
||||
error?: string;
|
||||
compatibilityIssue?: string;
|
||||
downloaded: number;
|
||||
total: number;
|
||||
}
|
||||
@@ -34,7 +35,11 @@ export const useAddonsStore = defineStore("addons", {
|
||||
},
|
||||
available(id: string) {
|
||||
return this.items.some(
|
||||
(item) => item.id === id && item.enabled && !!item.build
|
||||
(item) =>
|
||||
item.id === id &&
|
||||
item.enabled &&
|
||||
!item.compatibilityIssue &&
|
||||
!!item.build
|
||||
);
|
||||
},
|
||||
},
|
||||
|
||||
@@ -69,17 +69,20 @@ export const useUploadStore = defineStore("upload", () => {
|
||||
// Resets the state by preventing the processing of the remaning uploads
|
||||
lastUpload.value = Infinity;
|
||||
tus.abortAllUploads();
|
||||
api.abortResourceUploads();
|
||||
};
|
||||
|
||||
//
|
||||
// GETTERS
|
||||
//
|
||||
|
||||
const pendingUploadCount = computed(
|
||||
() =>
|
||||
const pendingUploadCount = computed(() =>
|
||||
Math.max(
|
||||
0,
|
||||
allUploads.value.length -
|
||||
(lastUpload.value + 1) +
|
||||
activeUploads.value.size
|
||||
(lastUpload.value + 1) +
|
||||
activeUploads.value.size
|
||||
)
|
||||
);
|
||||
|
||||
//
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { expect, it } from "vitest";
|
||||
import { transferProgress, transferSample } from "../transfer";
|
||||
it("keeps throttled progress bytes until the next speed sample", () => {
|
||||
const start = { bytes: 0, time: 1000, rate: 0 };
|
||||
const deferred = transferSample(start, 100, 1100);
|
||||
expect(deferred).toBe(start);
|
||||
expect(transferSample(deferred, 500, 1500).rate).toBe(1000);
|
||||
});
|
||||
it("resets the rate for a restarted upload and bounds progress", () => {
|
||||
expect(
|
||||
transferSample({ bytes: 1000, time: 1000, rate: 100 }, 0, 2000).rate
|
||||
).toBe(0);
|
||||
expect(transferProgress(11, 10)).toBe(100);
|
||||
expect(transferProgress(0, 0)).toBe(0);
|
||||
expect(transferProgress(-1, 10)).toBe(0);
|
||||
});
|
||||
@@ -54,6 +54,7 @@ export function craftMessage(
|
||||
dirty?: boolean;
|
||||
saveAs?: boolean;
|
||||
error?: string;
|
||||
intent?: string;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -78,6 +79,7 @@ export function defaultCraftTool(items: Addon[], name: string, type = "") {
|
||||
return items.find(
|
||||
(item) =>
|
||||
item.enabled &&
|
||||
!item.compatibilityIssue &&
|
||||
item.build &&
|
||||
addonAccepts(item, name) &&
|
||||
(preview !== "pdf" || item.id === "pdfcraft")
|
||||
|
||||
@@ -6,6 +6,8 @@ export interface DicomSource {
|
||||
}
|
||||
export const MAX_VOLUME_BYTES = 1.5 * 1024 * 1024 * 1024;
|
||||
export const MAX_SERIES_FILES = 2048;
|
||||
// Temporarily disabled while volume rendering is being stabilized.
|
||||
export const DICOM_3D_ENABLED = false;
|
||||
|
||||
// Names only trigger the offer. Patient-space geometry is checked after consent.
|
||||
export function dicomSeries(
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
export function transferProgress(sent: number, total: number) {
|
||||
return total > 0 && Number.isFinite(sent)
|
||||
? Math.max(0, Math.min(100, Math.round((sent / total) * 100)))
|
||||
: 0;
|
||||
}
|
||||
export function transferSample(
|
||||
previous: { bytes: number; time: number; rate: number },
|
||||
bytes: number,
|
||||
time: number
|
||||
) {
|
||||
if (bytes < previous.bytes || bytes === 0) return { bytes, time, rate: 0 };
|
||||
const elapsed = (time - previous.time) / 1000;
|
||||
if (elapsed < 0.25) return previous;
|
||||
const current = (bytes - previous.bytes) / elapsed;
|
||||
return {
|
||||
bytes,
|
||||
time,
|
||||
rate: previous.rate ? current * 0.4 + previous.rate * 0.6 : current,
|
||||
};
|
||||
}
|
||||
@@ -1,5 +1,17 @@
|
||||
<template>
|
||||
<div class="craft-editor">
|
||||
<ServerFilePicker
|
||||
v-if="pickerRequest"
|
||||
:initial-path="
|
||||
currentPath.slice(0, currentPath.lastIndexOf('/') + 1) || '/'
|
||||
"
|
||||
:extensions="activeTool?.extensions || [activeTool?.extension || '']"
|
||||
:intent="pickerRequest.intent"
|
||||
:external-error="error"
|
||||
@cancel="cancelPicker"
|
||||
@open="openServerDocument"
|
||||
@import="importServerFile"
|
||||
/>
|
||||
<div v-if="pending || error || saving || saveAs" class="craft-feedback">
|
||||
<div class="craft-status" role="status">
|
||||
<strong>{{ title }}</strong
|
||||
@@ -78,7 +90,15 @@
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, onMounted, onBeforeUnmount } from "vue";
|
||||
import { useRoute, onBeforeRouteLeave, onBeforeRouteUpdate } from "vue-router";
|
||||
import {
|
||||
useRoute,
|
||||
useRouter,
|
||||
onBeforeRouteLeave,
|
||||
onBeforeRouteUpdate,
|
||||
} from "vue-router";
|
||||
import ServerFilePicker from "@/components/files/ServerFilePicker.vue";
|
||||
import { getDownloadURL } from "@/api/files";
|
||||
import { previewBuffer } from "@/utils/preview";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
@@ -92,6 +112,7 @@ import {
|
||||
safeCraftName,
|
||||
} from "@/utils/craft";
|
||||
const route = useRoute(),
|
||||
router = useRouter(),
|
||||
store = useAddonsStore(),
|
||||
files = useFileStore(),
|
||||
auth = useAuthStore(),
|
||||
@@ -126,6 +147,79 @@ interface Save {
|
||||
}
|
||||
const pending = ref<Save>();
|
||||
const authExpired = ref(false);
|
||||
const pickerRequest = ref<{ requestId: string; intent: string }>();
|
||||
function cancelPicker() {
|
||||
if (!pickerRequest.value) return;
|
||||
frame.value?.contentWindow?.postMessage(
|
||||
{
|
||||
type: id + ":pick-result",
|
||||
requestId: pickerRequest.value.requestId,
|
||||
error: "AbortError",
|
||||
},
|
||||
window.location.origin
|
||||
);
|
||||
pickerRequest.value = undefined;
|
||||
}
|
||||
function openServerDocument(item: ResourceItem) {
|
||||
if (
|
||||
!activeTool.value ||
|
||||
!addonAccepts(activeTool.value, item.name) ||
|
||||
!mayLeave()
|
||||
)
|
||||
return;
|
||||
if (item.size > 64 * 1024 * 1024) {
|
||||
error.value = t("addons.tooLarge");
|
||||
return;
|
||||
}
|
||||
cancelPicker();
|
||||
pending.value = undefined;
|
||||
frameDirty.value = false;
|
||||
window.location.assign(
|
||||
router.resolve({
|
||||
name: "CraftEditor",
|
||||
params: { addon: id },
|
||||
query: { path: item.path },
|
||||
}).href
|
||||
);
|
||||
}
|
||||
async function importServerFile(item: ResourceItem) {
|
||||
const request = pickerRequest.value;
|
||||
if (!request) return;
|
||||
try {
|
||||
if (item.size > 64 * 1024 * 1024) throw new Error(t("addons.tooLarge"));
|
||||
const bytes = await previewBuffer(
|
||||
getDownloadURL(item, true),
|
||||
controller.signal,
|
||||
64 * 1024 * 1024
|
||||
);
|
||||
if (pickerRequest.value !== request || disposed) return;
|
||||
const mime =
|
||||
(
|
||||
{
|
||||
".png": "image/png",
|
||||
".jpg": "image/jpeg",
|
||||
".jpeg": "image/jpeg",
|
||||
".svg": "image/svg+xml",
|
||||
".pdf": "application/pdf",
|
||||
".wav": "audio/wav",
|
||||
} as Record<string, string>
|
||||
)[item.extension] || "";
|
||||
frame.value?.contentWindow?.postMessage(
|
||||
{
|
||||
type: id + ":pick-result",
|
||||
requestId: request.requestId,
|
||||
files: [{ name: item.name, bytes, mime }],
|
||||
},
|
||||
window.location.origin,
|
||||
[bytes]
|
||||
);
|
||||
pickerRequest.value = undefined;
|
||||
frameDirty.value = true;
|
||||
revision++;
|
||||
} catch (failure) {
|
||||
if (!disposed) error.value = String(failure);
|
||||
}
|
||||
}
|
||||
let activityDocument: Document | null = null,
|
||||
lastActivity = 0;
|
||||
const activityEvents = [
|
||||
@@ -290,7 +384,20 @@ function receive(event: MessageEvent) {
|
||||
window.location.origin
|
||||
);
|
||||
if (!message) return;
|
||||
if (message.type === id + ":ready") {
|
||||
if (message.type === id + ":pick-request") {
|
||||
if (
|
||||
typeof message.requestId !== "string" ||
|
||||
message.requestId.length > 80 ||
|
||||
!auth.user?.perm.download
|
||||
)
|
||||
return;
|
||||
if (pickerRequest.value) return;
|
||||
error.value = "";
|
||||
pickerRequest.value = {
|
||||
requestId: message.requestId,
|
||||
intent: message.intent === "open" ? "open" : "choose",
|
||||
};
|
||||
} else if (message.type === id + ":ready") {
|
||||
if (opened || !original) return;
|
||||
opened = true;
|
||||
clearTimeout(startup);
|
||||
@@ -354,7 +461,8 @@ onMounted(async () => {
|
||||
document.title = currentName.value;
|
||||
await store.refresh();
|
||||
const addon = store.items.find(
|
||||
(item) => item.id === id && item.enabled && item.build
|
||||
(item) =>
|
||||
item.id === id && item.enabled && !item.compatibilityIssue && item.build
|
||||
);
|
||||
if (
|
||||
!addon ||
|
||||
|
||||
@@ -72,7 +72,10 @@
|
||||
<template v-else>
|
||||
<div
|
||||
class="preview"
|
||||
:class="{ 'document-preview': isDicom || isPdf || isGenericPreview }"
|
||||
:class="{
|
||||
'document-preview':
|
||||
isDicom || isPdf || isEpub || isCsv || isGenericPreview,
|
||||
}"
|
||||
>
|
||||
<PdfViewer v-if="isPdf" :source="previewUrl" />
|
||||
<DicomViewer
|
||||
@@ -159,6 +162,7 @@
|
||||
</template>
|
||||
|
||||
<button
|
||||
v-if="['image', 'audio', 'video'].includes(fileStore.req?.type || '')"
|
||||
@click="prev"
|
||||
@mouseover="hoverNav = true"
|
||||
@mouseleave="hoverNav = false"
|
||||
@@ -169,6 +173,7 @@
|
||||
<AppIcon name="chevron_left" />
|
||||
</button>
|
||||
<button
|
||||
v-if="['image', 'audio', 'video'].includes(fileStore.req?.type || '')"
|
||||
@click="next"
|
||||
@mouseover="hoverNav = true"
|
||||
@mouseleave="hoverNav = false"
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
><input type="checkbox" v-model="redirectAfterCopyMove"
|
||||
/></label>
|
||||
</section>
|
||||
<section class="card settings-section">
|
||||
<section v-if="DICOM_3D_ENABLED" class="card settings-section">
|
||||
<h2><AppIcon name="tune" />{{ t("preferences.dicom3D") }}</h2>
|
||||
<label class="settings-field"
|
||||
>{{ t("preferences.dicomQuality") }}
|
||||
@@ -110,8 +110,10 @@ import { users as api } from "@/api";
|
||||
import Languages from "@/components/settings/Languages.vue";
|
||||
import AccountAvatar from "@/components/AccountAvatar.vue";
|
||||
import { baseURL } from "@/utils/constants";
|
||||
import { getTheme, setTheme } from "@/utils/theme";
|
||||
import { getTheme, getMediaPreference, setTheme } from "@/utils/theme";
|
||||
import { dicomPreferences } from "@/utils/dicom-quality";
|
||||
import { detectLocale } from "@/i18n";
|
||||
import { DICOM_3D_ENABLED } from "@/utils/dicom-series";
|
||||
import { inject, onMounted, ref } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
|
||||
@@ -128,7 +130,7 @@ const singleClick = ref<boolean>(false);
|
||||
const redirectAfterCopyMove = ref<boolean>(false);
|
||||
const dateFormat = ref<boolean>(false);
|
||||
const locale = ref<string>("");
|
||||
const selectedTheme = ref<UserTheme>(getTheme());
|
||||
const selectedTheme = ref<UserTheme>(getTheme() || getMediaPreference());
|
||||
const saving = ref(false);
|
||||
const dicom3D = ref(dicomPreferences());
|
||||
|
||||
@@ -138,7 +140,7 @@ onMounted(async () => {
|
||||
layoutStore.loading = false;
|
||||
return false;
|
||||
}
|
||||
locale.value = authStore.user.locale;
|
||||
locale.value = authStore.user.locale || detectLocale();
|
||||
hideDotfiles.value = authStore.user.hideDotfiles;
|
||||
showPreviews.value = !authStore.user.hidePreviews;
|
||||
singleClick.value = authStore.user.singleClick;
|
||||
|
||||
Reference in new issue
Block a user