Allow password entry for shared directories

This commit is contained in:
Pixeldrain-Server committed 2026-10-05 17:39:39 +02:00
1 parent 6f0f58d2d9
commit f3738cbc4d
8 files changed
+91 -24

No files matched your search

+16 -4
View File
@@ -45,8 +45,8 @@ export class FSNavigator {
last_requested_path: string = ""
navigation_error: string = ""
navigate = async (path: string, push_history: boolean) => {
if (path === this.last_requested_path) {
navigate = async (path: string, push_history: boolean, password?: string) => {
if (path === this.last_requested_path && password === undefined) {
console.debug("FSNavigator: Requested path ", path, " is equal to current path. Debouncing")
return
}
@@ -56,6 +56,18 @@ export class FSNavigator {
path = "/" + path
}
// The password of a shared directory is entered by the visitor, or it's
// in the link they opened. It's sent in a cookie, which is the only way
// to get it into the requests for images, videos and downloads. The
// cookie's path is the directory, so each directory has its own password
if (password === undefined && this.history_enabled) {
password = new URLSearchParams(window.location.search).get("password")
}
if (password) {
document.cookie = "nova_fs_password=" + encodeURIComponent(password) +
"; path=" + fs_path_url(path.split("/")[1]) + "; samesite=lax"
}
console.debug("FSNavigator: Navigating to path", path, push_history)
try {
@@ -70,9 +82,9 @@ export class FSNavigator {
this.open_node(resp, push_history)
} catch (err: any) {
if (err.value !== undefined && err.value === "path_not_found") {
if (path !== this.path[0].path && path !== "/" && path !== "") {
if (path !== this.path[0]?.path && path !== "/" && path !== "") {
console.debug("Path", path, "was not found, trying to navigate to parent")
this.navigate(fs_split_path(path).parent, push_history)
this.navigate(fs_split_path(path).parent, push_history, password)
}
} else if (err.value !== undefined) {
this.navigation_error = err.value