feat: add explorer sidebar, account menu and preview preferences
This commit is contained in:
1 parent
b87f8cb961
commit
fa1832dfa7
22 files changed
+929
-226
No files matched your search
@@ -0,0 +1,7 @@
|
||||
# Навигация и миниатюры
|
||||
|
||||
Боковая панель содержит закладки и раскрывающееся дерево каталогов. Текущий путь раскрывается автоматически; для остальных папок запрашивается только непосредственное содержимое при раскрытии. Обновления текущего каталога берутся из уже загруженного списка файлов. Скрытые каталоги учитывают настройку профиля. Права и область доступа проверяются существующим API.
|
||||
|
||||
Кнопка закладки закрепляет текущую папку. Закладки хранятся в браузере отдельно для каждого аккаунта и базового URL приложения. Крестик удаляет только закладку. Нижняя строка аккаунта открывает профиль, управление ссылками, административные разделы и выход в соответствии с правами пользователя. Меню поддерживает клавиатуру и закрывается по Escape или нажатию снаружи.
|
||||
|
||||
«Настройки профиля → Показ превью» сохраняется в базе пользователя и действует после повторного входа. По умолчанию показ включён, если миниатюры разрешены сервером. При отключении запросов миниатюр нет. Изображения загружаются по мере приближения к видимой области как в таблице, так и в плитках; ошибки миниатюр заменяются иконкой типа файла. DICOM отображается отдельной иконкой `.dcm`, без попытки генерации серверной миниатюры.
|
||||
@@ -0,0 +1,120 @@
|
||||
<template>
|
||||
<li class="folder-node">
|
||||
<div
|
||||
class="folder-row"
|
||||
:class="{ selected }"
|
||||
:style="{ paddingInlineStart: `${depth * 14}px` }"
|
||||
>
|
||||
<button
|
||||
class="folder-expand"
|
||||
:aria-expanded="expanded"
|
||||
:aria-label="name"
|
||||
@click="expanded = !expanded"
|
||||
>
|
||||
<i class="material-icons">{{
|
||||
expanded ? "expand_more" : "chevron_right"
|
||||
}}</i>
|
||||
</button>
|
||||
<router-link
|
||||
:to="url"
|
||||
:title="name"
|
||||
:aria-current="selected ? 'page' : undefined"
|
||||
@click="layout.closeHovers"
|
||||
>
|
||||
<i class="material-icons">{{ expanded ? "folder_open" : "folder" }}</i
|
||||
><span>{{ name }}</span>
|
||||
</router-link>
|
||||
</div>
|
||||
<ul v-if="expanded">
|
||||
<li v-if="loading" class="tree-status">{{ t("files.loading") }}</li>
|
||||
<li v-else-if="error" class="tree-status">
|
||||
<button @click="load">{{ t("explorer.retry") }}</button>
|
||||
</li>
|
||||
<FolderTreeNode
|
||||
v-for="folder in folders"
|
||||
:key="folder.url"
|
||||
:url="folder.url"
|
||||
:name="folder.name"
|
||||
:depth="depth + 1"
|
||||
/>
|
||||
</ul>
|
||||
</li>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
import { files as api } from "@/api";
|
||||
const props = defineProps<{ url: string; name: string; depth: number }>();
|
||||
const route = useRoute(),
|
||||
file = useFileStore(),
|
||||
auth = useAuthStore(),
|
||||
layout = useLayoutStore();
|
||||
const { t } = useI18n();
|
||||
const normalized = (url: string) => url.replace(/\/+$/, "") + "/";
|
||||
const expanded = ref(props.depth === 0),
|
||||
loading = ref(false),
|
||||
error = ref(false);
|
||||
const children = ref<ResourceItem[]>([]);
|
||||
const selected = computed(
|
||||
() => !!file.req?.isDir && normalized(file.req.url) === normalized(props.url)
|
||||
);
|
||||
const folders = computed(() =>
|
||||
children.value
|
||||
.filter(
|
||||
(item) =>
|
||||
item.isDir && (!auth.user?.hideDotfiles || !item.name.startsWith("."))
|
||||
)
|
||||
.sort((a, b) => a.name.localeCompare(b.name, undefined, { numeric: true }))
|
||||
);
|
||||
let controller: AbortController | undefined;
|
||||
function useCurrentListing() {
|
||||
if (!selected.value || !file.req) return false;
|
||||
controller?.abort();
|
||||
children.value = file.req.items;
|
||||
loading.value = false;
|
||||
error.value = false;
|
||||
return true;
|
||||
}
|
||||
async function load() {
|
||||
if (useCurrentListing()) return;
|
||||
controller?.abort();
|
||||
const request = (controller = new AbortController());
|
||||
loading.value = true;
|
||||
error.value = false;
|
||||
try {
|
||||
const result = await api.fetch(props.url, request.signal);
|
||||
if (request.signal.aborted) return;
|
||||
children.value = result.items || [];
|
||||
} catch {
|
||||
if (!request.signal.aborted) error.value = true;
|
||||
} finally {
|
||||
if (controller === request) loading.value = false;
|
||||
}
|
||||
}
|
||||
watch(
|
||||
() => file.req,
|
||||
() => {
|
||||
if (expanded.value) useCurrentListing();
|
||||
}
|
||||
);
|
||||
watch(
|
||||
() => route.path,
|
||||
(path) => {
|
||||
if (normalized(path).startsWith(normalized(props.url)))
|
||||
expanded.value = true;
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
watch(
|
||||
expanded,
|
||||
(value) => {
|
||||
if (value) load();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
onBeforeUnmount(() => controller?.abort());
|
||||
</script>
|
||||
+306
-196
@@ -1,214 +1,324 @@
|
||||
<template>
|
||||
<div v-show="active" @click="closeHovers" class="overlay"></div>
|
||||
<nav :class="{ active }">
|
||||
<template v-if="isLoggedIn">
|
||||
<button @click="toAccountSettings" class="action">
|
||||
<i class="material-icons">person</i>
|
||||
<span class="sidebar-profile"
|
||||
><strong>{{ user.username }}</strong
|
||||
><small v-if="user.profileName">{{ user.profileName }}</small></span
|
||||
<div v-show="active" @click="layout.closeHovers" class="overlay"></div>
|
||||
<nav
|
||||
class="workspace-sidebar"
|
||||
@keydown.stop
|
||||
:class="{ active }"
|
||||
:aria-label="t('explorer.navigation')"
|
||||
>
|
||||
<template v-if="auth.isLoggedIn && auth.user">
|
||||
<div class="sidebar-scroll">
|
||||
<div class="sidebar-section-title">
|
||||
<span>{{ t("explorer.bookmarks") }}</span>
|
||||
<button
|
||||
v-if="file.isFiles"
|
||||
:disabled="bookmarked || bookmarks.length >= 40"
|
||||
@click="addBookmark"
|
||||
:title="t('explorer.pinCurrent')"
|
||||
:aria-label="t('explorer.pinCurrent')"
|
||||
>
|
||||
<i class="material-icons">bookmark_add</i>
|
||||
</button>
|
||||
</div>
|
||||
<router-link
|
||||
class="explorer-link"
|
||||
to="/files/"
|
||||
@click="layout.closeHovers"
|
||||
><i class="material-icons">home</i
|
||||
><span>{{ t("sidebar.myFiles") }}</span></router-link
|
||||
>
|
||||
</button>
|
||||
<button
|
||||
class="action"
|
||||
@click="toRoot"
|
||||
:aria-label="$t('sidebar.myFiles')"
|
||||
:title="$t('sidebar.myFiles')"
|
||||
>
|
||||
<i class="material-icons">folder</i>
|
||||
<span>{{ $t("sidebar.myFiles") }}</span>
|
||||
</button>
|
||||
|
||||
<div v-if="user.perm.create">
|
||||
<button
|
||||
@click="showHover('newDir')"
|
||||
class="action"
|
||||
:aria-label="$t('sidebar.newFolder')"
|
||||
:title="$t('sidebar.newFolder')"
|
||||
<div
|
||||
v-for="bookmark in bookmarks"
|
||||
:key="bookmark.url"
|
||||
class="bookmark-row"
|
||||
>
|
||||
<i class="material-icons">create_new_folder</i>
|
||||
<span>{{ $t("sidebar.newFolder") }}</span>
|
||||
</button>
|
||||
|
||||
<button
|
||||
@click="showHover('newFile')"
|
||||
class="action"
|
||||
:aria-label="$t('sidebar.newFile')"
|
||||
:title="$t('sidebar.newFile')"
|
||||
>
|
||||
<i class="material-icons">note_add</i>
|
||||
<span>{{ $t("sidebar.newFile") }}</span>
|
||||
</button>
|
||||
<router-link
|
||||
class="explorer-link"
|
||||
:to="bookmark.url"
|
||||
:title="bookmark.name"
|
||||
@click="layout.closeHovers"
|
||||
><i class="material-icons">star_outline</i
|
||||
><span>{{ bookmark.name }}</span></router-link
|
||||
>
|
||||
<button
|
||||
@click="removeBookmark(bookmark.url)"
|
||||
:aria-label="t('explorer.unpin')"
|
||||
:title="t('explorer.unpin')"
|
||||
>
|
||||
<i class="material-icons">close</i>
|
||||
</button>
|
||||
</div>
|
||||
<div class="sidebar-section-title">
|
||||
<span>{{ t("explorer.folders") }}</span>
|
||||
<button
|
||||
v-if="file.isFiles && file.req?.isDir && auth.user.perm.create"
|
||||
@click="layout.showHover('newDir')"
|
||||
:title="t('sidebar.newFolder')"
|
||||
:aria-label="t('sidebar.newFolder')"
|
||||
>
|
||||
<i class="material-icons">create_new_folder</i>
|
||||
</button>
|
||||
<button
|
||||
v-if="file.isFiles && file.req?.isDir && auth.user.perm.create"
|
||||
@click="layout.showHover('newFile')"
|
||||
:title="t('sidebar.newFile')"
|
||||
:aria-label="t('sidebar.newFile')"
|
||||
>
|
||||
<i class="material-icons">note_add</i>
|
||||
</button>
|
||||
</div>
|
||||
<ul class="folder-tree" :aria-label="t('explorer.folders')">
|
||||
<FolderTreeNode
|
||||
v-if="file.req || route.name !== 'Files'"
|
||||
:key="auth.user.id"
|
||||
url="/files/"
|
||||
:name="t('sidebar.myFiles')"
|
||||
:depth="0"
|
||||
/>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div v-if="user.perm.admin">
|
||||
<button
|
||||
class="action"
|
||||
@click="toGlobalSettings"
|
||||
:aria-label="$t('sidebar.settings')"
|
||||
:title="$t('sidebar.settings')"
|
||||
<div class="sidebar-bottom">
|
||||
<div
|
||||
class="disk-usage"
|
||||
v-if="file.isFiles && !disableUsedPercentage && usage.total"
|
||||
>
|
||||
<i class="material-icons">settings_applications</i>
|
||||
<span>{{ $t("sidebar.settings") }}</span>
|
||||
</button>
|
||||
<div class="disk-usage-heading">
|
||||
<span>{{ t("sso.storage") }}</span
|
||||
><strong>{{ usage.percent }}%</strong>
|
||||
</div>
|
||||
<progress
|
||||
:value="usage.percent"
|
||||
max="100"
|
||||
:aria-label="t('sso.storage')"
|
||||
></progress>
|
||||
<small>{{
|
||||
t("sidebar.diskUsed", {
|
||||
used: prettyBytes(usage.used, { binary: true }),
|
||||
total: prettyBytes(usage.total, { binary: true }),
|
||||
})
|
||||
}}</small>
|
||||
</div>
|
||||
<div
|
||||
ref="account"
|
||||
class="sidebar-account"
|
||||
@keydown.esc.stop.prevent="closeAccount"
|
||||
>
|
||||
<div
|
||||
v-if="accountOpen"
|
||||
id="sidebar-account-menu"
|
||||
class="account-menu"
|
||||
role="menu"
|
||||
@keydown="menuKey"
|
||||
>
|
||||
<router-link
|
||||
role="menuitem"
|
||||
to="/settings/profile"
|
||||
@click="navigate"
|
||||
><i class="material-icons">manage_accounts</i
|
||||
>{{ t("settings.profileSettings") }}</router-link
|
||||
>
|
||||
<router-link
|
||||
v-if="auth.user.perm.share"
|
||||
role="menuitem"
|
||||
to="/settings/shares"
|
||||
@click="navigate"
|
||||
><i class="material-icons">link</i
|
||||
>{{ t("settings.shareManagement") }}</router-link
|
||||
>
|
||||
<router-link
|
||||
v-if="auth.user.perm.admin"
|
||||
role="menuitem"
|
||||
to="/settings/global"
|
||||
@click="navigate"
|
||||
><i class="material-icons">settings</i
|
||||
>{{ t("settings.globalSettings") }}</router-link
|
||||
>
|
||||
<router-link
|
||||
v-if="auth.user.perm.admin"
|
||||
role="menuitem"
|
||||
to="/settings/users"
|
||||
@click="navigate"
|
||||
><i class="material-icons">group</i
|
||||
>{{ t("settings.userManagement") }}</router-link
|
||||
>
|
||||
<button v-if="canLogout" role="menuitem" @click="logout">
|
||||
<i class="material-icons">logout</i>{{ t("sidebar.logout") }}
|
||||
</button>
|
||||
</div>
|
||||
<button
|
||||
ref="accountButton"
|
||||
class="account-button"
|
||||
aria-haspopup="menu"
|
||||
:aria-expanded="accountOpen"
|
||||
aria-controls="sidebar-account-menu"
|
||||
@click="accountOpen = !accountOpen"
|
||||
@keydown.down.prevent="openAccount"
|
||||
>
|
||||
<span class="account-avatar">{{
|
||||
auth.user.username.slice(0, 1).toUpperCase()
|
||||
}}</span>
|
||||
<span class="account-label"
|
||||
><strong>{{ auth.user.username }}</strong
|
||||
><small>{{
|
||||
auth.user.email || auth.user.profileName || "AniDev SSO"
|
||||
}}</small></span
|
||||
><i class="material-icons">more_horiz</i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<button
|
||||
v-if="canLogout"
|
||||
@click="logout"
|
||||
class="action"
|
||||
id="logout"
|
||||
:aria-label="$t('sidebar.logout')"
|
||||
:title="$t('sidebar.logout')"
|
||||
>
|
||||
<i class="material-icons">exit_to_app</i>
|
||||
<span>{{ $t("sidebar.logout") }}</span>
|
||||
</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<router-link
|
||||
v-if="!hideLoginButton"
|
||||
class="action"
|
||||
to="/login"
|
||||
:aria-label="$t('sidebar.login')"
|
||||
:title="$t('sidebar.login')"
|
||||
>
|
||||
<i class="material-icons">exit_to_app</i>
|
||||
<span>{{ $t("sidebar.login") }}</span>
|
||||
</router-link>
|
||||
|
||||
<router-link
|
||||
v-if="signup"
|
||||
class="action"
|
||||
to="/login"
|
||||
:aria-label="$t('sidebar.signup')"
|
||||
:title="$t('sidebar.signup')"
|
||||
>
|
||||
<i class="material-icons">person_add</i>
|
||||
<span>{{ $t("sidebar.signup") }}</span>
|
||||
</router-link>
|
||||
</template>
|
||||
|
||||
<div
|
||||
class="disk-usage"
|
||||
v-if="isFiles && !disableUsedPercentage && usage.total !== '0 B'"
|
||||
<router-link v-else-if="!hideLoginButton" class="explorer-link" to="/login"
|
||||
><i class="material-icons">login</i>{{ t("sidebar.login") }}</router-link
|
||||
>
|
||||
<div class="disk-usage-heading">
|
||||
<span>{{ $t("sso.storage") }}</span
|
||||
><strong>{{ usage.usedPercentage }}%</strong>
|
||||
</div>
|
||||
<progress
|
||||
:value="usage.usedPercentage"
|
||||
max="100"
|
||||
:aria-label="$t('sso.storage')"
|
||||
></progress>
|
||||
<small>{{
|
||||
$t("sidebar.diskUsed", { used: usage.used, total: usage.total })
|
||||
}}</small>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import { reactive } from "vue";
|
||||
import { mapActions, mapState } from "pinia";
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute } from "vue-router";
|
||||
import { onClickOutside } from "@vueuse/core";
|
||||
import { useAuthStore } from "@/stores/auth";
|
||||
import { useFileStore } from "@/stores/file";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
|
||||
import * as auth from "@/utils/auth";
|
||||
import {
|
||||
signup,
|
||||
hideLoginButton,
|
||||
disableUsedPercentage,
|
||||
noAuth,
|
||||
logoutPage,
|
||||
loginPage,
|
||||
} from "@/utils/constants";
|
||||
import { files as api } from "@/api";
|
||||
import { logout as signOut } from "@/utils/auth";
|
||||
import {
|
||||
disableUsedPercentage,
|
||||
hideLoginButton,
|
||||
noAuth,
|
||||
loginPage,
|
||||
logoutPage,
|
||||
baseURL,
|
||||
} from "@/utils/constants";
|
||||
import { parseBookmarks, type Bookmark } from "@/utils/bookmarks";
|
||||
import FolderTreeNode from "./FolderTreeNode.vue";
|
||||
import prettyBytes from "pretty-bytes";
|
||||
|
||||
const USAGE_DEFAULT = { used: "0 B", total: "0 B", usedPercentage: 0 };
|
||||
|
||||
export default {
|
||||
name: "sidebar",
|
||||
setup() {
|
||||
const usage = reactive(USAGE_DEFAULT);
|
||||
return { usage, usageAbortController: new AbortController() };
|
||||
const auth = useAuthStore(),
|
||||
file = useFileStore(),
|
||||
layout = useLayoutStore(),
|
||||
route = useRoute();
|
||||
const { t } = useI18n();
|
||||
const active = computed(() => layout.currentPromptName === "sidebar");
|
||||
const canLogout = !noAuth && (loginPage || logoutPage !== "/login");
|
||||
const account = ref<HTMLElement>(),
|
||||
accountButton = ref<HTMLButtonElement>(),
|
||||
accountOpen = ref(false);
|
||||
onClickOutside(account, () => (accountOpen.value = false));
|
||||
function closeAccount() {
|
||||
accountOpen.value = false;
|
||||
accountButton.value?.focus();
|
||||
}
|
||||
function navigate() {
|
||||
accountOpen.value = false;
|
||||
layout.closeHovers();
|
||||
}
|
||||
async function openAccount() {
|
||||
accountOpen.value = true;
|
||||
await nextTick();
|
||||
account.value?.querySelector<HTMLElement>("[role=menuitem]")?.focus();
|
||||
}
|
||||
function menuKey(event: KeyboardEvent) {
|
||||
if (!["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) return;
|
||||
event.preventDefault();
|
||||
const items = Array.from(
|
||||
account.value?.querySelectorAll<HTMLElement>("[role=menuitem]") || []
|
||||
);
|
||||
const index = items.indexOf(document.activeElement as HTMLElement);
|
||||
items[
|
||||
event.key === "Home"
|
||||
? 0
|
||||
: event.key === "End"
|
||||
? items.length - 1
|
||||
: (index + (event.key === "ArrowUp" ? -1 : 1) + items.length) %
|
||||
items.length
|
||||
]?.focus();
|
||||
}
|
||||
function logout() {
|
||||
accountOpen.value = false;
|
||||
signOut();
|
||||
}
|
||||
watch(
|
||||
() => route.path,
|
||||
() => (accountOpen.value = false)
|
||||
);
|
||||
const bookmarks = ref<Bookmark[]>([]);
|
||||
const bookmarkKey = computed(
|
||||
() => `filebrowser:${baseURL}:bookmarks:${auth.user?.id}`
|
||||
);
|
||||
watch(
|
||||
bookmarkKey,
|
||||
(key) => {
|
||||
try {
|
||||
bookmarks.value = parseBookmarks(localStorage.getItem(key));
|
||||
} catch {
|
||||
bookmarks.value = [];
|
||||
}
|
||||
},
|
||||
inject: ["$showError"],
|
||||
computed: {
|
||||
...mapState(useAuthStore, ["user", "isLoggedIn"]),
|
||||
...mapState(useFileStore, ["isFiles", "reload"]),
|
||||
...mapState(useLayoutStore, ["currentPromptName"]),
|
||||
active() {
|
||||
return this.currentPromptName === "sidebar";
|
||||
},
|
||||
signup: () => signup,
|
||||
hideLoginButton: () => hideLoginButton,
|
||||
disableUsedPercentage: () => disableUsedPercentage,
|
||||
canLogout: () => !noAuth && (loginPage || logoutPage !== "/login"),
|
||||
{ immediate: true }
|
||||
);
|
||||
function saveBookmarks() {
|
||||
try {
|
||||
localStorage.setItem(bookmarkKey.value, JSON.stringify(bookmarks.value));
|
||||
} catch {
|
||||
/* Private browsing can disable storage. */
|
||||
}
|
||||
}
|
||||
const currentFolder = computed(() => {
|
||||
const req = file.req;
|
||||
if (!req) return { name: t("sidebar.myFiles"), url: "/files/" };
|
||||
const url = req.isDir
|
||||
? req.url
|
||||
: req.url.slice(0, req.url.lastIndexOf("/") + 1);
|
||||
const part = url.replace(/\/+$/, "").split("/").pop() || "";
|
||||
return {
|
||||
name:
|
||||
url.replace(/\/+$/, "") === "/files"
|
||||
? t("sidebar.myFiles")
|
||||
: decodeURIComponent(part),
|
||||
url: url.replace(/\/+$/, "") + "/",
|
||||
};
|
||||
});
|
||||
const bookmarked = computed(
|
||||
() =>
|
||||
currentFolder.value.url === "/files/" ||
|
||||
bookmarks.value.some((entry) => entry.url === currentFolder.value.url)
|
||||
);
|
||||
function addBookmark() {
|
||||
if (bookmarked.value || bookmarks.value.length >= 40) return;
|
||||
bookmarks.value.push(currentFolder.value);
|
||||
saveBookmarks();
|
||||
}
|
||||
function removeBookmark(url: string) {
|
||||
bookmarks.value = bookmarks.value.filter((entry) => entry.url !== url);
|
||||
saveBookmarks();
|
||||
}
|
||||
const usage = ref({ used: 0, total: 0, percent: 0 });
|
||||
let usageController: AbortController | undefined;
|
||||
watch(
|
||||
() => file.req?.url,
|
||||
async () => {
|
||||
if (!file.isFiles || disableUsedPercentage || !file.req) return;
|
||||
usageController?.abort();
|
||||
const request = (usageController = new AbortController());
|
||||
try {
|
||||
const stats = await api.usage(currentFolder.value.url, request.signal);
|
||||
if (request.signal.aborted) return;
|
||||
usage.value = {
|
||||
used: stats.used,
|
||||
total: stats.total,
|
||||
percent:
|
||||
stats.total > 0
|
||||
? Math.max(
|
||||
0,
|
||||
Math.min(100, Math.round((stats.used / stats.total) * 100))
|
||||
)
|
||||
: 0,
|
||||
};
|
||||
} catch {
|
||||
/* Storage usage is optional. */
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
...mapActions(useLayoutStore, ["closeHovers", "showHover"]),
|
||||
abortOngoingFetchUsage() {
|
||||
this.usageAbortController.abort();
|
||||
},
|
||||
async fetchUsage() {
|
||||
const path = this.$route.path.endsWith("/")
|
||||
? this.$route.path
|
||||
: this.$route.path + "/";
|
||||
let usageStats = USAGE_DEFAULT;
|
||||
if (this.disableUsedPercentage) {
|
||||
return Object.assign(this.usage, usageStats);
|
||||
}
|
||||
try {
|
||||
this.abortOngoingFetchUsage();
|
||||
this.usageAbortController = new AbortController();
|
||||
const usage = await api.usage(path, this.usageAbortController.signal);
|
||||
usageStats = {
|
||||
used: prettyBytes(usage.used, { binary: true }),
|
||||
total: prettyBytes(usage.total, { binary: true }),
|
||||
usedPercentage:
|
||||
usage.total > 0
|
||||
? Math.min(
|
||||
100,
|
||||
Math.max(0, Math.round((usage.used / usage.total) * 100))
|
||||
)
|
||||
: 0,
|
||||
};
|
||||
} finally {
|
||||
return Object.assign(this.usage, usageStats);
|
||||
}
|
||||
},
|
||||
toRoot() {
|
||||
this.$router.push({ path: "/files" });
|
||||
this.closeHovers();
|
||||
},
|
||||
toAccountSettings() {
|
||||
this.$router.push({ path: "/settings/profile" });
|
||||
this.closeHovers();
|
||||
},
|
||||
toGlobalSettings() {
|
||||
this.$router.push({ path: "/settings/global" });
|
||||
this.closeHovers();
|
||||
},
|
||||
help() {
|
||||
this.showHover("help");
|
||||
},
|
||||
logout: auth.logout,
|
||||
},
|
||||
watch: {
|
||||
$route: {
|
||||
handler(to) {
|
||||
if (to.path.includes("/files")) {
|
||||
this.fetchUsage();
|
||||
}
|
||||
},
|
||||
immediate: true,
|
||||
},
|
||||
},
|
||||
unmounted() {
|
||||
this.abortOngoingFetchUsage();
|
||||
},
|
||||
};
|
||||
{ immediate: true }
|
||||
);
|
||||
onBeforeUnmount(() => usageController?.abort());
|
||||
</script>
|
||||
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<svg
|
||||
class="dicom-file-icon"
|
||||
viewBox="0 0 48 56"
|
||||
fill="none"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
d="M8 2h21l13 13v37a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2Z"
|
||||
fill="currentColor"
|
||||
fill-opacity=".12"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
/>
|
||||
<path
|
||||
d="M28 2v14h14"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
<text
|
||||
x="24"
|
||||
y="37"
|
||||
text-anchor="middle"
|
||||
fill="currentColor"
|
||||
font-family="system-ui, sans-serif"
|
||||
font-weight="700"
|
||||
font-size="10"
|
||||
>
|
||||
.dcm
|
||||
</text>
|
||||
</svg>
|
||||
</template>
|
||||
@@ -1,6 +1,8 @@
|
||||
<template>
|
||||
<div
|
||||
class="item"
|
||||
ref="itemElement"
|
||||
:class="{ 'has-thumbnail': showThumbnail }"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
:draggable="isDraggable"
|
||||
@@ -22,11 +24,14 @@
|
||||
:data-ext="getExtension(name).toLowerCase()"
|
||||
@contextmenu="contextMenu"
|
||||
>
|
||||
<div>
|
||||
<div class="file-symbol">
|
||||
<DicomIcon v-if="isDicom" />
|
||||
<img
|
||||
v-if="!readOnly && type === 'image' && isThumbsEnabled"
|
||||
v-lazy="thumbnailUrl"
|
||||
:alt="name"
|
||||
v-else-if="showThumbnail && thumbnailVisible && !thumbnailFailed"
|
||||
:src="thumbnailUrl"
|
||||
alt=""
|
||||
decoding="async"
|
||||
@error="thumbnailFailed = true"
|
||||
/>
|
||||
<i v-else class="material-icons"></i>
|
||||
</div>
|
||||
@@ -54,7 +59,8 @@ import { filesize } from "@/utils";
|
||||
import dayjs from "dayjs";
|
||||
import { files as api } from "@/api";
|
||||
import * as upload from "@/utils/upload";
|
||||
import { computed, inject, ref } from "vue";
|
||||
import { computed, inject, ref, watch, onMounted, onBeforeUnmount } from "vue";
|
||||
import DicomIcon from "./DicomIcon.vue";
|
||||
import { useRouter } from "vue-router";
|
||||
|
||||
const touches = ref<number>(0);
|
||||
@@ -116,7 +122,52 @@ const thumbnailUrl = computed(() => {
|
||||
});
|
||||
|
||||
const isThumbsEnabled = computed(() => {
|
||||
return enableThumbs;
|
||||
return enableThumbs && !authStore.user?.hidePreviews;
|
||||
});
|
||||
const isDicom = computed(() => /\.(dcm|dicom)$/i.test(props.name));
|
||||
const showThumbnail = computed(
|
||||
() =>
|
||||
!props.readOnly &&
|
||||
!props.isDir &&
|
||||
props.type === "image" &&
|
||||
!isDicom.value &&
|
||||
isThumbsEnabled.value
|
||||
);
|
||||
const thumbnailFailed = ref(false),
|
||||
thumbnailVisible = ref(false);
|
||||
const itemElement = ref<HTMLElement>();
|
||||
let thumbnailObserver: IntersectionObserver | undefined;
|
||||
function observeThumbnail() {
|
||||
thumbnailObserver?.disconnect();
|
||||
if (!showThumbnail.value || !itemElement.value) return;
|
||||
if (typeof IntersectionObserver === "undefined") {
|
||||
thumbnailVisible.value = true;
|
||||
return;
|
||||
}
|
||||
thumbnailObserver = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries.some((entry) => entry.isIntersecting)) {
|
||||
thumbnailVisible.value = true;
|
||||
thumbnailObserver?.disconnect();
|
||||
}
|
||||
},
|
||||
{ rootMargin: "150px" }
|
||||
);
|
||||
thumbnailObserver.observe(itemElement.value);
|
||||
}
|
||||
watch(
|
||||
[thumbnailUrl, showThumbnail],
|
||||
() => {
|
||||
thumbnailFailed.value = false;
|
||||
thumbnailVisible.value = false;
|
||||
observeThumbnail();
|
||||
},
|
||||
{ flush: "post" }
|
||||
);
|
||||
onMounted(observeThumbnail);
|
||||
onBeforeUnmount(() => {
|
||||
thumbnailObserver?.disconnect();
|
||||
cancelLongPress();
|
||||
});
|
||||
|
||||
const humanSize = () => {
|
||||
|
||||
@@ -0,0 +1,280 @@
|
||||
.files-workspace {
|
||||
padding-top: 12px;
|
||||
}
|
||||
/* Skipped row contents can prevent thumbnail observers from waking up. */
|
||||
#listing.list .item.has-thumbnail {
|
||||
content-visibility: visible;
|
||||
contain-intrinsic-size: none;
|
||||
}
|
||||
nav.workspace-sidebar {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
padding: 10px 8px 0;
|
||||
overflow: hidden;
|
||||
}
|
||||
.workspace-sidebar > div {
|
||||
margin: 0;
|
||||
border: 0;
|
||||
}
|
||||
.sidebar-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.sidebar-section-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
margin: 14px 8px 6px;
|
||||
color: var(--textPrimary);
|
||||
font-size: 11px;
|
||||
font-weight: 650;
|
||||
}
|
||||
.sidebar-section-title > span {
|
||||
flex: 1;
|
||||
}
|
||||
.workspace-sidebar button {
|
||||
cursor: pointer;
|
||||
color: var(--textSecondary);
|
||||
background: transparent;
|
||||
border: 0;
|
||||
}
|
||||
.sidebar-section-title button,
|
||||
.bookmark-row > button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 4px;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.sidebar-section-title button:disabled {
|
||||
opacity: 0.35;
|
||||
cursor: default;
|
||||
}
|
||||
.sidebar-section-title i,
|
||||
.bookmark-row > button i {
|
||||
font-size: 18px;
|
||||
}
|
||||
.explorer-link {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
min-width: 0;
|
||||
padding: 9px 10px;
|
||||
border-radius: 6px;
|
||||
color: var(--textSecondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.explorer-link > span {
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
.explorer-link i {
|
||||
font-size: 19px;
|
||||
color: var(--blue);
|
||||
}
|
||||
.explorer-link:hover,
|
||||
.folder-row:hover,
|
||||
.account-button:hover,
|
||||
.account-menu > *:hover,
|
||||
.sidebar-section-title button:enabled:hover,
|
||||
.bookmark-row > button:hover {
|
||||
background: var(--hover);
|
||||
}
|
||||
.explorer-link.router-link-exact-active,
|
||||
.folder-row.selected {
|
||||
background: var(--surfaceSecondary);
|
||||
color: var(--blue);
|
||||
}
|
||||
.bookmark-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
.bookmark-row .explorer-link {
|
||||
flex: 1;
|
||||
}
|
||||
.bookmark-row > button {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.folder-tree,
|
||||
.folder-node > ul {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
}
|
||||
.folder-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
border-radius: 6px;
|
||||
min-height: 34px;
|
||||
font-size: 13px;
|
||||
}
|
||||
.folder-row .folder-expand {
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
width: 24px;
|
||||
padding: 3px 0;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.folder-expand i {
|
||||
font-size: 18px;
|
||||
}
|
||||
.folder-row a {
|
||||
display: flex;
|
||||
gap: 7px;
|
||||
align-items: center;
|
||||
padding: 7px 8px 7px 0;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
color: inherit;
|
||||
}
|
||||
.folder-row a > span {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.folder-row a i {
|
||||
color: var(--blue);
|
||||
font-size: 19px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.tree-status {
|
||||
padding: 5px 12px 5px 26px;
|
||||
font-size: 11px;
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
.sidebar-bottom {
|
||||
flex-shrink: 0;
|
||||
padding-top: 8px;
|
||||
}
|
||||
.workspace-sidebar .disk-usage {
|
||||
margin: 0 4px 8px;
|
||||
padding: 10px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
}
|
||||
.workspace-sidebar .disk-usage small {
|
||||
font-size: 10px;
|
||||
}
|
||||
.sidebar-account {
|
||||
position: relative;
|
||||
border-top: 1px solid var(--borderPrimary);
|
||||
padding: 8px 0;
|
||||
}
|
||||
.account-button {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
padding: 8px;
|
||||
border-radius: 8px;
|
||||
text-align: start;
|
||||
}
|
||||
.account-avatar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
background: var(--surfaceSecondary);
|
||||
color: var(--blue);
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.account-label {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 3px;
|
||||
min-width: 0;
|
||||
}
|
||||
.account-label strong,
|
||||
.account-label small {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.account-label strong {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
}
|
||||
.account-label small {
|
||||
font-size: 10px;
|
||||
color: var(--textPrimary);
|
||||
}
|
||||
.account-button > i {
|
||||
font-size: 20px;
|
||||
}
|
||||
.account-menu {
|
||||
position: absolute;
|
||||
bottom: calc(100% + 4px);
|
||||
inset-inline: 0;
|
||||
background: var(--surfacePrimary);
|
||||
border: 1px solid var(--borderPrimary);
|
||||
box-shadow: 0 8px 24px #0003;
|
||||
border-radius: 10px;
|
||||
padding: 5px;
|
||||
z-index: 10;
|
||||
}
|
||||
.account-menu > a,
|
||||
.account-menu > button {
|
||||
display: flex;
|
||||
width: 100%;
|
||||
align-items: center;
|
||||
gap: 9px;
|
||||
padding: 10px 8px;
|
||||
color: var(--textSecondary);
|
||||
border-radius: 6px;
|
||||
text-align: start;
|
||||
font-size: 12px;
|
||||
line-height: 1.4;
|
||||
}
|
||||
.account-menu i {
|
||||
font-size: 19px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.account-menu > button {
|
||||
border-top: 1px solid var(--borderPrimary);
|
||||
margin-top: 4px;
|
||||
}
|
||||
#listing .item .file-symbol {
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.dicom-file-icon {
|
||||
width: 56px;
|
||||
height: 64px;
|
||||
color: var(--blue);
|
||||
margin-inline-end: 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
#listing.list .dicom-file-icon {
|
||||
width: 28px;
|
||||
height: 34px;
|
||||
}
|
||||
#listing.mosaic.gallery .dicom-file-icon {
|
||||
width: 80px;
|
||||
height: 96px;
|
||||
}
|
||||
@media (max-width: 736px) {
|
||||
.workspace-sidebar .sidebar-bottom {
|
||||
padding-bottom: env(safe-area-inset-bottom, 0px);
|
||||
}
|
||||
.files-workspace {
|
||||
padding-top: 6px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 737px) {
|
||||
nav.workspace-sidebar {
|
||||
width: 240px;
|
||||
}
|
||||
main {
|
||||
width: calc(100% - 280px);
|
||||
}
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
@import "./mdPreview.css";
|
||||
@import "./context-menu.css";
|
||||
@import "./workspace.css";
|
||||
@import "./explorer.css";
|
||||
|
||||
/* For testing only
|
||||
:focus {
|
||||
|
||||
@@ -283,7 +283,8 @@
|
||||
"userUpdated": "User updated!",
|
||||
"username": "Username",
|
||||
"users": "Users",
|
||||
"currentPassword": "Your Current Password"
|
||||
"currentPassword": "Your Current Password",
|
||||
"showPreviews": "Show previews"
|
||||
},
|
||||
"sidebar": {
|
||||
"diskUsed": "{used} of {total} used",
|
||||
@@ -367,5 +368,13 @@
|
||||
"checksums": "Checksums",
|
||||
"autoEncoding": "Automatic",
|
||||
"usedEncoding": "Using"
|
||||
},
|
||||
"explorer": {
|
||||
"navigation": "File navigation",
|
||||
"bookmarks": "Bookmarks",
|
||||
"pinCurrent": "Pin current folder",
|
||||
"unpin": "Remove bookmark",
|
||||
"folders": "Folders",
|
||||
"retry": "Retry"
|
||||
}
|
||||
}
|
||||
@@ -280,7 +280,8 @@
|
||||
"userUpdated": "Пользователь изменен!",
|
||||
"username": "Имя пользователя",
|
||||
"users": "Пользователи",
|
||||
"currentPassword": "Your Current Password"
|
||||
"currentPassword": "Your Current Password",
|
||||
"showPreviews": "Показ превью"
|
||||
},
|
||||
"sidebar": {
|
||||
"diskUsed": "Занято {used} из {total}",
|
||||
@@ -364,5 +365,13 @@
|
||||
"checksums": "Контрольные суммы",
|
||||
"autoEncoding": "Автоматически",
|
||||
"usedEncoding": "Используется"
|
||||
},
|
||||
"explorer": {
|
||||
"navigation": "Навигация по файлам",
|
||||
"bookmarks": "Закладки",
|
||||
"pinCurrent": "Закрепить текущую папку",
|
||||
"unpin": "Убрать закладку",
|
||||
"folders": "Папки",
|
||||
"retry": "Повторить"
|
||||
}
|
||||
}
|
||||
Vendored
+1
@@ -12,6 +12,7 @@ interface IUser {
|
||||
rules: IRule[];
|
||||
lockPassword: boolean;
|
||||
hideDotfiles: boolean;
|
||||
hidePreviews?: boolean;
|
||||
singleClick: boolean;
|
||||
redirectAfterCopyMove: boolean;
|
||||
dateFormat: boolean;
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { parseBookmarks } from "../bookmarks";
|
||||
describe("folder bookmarks", () => {
|
||||
it("handles unavailable, corrupt or unrelated storage", () => {
|
||||
for (const value of [null, "broken", "{}", '"string"'])
|
||||
expect(parseBookmarks(value)).toEqual([]);
|
||||
});
|
||||
it("keeps unique file locations and rejects external URLs", () => {
|
||||
expect(
|
||||
parseBookmarks(
|
||||
JSON.stringify([
|
||||
{ name: "Scans", url: "/files/scans/" },
|
||||
{ name: "Duplicate", url: "/files/scans/" },
|
||||
{ name: "Wrong", url: "https://example.com" },
|
||||
{ name: "Wrong", url: "/files-other/" },
|
||||
{ name: "Wrong", url: "/files/a/?secret=1" },
|
||||
null,
|
||||
])
|
||||
)
|
||||
).toEqual([{ name: "Scans", url: "/files/scans/" }]);
|
||||
});
|
||||
it("bounds the number and length of bookmarks", () => {
|
||||
const entries = parseBookmarks(
|
||||
JSON.stringify(
|
||||
Array.from({ length: 80 }, (_, i) => ({
|
||||
name: "a".repeat(500),
|
||||
url: `/files/${i}/`,
|
||||
}))
|
||||
)
|
||||
);
|
||||
expect(entries).toHaveLength(40);
|
||||
expect(entries[0].name).toHaveLength(255);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
export interface Bookmark {
|
||||
name: string;
|
||||
url: string;
|
||||
}
|
||||
export function parseBookmarks(value: string | null): Bookmark[] {
|
||||
try {
|
||||
const entries: unknown = JSON.parse(value || "[]");
|
||||
if (!Array.isArray(entries)) return [];
|
||||
const seen = new Set<string>();
|
||||
return entries
|
||||
.filter((entry): entry is Bookmark => {
|
||||
if (
|
||||
!entry ||
|
||||
typeof entry.name !== "string" ||
|
||||
typeof entry.url !== "string" ||
|
||||
!/^\/files(?:\/|$)/.test(entry.url) ||
|
||||
/[?#\r\n]/.test(entry.url) ||
|
||||
seen.has(entry.url)
|
||||
)
|
||||
return false;
|
||||
seen.add(entry.url);
|
||||
return true;
|
||||
})
|
||||
.slice(0, 40)
|
||||
.map((entry) => ({ name: entry.name.slice(0, 255), url: entry.url }));
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -1,27 +1,11 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="files-workspace">
|
||||
<header-bar
|
||||
v-if="error || fileStore.req?.type === undefined"
|
||||
showMenu
|
||||
showLogo
|
||||
/>
|
||||
|
||||
<breadcrumbs base="/files" />
|
||||
<section v-if="fileStore.req?.isDir" class="workspace-overview">
|
||||
<div>
|
||||
<span class="eyebrow">{{ t("sso.workspace") }}</span>
|
||||
<h1>
|
||||
{{
|
||||
route.path.replace(/\/+$/, "") === "/files"
|
||||
? t("sidebar.myFiles")
|
||||
: fileStore.req.name
|
||||
}}
|
||||
</h1>
|
||||
</div>
|
||||
<span class="workspace-count">{{
|
||||
t("sso.itemsCount", { count: fileStore.req.items?.length || 0 })
|
||||
}}</span>
|
||||
</section>
|
||||
<errors v-if="error" :errorCode="error.status" />
|
||||
<component v-else-if="currentView" :is="currentView"></component>
|
||||
<div v-else>
|
||||
@@ -53,7 +37,6 @@ import { useFileStore } from "@/stores/file";
|
||||
import { useLayoutStore } from "@/stores/layout";
|
||||
|
||||
import HeaderBar from "@/components/header/HeaderBar.vue";
|
||||
import Breadcrumbs from "@/components/Breadcrumbs.vue";
|
||||
import Errors from "@/views/Errors.vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import { useRoute } from "vue-router";
|
||||
|
||||
@@ -23,6 +23,16 @@
|
||||
<input type="checkbox" name="singleClick" v-model="singleClick" />
|
||||
{{ t("settings.singleClick") }}
|
||||
</p>
|
||||
<p>
|
||||
<label
|
||||
><input
|
||||
type="checkbox"
|
||||
name="showPreviews"
|
||||
v-model="showPreviews"
|
||||
/>
|
||||
{{ t("settings.showPreviews") }}</label
|
||||
>
|
||||
</p>
|
||||
<p>
|
||||
<input
|
||||
type="checkbox"
|
||||
@@ -73,6 +83,7 @@ const $showSuccess = inject<IToastSuccess>("$showSuccess")!;
|
||||
const $showError = inject<IToastError>("$showError")!;
|
||||
|
||||
const hideDotfiles = ref<boolean>(false);
|
||||
const showPreviews = ref(true);
|
||||
const singleClick = ref<boolean>(false);
|
||||
const redirectAfterCopyMove = ref<boolean>(false);
|
||||
const dateFormat = ref<boolean>(false);
|
||||
@@ -84,6 +95,7 @@ onMounted(async () => {
|
||||
if (authStore.user === null) return false;
|
||||
locale.value = authStore.user.locale;
|
||||
hideDotfiles.value = authStore.user.hideDotfiles;
|
||||
showPreviews.value = !authStore.user.hidePreviews;
|
||||
singleClick.value = authStore.user.singleClick;
|
||||
redirectAfterCopyMove.value = authStore.user.redirectAfterCopyMove;
|
||||
dateFormat.value = authStore.user.dateFormat;
|
||||
@@ -104,6 +116,7 @@ const updateSettings = async (event: Event) => {
|
||||
id: authStore.user.id,
|
||||
locale: locale.value,
|
||||
hideDotfiles: hideDotfiles.value,
|
||||
hidePreviews: !showPreviews.value,
|
||||
singleClick: singleClick.value,
|
||||
redirectAfterCopyMove: redirectAfterCopyMove.value,
|
||||
dateFormat: dateFormat.value,
|
||||
@@ -113,6 +126,7 @@ const updateSettings = async (event: Event) => {
|
||||
await api.update(data, [
|
||||
"locale",
|
||||
"hideDotfiles",
|
||||
"hidePreviews",
|
||||
"singleClick",
|
||||
"redirectAfterCopyMove",
|
||||
"dateFormat",
|
||||
|
||||
@@ -15,6 +15,7 @@ type userInfo struct {
|
||||
Commands []string `json:"commands"`
|
||||
LockPassword bool `json:"lockPassword"`
|
||||
HideDotfiles bool `json:"hideDotfiles"`
|
||||
HidePreviews bool `json:"hidePreviews"`
|
||||
DateFormat bool `json:"dateFormat"`
|
||||
Username string `json:"username"`
|
||||
ProfileName string `json:"profileName,omitempty"`
|
||||
|
||||
+1
-1
@@ -447,5 +447,5 @@ func applySSOIdentity(u *users.User, i sessionIdentity) {
|
||||
u.DisplayName = i.Name
|
||||
}
|
||||
func ssoUserInfo(u *users.User) userInfo {
|
||||
return userInfo{ID: u.ID, Username: u.DisplayName, ProfileName: u.ProfileName, Email: u.Email, Locale: u.Locale, ViewMode: u.ViewMode, SingleClick: u.SingleClick, RedirectAfterCopyMove: u.RedirectAfterCopyMove, Perm: u.Perm, Commands: []string{}, LockPassword: true, HideDotfiles: u.HideDotfiles, DateFormat: u.DateFormat, AceEditorTheme: u.AceEditorTheme}
|
||||
return userInfo{ID: u.ID, Username: u.DisplayName, ProfileName: u.ProfileName, Email: u.Email, Locale: u.Locale, ViewMode: u.ViewMode, SingleClick: u.SingleClick, RedirectAfterCopyMove: u.RedirectAfterCopyMove, Perm: u.Perm, Commands: []string{}, LockPassword: true, HideDotfiles: u.HideDotfiles, HidePreviews: u.HidePreviews, DateFormat: u.DateFormat, AceEditorTheme: u.AceEditorTheme}
|
||||
}
|
||||
@@ -142,6 +142,16 @@ func TestOIDCSessionLifecycle(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
for _, hidden := range []bool{true, false} {
|
||||
if err = st.Users.Update(&users.User{ID: firstID, HidePreviews: hidden}, "HidePreviews"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
check = request("GET", "/api/session")
|
||||
var profile userInfo
|
||||
if err := json.Unmarshal(check.Body.Bytes(), &profile); err != nil || profile.HidePreviews != hidden {
|
||||
t.Fatalf("session lost preview preference: %s (%v)", check.Body.String(), err)
|
||||
}
|
||||
}
|
||||
roles = []string{"User"}
|
||||
check = request("GET", "/api/session")
|
||||
if check.Code != 200 || !strings.Contains(check.Body.String(), `"admin":true`) {
|
||||
|
||||
+1
-1
@@ -130,7 +130,7 @@ var userPutHandler = withSelfOrAdmin(func(w http.ResponseWriter, r *http.Request
|
||||
if req.Data == nil || req.Data.ID != d.raw.(uint) || len(req.Which) == 0 || req.Data.Password != "" {
|
||||
return http.StatusBadRequest, nil
|
||||
}
|
||||
allowed := map[string]string{"scope": "Scope", "perm": "Perm", "rules": "Rules", "locale": "Locale", "viewmode": "ViewMode", "singleclick": "SingleClick", "redirectaftercopymove": "RedirectAfterCopyMove", "hidedotfiles": "HideDotfiles", "dateformat": "DateFormat", "aceeditortheme": "AceEditorTheme", "sorting": "Sorting"}
|
||||
allowed := map[string]string{"scope": "Scope", "perm": "Perm", "rules": "Rules", "locale": "Locale", "viewmode": "ViewMode", "singleclick": "SingleClick", "redirectaftercopymove": "RedirectAfterCopyMove", "hidedotfiles": "HideDotfiles", "hidepreviews": "HidePreviews", "dateformat": "DateFormat", "aceeditortheme": "AceEditorTheme", "sorting": "Sorting"}
|
||||
for i, field := range req.Which {
|
||||
canonical, ok := allowed[strings.ToLower(field)]
|
||||
if !ok {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
param([string]$Version = '3.0.0-sso.10')
|
||||
param([string]$Version = '3.0.0-sso.11')
|
||||
$ErrorActionPreference = 'Stop'
|
||||
$repo = (Resolve-Path (Join-Path $PSScriptRoot '..')).Path
|
||||
Push-Location $repo
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
cd "$(dirname "$0")/.."
|
||||
VERSION="${VERSION:-3.0.0-sso.10}"
|
||||
VERSION="${VERSION:-3.0.0-sso.11}"
|
||||
COMMIT=$(git rev-parse --short HEAD)
|
||||
(cd frontend && pnpm install --frozen-lockfile && pnpm run build)
|
||||
mkdir -p build/release/linux-amd64
|
||||
|
||||
@@ -38,6 +38,16 @@ func TestPartialUserUpdatePreservesIdentityIndex(t *testing.T) {
|
||||
t.Fatalf("unexpected user: %+v", got)
|
||||
}
|
||||
}
|
||||
// Preferences must preserve false values, including when re-enabling previews.
|
||||
for _, hidden := range []bool{true, false} {
|
||||
if err = st.Users.Update(&users.User{ID: u.ID, HidePreviews: hidden}, "HidePreviews"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
got, err := st.Users.Get("", false, "sso:stable-subject")
|
||||
if err != nil || got.HidePreviews != hidden {
|
||||
t.Fatalf("preview preference did not persist: %+v %v", got, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetByScope must match case-insensitively: on a case-insensitive filesystem
|
||||
|
||||
@@ -37,6 +37,7 @@ type User struct {
|
||||
Fs afero.Fs `json:"-" yaml:"-"`
|
||||
Rules []rules.Rule `json:"rules"`
|
||||
HideDotfiles bool `json:"hideDotfiles"`
|
||||
HidePreviews bool `json:"hidePreviews"`
|
||||
DateFormat bool `json:"dateFormat"`
|
||||
AceEditorTheme string `json:"aceEditorTheme"`
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user