parent
e66951fd11
commit
db71f75236
|
@ -21,6 +21,7 @@ body {
|
||||||
|
|
||||||
.breadcrumb {
|
.breadcrumb {
|
||||||
font-size: 1.25em;
|
font-size: 1.25em;
|
||||||
|
padding-right: 0.6em;
|
||||||
}
|
}
|
||||||
|
|
||||||
.breadcrumb > a {
|
.breadcrumb > a {
|
||||||
|
@ -45,8 +46,6 @@ body {
|
||||||
.breadcrumb svg {
|
.breadcrumb svg {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
fill: rgba(3,47,98,0.5);
|
fill: rgba(3,47,98,0.5);
|
||||||
padding-right: 0.5em;
|
|
||||||
padding-left: 0.5em;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.toolbox {
|
.toolbox {
|
||||||
|
|
|
@ -29,10 +29,6 @@ let $uploadersTable;
|
||||||
* @type Element
|
* @type Element
|
||||||
*/
|
*/
|
||||||
let $emptyFolder;
|
let $emptyFolder;
|
||||||
/**
|
|
||||||
* @type string
|
|
||||||
*/
|
|
||||||
let baseDir;
|
|
||||||
|
|
||||||
class Uploader {
|
class Uploader {
|
||||||
/**
|
/**
|
||||||
|
@ -122,28 +118,35 @@ class Uploader {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add breadcrumb
|
* Add breadcrumb
|
||||||
* @param {string} value
|
* @param {string} href
|
||||||
|
* @param {string} uri_prefix
|
||||||
*/
|
*/
|
||||||
function addBreadcrumb(value) {
|
function addBreadcrumb(href, uri_prefix) {
|
||||||
const $breadcrumb = document.querySelector(".breadcrumb");
|
const $breadcrumb = document.querySelector(".breadcrumb");
|
||||||
const parts = value.split("/").filter(v => !!v);
|
let parts = [];
|
||||||
|
if (href === "/") {
|
||||||
|
parts = [""];
|
||||||
|
} else {
|
||||||
|
parts = href.split("/");
|
||||||
|
}
|
||||||
const len = parts.length;
|
const len = parts.length;
|
||||||
let path = "";
|
let path = uri_prefix.slice(0, -1);
|
||||||
for (let i = 0; i < len; i++) {
|
for (let i = 0; i < len; i++) {
|
||||||
const name = parts[i];
|
const name = parts[i];
|
||||||
if (i > 0) {
|
if (i > 0) {
|
||||||
path += "/" + name;
|
path += "/" + encodeURI(name);
|
||||||
}
|
}
|
||||||
if (i === len - 1) {
|
if (i === 0) {
|
||||||
|
$breadcrumb.insertAdjacentHTML("beforeend", `<a href="${path}"><svg width="16" height="16" viewBox="0 0 16 16"><path d="M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5z"/></svg></a>`);
|
||||||
|
} else if (i === len - 1) {
|
||||||
$breadcrumb.insertAdjacentHTML("beforeend", `<b>${name}</b>`);
|
$breadcrumb.insertAdjacentHTML("beforeend", `<b>${name}</b>`);
|
||||||
baseDir = name;
|
|
||||||
} else if (i === 0) {
|
|
||||||
$breadcrumb.insertAdjacentHTML("beforeend", `<a href="/"><b>${name}</b></a>`);
|
|
||||||
} else {
|
} else {
|
||||||
$breadcrumb.insertAdjacentHTML("beforeend", `<a href="${encodeURI(path)}">${name}</a>`);
|
$breadcrumb.insertAdjacentHTML("beforeend", `<a href="${path}">${name}</a>`);
|
||||||
}
|
}
|
||||||
|
if (i !== len - 1) {
|
||||||
$breadcrumb.insertAdjacentHTML("beforeend", `<span class="separator">/</span>`);
|
$breadcrumb.insertAdjacentHTML("beforeend", `<span class="separator">/</span>`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -333,7 +336,7 @@ function ready() {
|
||||||
document.getElementById('search').value = params.q;
|
document.getElementById('search').value = params.q;
|
||||||
}
|
}
|
||||||
|
|
||||||
addBreadcrumb(DATA.breadcrumb);
|
addBreadcrumb(DATA.href, DATA.uri_prefix);
|
||||||
if (Array.isArray(DATA.paths)) {
|
if (Array.isArray(DATA.paths)) {
|
||||||
const len = DATA.paths.length;
|
const len = DATA.paths.length;
|
||||||
if (len > 0) {
|
if (len > 0) {
|
||||||
|
|
|
@ -684,12 +684,10 @@ impl Server {
|
||||||
res: &mut Response,
|
res: &mut Response,
|
||||||
) -> BoxResult<()> {
|
) -> BoxResult<()> {
|
||||||
paths.sort_unstable();
|
paths.sort_unstable();
|
||||||
let rel_path = match self.args.path.parent() {
|
let href = format!("/{}", normalize_path(path.strip_prefix(&self.args.path)?));
|
||||||
Some(p) => path.strip_prefix(p).unwrap(),
|
|
||||||
None => path,
|
|
||||||
};
|
|
||||||
let data = IndexData {
|
let data = IndexData {
|
||||||
breadcrumb: normalize_path(rel_path),
|
href: href.clone(),
|
||||||
|
uri_prefix: self.args.uri_prefix.clone(),
|
||||||
paths,
|
paths,
|
||||||
allow_upload: self.args.allow_upload,
|
allow_upload: self.args.allow_upload,
|
||||||
allow_delete: self.args.allow_delete,
|
allow_delete: self.args.allow_delete,
|
||||||
|
@ -700,17 +698,14 @@ impl Server {
|
||||||
"__SLOT__",
|
"__SLOT__",
|
||||||
&format!(
|
&format!(
|
||||||
r#"
|
r#"
|
||||||
<title>Files in {}/ - Duf</title>
|
<title>Index of {} - Duf</title>
|
||||||
<style>{}</style>
|
<style>{}</style>
|
||||||
<script>
|
<script>
|
||||||
const DATA =
|
const DATA =
|
||||||
{}
|
{}
|
||||||
{}</script>
|
{}</script>
|
||||||
"#,
|
"#,
|
||||||
rel_path.display(),
|
href, INDEX_CSS, data, INDEX_JS
|
||||||
INDEX_CSS,
|
|
||||||
data,
|
|
||||||
INDEX_JS
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
res.headers_mut()
|
res.headers_mut()
|
||||||
|
@ -819,7 +814,8 @@ const DATA =
|
||||||
|
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
struct IndexData {
|
struct IndexData {
|
||||||
breadcrumb: String,
|
href: String,
|
||||||
|
uri_prefix: String,
|
||||||
paths: Vec<PathItem>,
|
paths: Vec<PathItem>,
|
||||||
allow_upload: bool,
|
allow_upload: bool,
|
||||||
allow_delete: bool,
|
allow_delete: bool,
|
||||||
|
|
Loading…
Reference in New Issue