diff --git a/app.py b/app.py
index 35c7940..7ce737b 100644
--- a/app.py
+++ b/app.py
@@ -4,6 +4,7 @@ import os, sys, time, hashlib
from apscheduler.schedulers.background import BackgroundScheduler
import markdown
import shutil
+from pathlib import Path
app = Flask(__name__)
db = sqlite3.connect('wastetape.db', check_same_thread=False)
@@ -12,7 +13,7 @@ app.secret_key = hashlib.md5(os.urandom(32)).hexdigest()
maxFileSize = 1024 * 1024 * 128
maxExpiry = 60 * 60 * 24 * 7
-allowedFormats = ["png", "jpg", "jpeg", "gif", "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "mp4", "mpg", "wmv", "mov", "avi", "swf", "zip", "tar.gz", "tar", "rar", "7z", "mp3", "txt", "py", "php", "htm", "html", "css", "js", "ts", "cr", "c", "cpp", "rs", "rst", "md"]
+allowedFormats = ["png", "jpg", "jpeg", "gif", "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "mp4", "mpg", "wmv", "mov", "avi", "swf", "zip", "tar.gz", "tar", "rar", "7z", "mp3", "txt", "py", "php", "htm", "html", "css", "js", "ts", "cr", "c", "cpp", "rs", "rst", "md", "webp", "webm"]
def removal():
cs.execute("SELECT * FROM files WHERE deletion < ?;", (int(time.time()),))
@@ -49,6 +50,20 @@ def gettxt(value):
with open(os.path.join('static/files', value), 'r') as f:
return f.read()
+@app.template_filter('totalfiles')
+def totalfiles(value):
+ files = os.listdir("static/files")
+ return len(files)
+
+@app.template_filter('totalfilesize')
+def totalfilesize(value):
+ size = sum(p.stat().st_size for p in Path("static/files").rglob('*'))
+ print(size)
+ for unit in ("B", "K", "M", "G", "T"):
+ if size < 1024:
+ return f"{size:.1f}{unit}"
+ size /= 1024
+
@app.route('/')
def index():
@@ -87,7 +102,7 @@ def upload():
os.remove(os.path.join('tmp', filename))
flash('File too large')
return redirect(url_for('index'))
- if filename.split('.')[-1] not in allowedFormats:
+ if filename.lower().split('.')[-1] not in allowedFormats:
os.remove(os.path.join('tmp', filename))
flash('File format not allowed')
return redirect(url_for('index'))
diff --git a/templates/index.html b/templates/index.html
index 6101a1b..0efa1fb 100644
--- a/templates/index.html
+++ b/templates/index.html
@@ -27,5 +27,7 @@
max file size: 134mb (temporary), 32mb (forever)
+ {% include 'stats.html' %}
+
{% endblock %}
diff --git a/templates/stats.html b/templates/stats.html
new file mode 100644
index 0000000..ab385cb
--- /dev/null
+++ b/templates/stats.html
@@ -0,0 +1 @@
+
{{ ""|totalfiles }} files uploaded // {{ ""|totalfilesize }} occupied
\ No newline at end of file