Fix URI encoding and navigation issues
This commit is contained in:
@@ -83,20 +83,11 @@ const sort_children = children => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const navigate = (path, pushHist) => {
|
const navigate = (path, push_history) => {
|
||||||
state.loading = true
|
state.loading = true
|
||||||
|
|
||||||
fs_get_node(state.root.id, path).then(resp => {
|
fs_get_node(state.root.id, path).then(resp => {
|
||||||
window.document.title = resp.path[resp.base_index].name+" ~ pixeldrain"
|
open_node(resp, push_history)
|
||||||
if (pushHist) {
|
|
||||||
window.history.pushState(
|
|
||||||
{},
|
|
||||||
window.document.title,
|
|
||||||
"/d/"+resp.path[0].id+resp.path[resp.base_index].path,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
open_node(resp)
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
alert(err)
|
alert(err)
|
||||||
@@ -105,7 +96,23 @@ const navigate = (path, pushHist) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const open_node = (node) => {
|
const open_node = (node, push_history) => {
|
||||||
|
// We need to properly URL encode the file paths so they don't cause
|
||||||
|
// issues.. but we also want the slashes to stay clean. So here we encode
|
||||||
|
// the whole path, then decode the slashes
|
||||||
|
let cleanup_func = p => p.path_uri = encodeURIComponent(p.path).replaceAll("%2F", "/")
|
||||||
|
node.path.forEach(cleanup_func)
|
||||||
|
node.children.forEach(cleanup_func)
|
||||||
|
|
||||||
|
// Update window title and navigation history
|
||||||
|
window.document.title = node.path[node.base_index].name+" ~ pixeldrain"
|
||||||
|
if (push_history) {
|
||||||
|
window.history.pushState(
|
||||||
|
{}, window.document.title,
|
||||||
|
"/d/"+node.path[0].id+node.path[node.base_index].path,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// If the new node is a child of the previous node we save the parent's
|
// If the new node is a child of the previous node we save the parent's
|
||||||
// children array
|
// children array
|
||||||
if (node.path.length > 0 && node.path[node.path.length-1].path === state.base.path) {
|
if (node.path.length > 0 && node.path[node.path.length-1].path === state.base.path) {
|
||||||
@@ -152,10 +159,13 @@ const open_node = (node) => {
|
|||||||
state.viewer_type = ""
|
state.viewer_type = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.debug("Opened node", node)
|
||||||
|
|
||||||
// Remove spinner
|
// Remove spinner
|
||||||
state.loading = false
|
state.loading = false
|
||||||
}
|
}
|
||||||
onMount(() => open_node(window.initial_node))
|
|
||||||
|
onMount(() => open_node(window.initial_node, false))
|
||||||
|
|
||||||
// Opens a sibling of the currently open file. The offset is relative to the
|
// Opens a sibling of the currently open file. The offset is relative to the
|
||||||
// file which is currently open. Give a positive number to move forward and a
|
// file which is currently open. Give a positive number to move forward and a
|
||||||
@@ -221,7 +231,7 @@ const open_sibling = async offset => {
|
|||||||
// If we found a sibling we open it
|
// If we found a sibling we open it
|
||||||
if (next_sibling !== null) {
|
if (next_sibling !== null) {
|
||||||
console.debug("Opening sibling", next_sibling)
|
console.debug("Opening sibling", next_sibling)
|
||||||
navigate(next_sibling.path,true)
|
navigate(next_sibling.path, true)
|
||||||
} else {
|
} else {
|
||||||
console.debug("No siblings found")
|
console.debug("No siblings found")
|
||||||
state.loading = false
|
state.loading = false
|
||||||
@@ -230,11 +240,9 @@ const open_sibling = async offset => {
|
|||||||
|
|
||||||
// Capture browser back and forward navigation buttons
|
// Capture browser back and forward navigation buttons
|
||||||
window.onpopstate = (e) => {
|
window.onpopstate = (e) => {
|
||||||
if(e.state){
|
// Get the part of the URL after the bucket ID and navigate to it
|
||||||
// Get the part of the URL after the bucket ID and navigate to it
|
let locsplit = document.location.pathname.split(state.root.id+"/", 2)
|
||||||
let locsplit = document.location.pathname.split(state.root.id+"/", 2)
|
navigate(decodeURIComponent(locsplit[1]), false)
|
||||||
navigate(decodeURIComponent(locsplit[1]))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const keydown = e => {
|
const keydown = e => {
|
||||||
@@ -297,9 +305,6 @@ const share = () => {
|
|||||||
on:click|preventDefault={() => {navigate(node.path, true)}}>
|
on:click|preventDefault={() => {navigate(node.path, true)}}>
|
||||||
{node.name}
|
{node.name}
|
||||||
</a>
|
</a>
|
||||||
{#if i < state.base_index}
|
|
||||||
/
|
|
||||||
{/if}
|
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -443,11 +448,10 @@ const share = () => {
|
|||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
}
|
}
|
||||||
.breadcrumb {
|
.breadcrumb {
|
||||||
border-radius: 1em;
|
|
||||||
min-width: 1em;
|
min-width: 1em;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
padding: 4px 8px;
|
padding: 6px 8px;
|
||||||
margin: 2px 6px;
|
margin: 4px;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -48,7 +48,7 @@ const node_icon = node => {
|
|||||||
<div class="gallery">
|
<div class="gallery">
|
||||||
{#each state.children as child, index (child.path)}
|
{#each state.children as child, index (child.path)}
|
||||||
<a class="file"
|
<a class="file"
|
||||||
href={state.path_root+child.path}
|
href={state.path_root+child.path_uri}
|
||||||
on:click|preventDefault={() => {dispatch("node_click", index)}}
|
on:click|preventDefault={() => {dispatch("node_click", index)}}
|
||||||
class:selected={child.fm_selected}
|
class:selected={child.fm_selected}
|
||||||
class:hidden={child.name.startsWith(".") && !show_hidden}
|
class:hidden={child.name.startsWith(".") && !show_hidden}
|
||||||
|
@@ -54,7 +54,7 @@ const node_icon = node => {
|
|||||||
</tr>
|
</tr>
|
||||||
{#each state.children as child, index (child.path)}
|
{#each state.children as child, index (child.path)}
|
||||||
<a
|
<a
|
||||||
href={state.path_root+child.path}
|
href={state.path_root+child.path_uri}
|
||||||
on:click|preventDefault={() => {dispatch("node_click", index)}}
|
on:click|preventDefault={() => {dispatch("node_click", index)}}
|
||||||
class="node"
|
class="node"
|
||||||
class:node_selected={child.fm_selected}
|
class:node_selected={child.fm_selected}
|
||||||
|
Reference in New Issue
Block a user