diff --git a/pywebfs/pywebfs.py b/pywebfs/pywebfs.py index 2055b29..1d20582 100755 --- a/pywebfs/pywebfs.py +++ b/pywebfs/pywebfs.py @@ -281,16 +281,19 @@ background: url('data:image/svg+xml;utf8,{UPFOLDER_CSS}') no-repeat; width: 100px; }} + .rootfolder {{ + background: url('data:image/svg+xml;utf8,{HOME_CSS}') no-repeat; + }} .sort {{ background: url('data:image/svg+xml;utf8,{SORT_CSS}') no-repeat; text-indent: 15px !important; }} - .folder, .file, .link, .upfolder, .sort {{ + .folder, .file, .link, .upfolder, .rootfolder, .sort {{ display: inline-block; text-indent: 20px; background-size: 16px 16px; }} - .folder, .file, .link, .upfolder {{ + .folder, .file, .link, .upfolder, .rootfolder {{ background-position-x: 8px; background-position-y: 50%; }} @@ -304,13 +307,14 @@ }} tr.titles th {{ background-color: #d5d5d5; + width: 1px; }} th.name {{ - min-width: 100px; + width: 100px; padding-left: 10px; }} #files th.name {{ - min-width: 200px; + width: 200px; }} table.searchresult tr td {{ vertical-align: top; @@ -345,7 +349,7 @@ body {{ -webkit-text-size-adjust: 180%; }} - .search, .searchtxt, .home, .folder, .file, .link, .upfolder, #files tr td:last-child a {{ + .search, .searchtxt, .home, .folder, .file, .link, .upfolder, .rootfolder, #files tr td:last-child a {{ background-size: 32px 32px; text-indent: 40px; }} @@ -421,7 +425,7 @@ if (filesTable) { lastRow = filesTable.rows.length - 1; firstRow = 2; - filesTable.rows[2].querySelector('a').focus(); + focusRow(2) setTimeout(() => { window.scrollTo(0, 0); }, 40); @@ -451,6 +455,20 @@ filesTable.style.display = ""; }); + function focusRow(rowIndex) { + anchor = filesTable.rows[rowIndex].querySelector('a'); + anchor.focus(); + path = document.getElementById("file"); + if(! [".",".."].includes(anchor.innerHTML)) { + href = anchor.getAttribute("href") + path.href = href + path.textContent = "/" + decodeURIComponent(href); + }else{ + path.href = ""; + path.innerHTML = ""; + } + } + function focusFile(event, table, start, increment, nb) { event.preventDefault(); nbRows = 0; @@ -464,7 +482,7 @@ window.scrollBy(0, focusRect.top-bottomHeader); if (focusRect.bottom > window.innerHeight-focusRect.height) window.scrollBy(0, focusRect.bottom-window.innerHeight+focusRect.height); - table.rows[i].querySelector('a').focus(); + focusRow(i); break; } } @@ -713,13 +731,20 @@ def file_head(): def file_folderup(path): """build folder up row""" if path == "./": - return "" - parentdir = os.path.dirname(path[1:].rstrip("/")).rstrip("/") + "/" - stat = os_stat("."+parentdir) + scan = os_scandir("./") + stat = os_stat("./") + folder = "." + classname = "rootfolder" + else: + folder = ".." + parentdir = os.path.dirname(path[1:].rstrip("/")).rstrip("/") + "/" + scan = os_scandir("."+parentdir) + stat = os_stat("."+parentdir) + classname = "upfolder" fields = [ - '..' % urllib.parse.quote(parentdir , errors='surrogatepass'), + f'{folder}', '', - '%s' % len(tuple(os_scandir("."+parentdir))), + '%s' % len(tuple(scan)), 'items', '%s' % get_username(stat.st_uid), '%s' % get_groupname(stat.st_gid), @@ -1032,15 +1057,15 @@ def do_GET(self): htmldoc = HTML.format(title=title, charset=ENC) htmldoc += '\n' - href = ' ' + href = [' '] fpath = "/" for dir in path.rstrip("/").split("/")[1:]: fpath += dir + "/" - href += '/%s' % ( + href.append('/%s' % ( urllib.parse.quote(fpath, errors="surrogatepass"), html.escape(dir, quote=False), - ) - #htmldoc += '
\n' + )) + href.append('') header = [ '\n', '
\n' @@ -1053,7 +1078,7 @@ def do_GET(self): ' \n' ) header += [ - f' {href}' + f' {"\n".join(href)}' ' ', '
', '\n\n',