added size info, new sort logic
This commit is contained in:
parent
978d4de212
commit
b30a8f4b44
@ -79,6 +79,11 @@
|
|||||||
max-height: 100% !important;
|
max-height: 100% !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.float-right {
|
||||||
|
float: right;
|
||||||
|
text-align: right;
|
||||||
|
font-size: initial;
|
||||||
|
}
|
||||||
|
|
||||||
/* Other message text colors */
|
/* Other message text colors */
|
||||||
.errorTxt { color: rgb(170, 18, 18); }
|
.errorTxt { color: rgb(170, 18, 18); }
|
||||||
|
16
src/core/static/js/react-ui-logic.js
vendored
16
src/core/static/js/react-ui-logic.js
vendored
@ -54,6 +54,7 @@ class FilesList extends React.Component {
|
|||||||
for (let file of files) {
|
for (let file of files) {
|
||||||
const name = file[0];
|
const name = file[0];
|
||||||
const hash = file[1];
|
const hash = file[1];
|
||||||
|
const fsize = file[2];
|
||||||
let extension = re.exec( name.toLowerCase() )[1] ? name : "file.dir";
|
let extension = re.exec( name.toLowerCase() )[1] ? name : "file.dir";
|
||||||
let data = setFileIconType(extension);
|
let data = setFileIconType(extension);
|
||||||
let icon = data[0];
|
let icon = data[0];
|
||||||
@ -63,13 +64,22 @@ class FilesList extends React.Component {
|
|||||||
|
|
||||||
if (filetype === "video") {
|
if (filetype === "video") {
|
||||||
card_header = name;
|
card_header = name;
|
||||||
card_body = <img class="card-img-top" src={"static/imgs/thumbnails/" + hash + ".jpg"} alt={name} />;
|
card_body = <React.Fragment>
|
||||||
|
<img class="card-img-top" src={"static/imgs/thumbnails/" + hash + ".jpg"} alt={name} />
|
||||||
|
<span class="float-right">{fsize}</span>
|
||||||
|
</React.Fragment>;
|
||||||
} else if (filetype === "image") {
|
} else if (filetype === "image") {
|
||||||
card_header = name;
|
card_header = name;
|
||||||
card_body = <img class="card-img-top" src={"api/file-manager-action/files/" + hash} alt={name} />;
|
card_body = <React.Fragment>
|
||||||
|
<img class="card-img-top" src={"api/file-manager-action/files/" + hash} alt={name} />
|
||||||
|
<span class="float-right">{fsize}</span>
|
||||||
|
</React.Fragment>;
|
||||||
} else {
|
} else {
|
||||||
card_header = <img class="icon-style" src={icon} alt={name} />;
|
card_header = <img class="icon-style" src={icon} alt={name} />;
|
||||||
card_body = name;
|
card_body = <React.Fragment>
|
||||||
|
{name}
|
||||||
|
<span>{fsize}</span>
|
||||||
|
</React.Fragment>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import hashlib
|
import hashlib, os, re
|
||||||
import os
|
|
||||||
from os import listdir
|
from os import listdir
|
||||||
from os.path import isdir, isfile, join
|
from os.path import isdir, isfile, join
|
||||||
|
|
||||||
@ -56,11 +55,11 @@ class View(Settings, Launcher, Path):
|
|||||||
else:
|
else:
|
||||||
self.dirs.append(f)
|
self.dirs.append(f)
|
||||||
|
|
||||||
self.dirs.sort()
|
self.dirs.sort(key=self._natural_keys)
|
||||||
self.vids.sort()
|
self.vids.sort(key=self._natural_keys)
|
||||||
self.images.sort()
|
self.images.sort(key=self._natural_keys)
|
||||||
self.desktop.sort()
|
self.desktop.sort(key=self._natural_keys)
|
||||||
self.ungrouped.sort()
|
self.ungrouped.sort(key=self._natural_keys)
|
||||||
|
|
||||||
self.files = self.dirs + self.vids + self.images + self.desktop + self.ungrouped
|
self.files = self.dirs + self.vids + self.images + self.desktop + self.ungrouped
|
||||||
|
|
||||||
@ -68,9 +67,12 @@ class View(Settings, Launcher, Path):
|
|||||||
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
return hashlib.sha256(str.encode(text)).hexdigest()[:18]
|
||||||
|
|
||||||
def hashSet(self, arry):
|
def hashSet(self, arry):
|
||||||
|
path = self.get_path()
|
||||||
data = []
|
data = []
|
||||||
for arr in arry:
|
for arr in arry:
|
||||||
data.append([arr, self.hashText(arr)])
|
file = f"{path}/{arr}"
|
||||||
|
size = "4K" if isdir(file) else self.sizeof_fmt(os.path.getsize(file))
|
||||||
|
data.append([arr, self.hashText(arr), size])
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def get_path_part_from_hash(self, hash):
|
def get_path_part_from_hash(self, hash):
|
||||||
@ -167,3 +169,31 @@ class View(Settings, Launcher, Path):
|
|||||||
|
|
||||||
def get_ungrouped(self):
|
def get_ungrouped(self):
|
||||||
return self.hashSet(self.ungrouped)
|
return self.hashSet(self.ungrouped)
|
||||||
|
|
||||||
|
def sizeof_fmt(self, num, suffix="B"):
|
||||||
|
for unit in ["", "K", "M", "G", "T", "Pi", "Ei", "Zi"]:
|
||||||
|
if abs(num) < 1024.0:
|
||||||
|
return f"{num:3.1f} {unit}{suffix}"
|
||||||
|
num /= 1024.0
|
||||||
|
return f"{num:.1f} Yi{suffix}"
|
||||||
|
|
||||||
|
def get_dir_size(self, sdir):
|
||||||
|
"""Get the size of a directory. Based on code found online."""
|
||||||
|
size = os.path.getsize(sdir)
|
||||||
|
|
||||||
|
for item in listdir(sdir):
|
||||||
|
item = join(sdir, item)
|
||||||
|
|
||||||
|
if isfile(item):
|
||||||
|
size = size + os.path.getsize(item)
|
||||||
|
elif isdir(item):
|
||||||
|
size = size + self.get_dir_size(item)
|
||||||
|
|
||||||
|
return size
|
||||||
|
|
||||||
|
|
||||||
|
def _atoi(self, text):
|
||||||
|
return int(text) if text.isdigit() else text
|
||||||
|
|
||||||
|
def _natural_keys(self, text):
|
||||||
|
return [ self._atoi(c) for c in re.split('(\d+)',text) ]
|
||||||
|
Loading…
Reference in New Issue
Block a user