Skip to content

Commit

Permalink
Updated to v0.9.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RaSan147 committed Mar 3, 2024
1 parent 23337dd commit a8a7978
Show file tree
Hide file tree
Showing 13 changed files with 294 additions and 115 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
# Version 0.9.3
## Client-side Changes:
* Fixed zip downloader as a PWA
* Now empty folders are included in zip

## Server-side Changes:
* Support empty folders in zip
* Added zip as a PWA

## Fixes:
* Fixed zip downloader page
* Fixed unwanted URL-encoding in Top-nav
* Video player page now use innerHTML instead of innerText (error message was wrongly shown)

## TODO:
* add zip in dynamic island (maybe use session storage to store zip data)



# Version 0.9.2
## Client-side Changes:
* Added optional Account system.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.9.2
0.9.3
1 change: 0 additions & 1 deletion dev_src/_zipfly_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ def generator(self):


if os.path.isdir(path[self.filesystem]):
print(path[self.filesystem])
if os.listdir(path[self.filesystem]):
continue # not empty
print("empty")
Expand Down
2 changes: 1 addition & 1 deletion dev_src/pyroboxCore.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import atexit
import os

__version__ = "0.9.2"
__version__ = "0.9.3"
enc = "utf-8"
__all__ = [
"HTTPServer", "ThreadingHTTPServer", "BaseHTTPRequestHandler",
Expand Down
6 changes: 0 additions & 6 deletions dev_src/script_zip_page.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@


// const id = "${PY_ZIP_ID}";
// const filename = "${PY_ZIP_NAME}";



class Zip_Page {
constructor() {
this.type = "zip"
Expand Down
4 changes: 2 additions & 2 deletions run_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

os.system(f"pip uninstall pyrobox -y")
os.system(f"pip install ./dist/pyrobox-{version}.tar.gz")
# os.system("pyrobox 45454")
os.system("pyrobox 45454")

# post to pypi
os.system("twine upload dist/*")
# os.system("twine upload dist/*")
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = pyrobox
version = 0.9.2
version = 0.9.3
author = Rasan
author_email= [email protected]
description = Personal DropBox for Private Network
Expand Down
27 changes: 15 additions & 12 deletions src/_fs_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ def _get_tree_size(path, limit=None, must_read=False):

return total

def _get_tree_path_n_size(path, limit=-1, must_read=False, path_type="full"):
def _get_tree_path_n_size(path, limit=-1, must_read=False, path_type="full", add_dirs=False):
"""
returns a list of files[size, path] in a directory and its subdirectories.
[ [`path`, size], ... ]
Expand All @@ -212,18 +212,20 @@ def _get_tree_path_n_size(path, limit=-1, must_read=False, path_type="full"):
total = 0
start_path = path

for entry in walk_dir(path):
try:
size = entry.stat(follow_symlinks=False).st_size
except OSError:
continue
total += size
for entry in walk_dir(path, yield_dir=add_dirs):
size = 0
if not entry.is_dir():
try:
size = entry.stat(follow_symlinks=False).st_size
except OSError:
continue
total += size

if limit>0 and total>limit:
raise LimitExceed
if limit>0 and total>limit:
raise LimitExceed

if must_read and not check_access(entry.path):
continue
if must_read and not check_access(entry.path):
continue


if path_type == "full":
Expand Down Expand Up @@ -376,7 +378,8 @@ def dir_navigator(path):

for i in range(1, len(dirs)-1):
dir = dirs[i]
urls.append(urls[i-1] + urllib.parse.quote(dir, errors='surrogatepass' )+ '/' if not dir.endswith('/') else "")
# urls.append(urls[i-1] + urllib.parse.quote(dir, errors='surrogatepass' )+ '/' if not dir.endswith('/') else "")
urls.append(urls[i-1] + dir+ '/' if not dir.endswith('/') else "")
names.append(dir)

for i in range(len(names)):
Expand Down
186 changes: 130 additions & 56 deletions src/_page_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ def admin_page_script():
def error_page_script():
return get_template("script_error_page.js")

def zip_page_script():
return get_template("script_zip_page.js")




Expand Down Expand Up @@ -268,6 +271,12 @@ def signup_page():
</div>
<div id="zip-page" class="page">
<h2>ZIPPING FOLDER</h2>
<h3 id="zip-prog">Progress</h3>
<h3 id="zip-perc"></h3>
</div>
<div id="admin_page" class="page">
<h1 style="text-align: center;">Admin Page</h1>
Expand Down Expand Up @@ -320,6 +329,8 @@ def signup_page():
<script src="/?video_page_script"></script>
<script src="/?admin_page_script"></script>
<script src="/?error_page_script"></script>
<script src="/?zip_page_script"></script>
<script src="/?page_handler_script"></script>
Expand All @@ -329,6 +340,7 @@ def signup_page():
<link rel="stylesheet" href="https://raw.githack.com/RaSan147/pyrobox/main/assets/video.css" />
"""


Expand Down Expand Up @@ -3910,7 +3922,7 @@ class Video_Page {
this.player_title.innerText = title
this.player_warning.innerText = warning
this.player_warning.innerHTML = warning
this.video_dl_url.href = video
page.set_title(title)
Expand Down Expand Up @@ -3950,7 +3962,7 @@ class Video_Page {
this.player_source.src = ""
this.player_source.type = ""
this.player_title.innerText = ""
this.player_warning.innerText = ""
this.player_warning.innerHTML = ""
this.video_dl_url.href = ""
}
Expand Down Expand Up @@ -4169,6 +4181,8 @@ class Page{
this.handler = video_page;
} else if (type == "admin") {
this.handler = admin_page;
} else if (type == "zip") {
this.handler = zip_page;
}
if (this.handler){
Expand Down Expand Up @@ -4232,7 +4246,8 @@ class Page{
for (let i = 1; i < dirs.length - 1; i++) {
const dir = dirs[i];
urls.push(urls[i - 1] + encodeURIComponent(dir).replace(/'/g, "%27").replace(/"/g, "%22") + (dir.endsWith('/') ? '' : '/'));
// urls.push(urls[i - 1] + encodeURIComponent(dir).replace(/'/g, "%27").replace(/"/g, "%22") + (dir.endsWith('/') ? '' : '/'));
urls.push(urls[i - 1] + dir + '/');
names.push(decodeURIComponent(dir));
}
Expand All @@ -4253,6 +4268,7 @@ class Page{
}
const page = new Page();
"""


Expand Down Expand Up @@ -4876,70 +4892,128 @@ class Error_Page {
"""


pt_config.file_list["html_zip_page.html"] = r"""
<h2>ZIPPING FOLDER</h2>
<h3 id="zip-prog">Progress</h3>
<h3 id="zip-perc"></h3>
pt_config.file_list["script_zip_page.js"] = r"""
<script>
class Zip_Page {
constructor() {
this.type = "zip"
this.my_part = document.getElementById("zip-page")
const id = "${PY_ZIP_ID}";
const filename = "${PY_ZIP_NAME}";
var dl_now = false
var check_prog = true
var message = document.getElementById("zip-prog")
var percentage = document.getElementById("zip-perc")
this.message = document.getElementById("zip-prog")
this.percentage = document.getElementById("zip-perc")
}
function ping(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (dl_now) {
return
}
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
//document.getElementById("demo").innerHTML = xhttp.responseText;
// json of the response
var resp = safeJSONParse(xhttp.response, ["status", "message"], 5000);
if (resp.status=="SUCCESS"){
check_prog = true;
} else if (resp.status=="DONE"){
message.innerHTML = "Downloading";
percentage.innerText = "";
dl_now = true;
clearTimeout(prog_timer)
run_dl()
} else if (resp.status=="ERROR"){
message.innerHTML = "Error";
percentage.innerText = resp.message;
clearTimeout(prog_timer)
} else if (resp.status=="PROGRESS"){
percentage.innerText = resp.message + "%";
} else {
percentage.innerText = resp.status + ": " + resp.message;
clearTimeout(prog_timer)
}
async initialize() {
page.hide_actions_button(); // Hide actions button, not needed here
this.dl_now = false
this.check_prog = true
this.prog_timer = null
var url = tools.add_query_here("zip_id")
var data = await fetch(url)
.then(data => {return data.json()})
.catch(err => {console.error(err)})
// {
// "status": status,
// "message": message,
// "zid": zid,
// "filename": filename
// }
var status = data.status
var message = data.message
this.zid = data.zid
this.filename = data.filename
const that = this
if (status) {
this.prog_timer = setInterval(function() {
that.ping(window.location.pathname + "?zip&zid=" + that.zid + "&progress")}, 500)
} else {
this.message.innerHTML = "Error";
this.percentage.innerText = message;
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
function run_dl() {
tools.download(window.location.pathname + "?zip&zid=" + id + "&download", filename, new_tab = true)
}
var prog_timer = setInterval(function() {
ping(window.location.pathname + "?zip&zid=" + id + "&progress")}, 500)
}
</script>
hide() {
this.my_part.classList.remove("active");
}
show() {
this.my_part.classList.add("active");
}
<p>pyroBox UI v4 - I ❤️ emoji!</p>
clear() {
this.message.innerHTML = ""
this.percentage.innerText = ""
this.dl_now = false
this.check_prog = true
this.zid = null
this.filename = null
if(this.prog_timer){
clearTimeout(this.prog_timer)
this.prog_timer = null
}
}
ping(url) {
const that = this
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (that.dl_now) {
return
}
if (this.readyState == 4 && this.status == 200) {
// Typical action to be performed when the document is ready:
//document.getElementById("demo").innerHTML = xhttp.responseText;
// json of the response
var resp = safeJSONParse(this.response, ["status", "message"], 5000);
// console.log(resp)
if (resp.status=="SUCCESS"){
that.check_prog = true;
} else if (resp.status=="DONE"){
that.message.innerHTML = "Downloading";
that.percentage.innerText = "";
that.dl_now = true;
clearTimeout(that.prog_timer)
that.run_dl()
} else if (resp.status=="ERROR"){
that.message.innerHTML = "Error";
that.percentage.innerText = resp.message;
clearTimeout(that.prog_timer)
} else if (resp.status=="PROGRESS"){
that.percentage.innerText = resp.message + "%";
} else {
that.percentage.innerText = resp.status + ": " + resp.message;
if(that.prog_timer){
clearTimeout(that.prog_timer)
that.prog_timer = null
}
}
}
};
xhttp.open("GET", url, true);
xhttp.send();
}
run_dl() {
tools.download(window.location.pathname + "?zip&zid=" + this.zid + "&download", this.filename, true)
}
}
var zip_page = new Zip_Page();
"""


Expand Down
Loading

0 comments on commit a8a7978

Please sign in to comment.