Compare commits
No commits in common. "98231879cfccbbad37992cdcc9573a50b7e95d54" and "79982ecb589819592fa1a22ed0a2579934e04f23" have entirely different histories.
98231879cf
...
79982ecb58
21
app.py
21
app.py
@ -4,7 +4,6 @@ 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)
|
||||
@ -13,7 +12,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", "webp", "webm"]
|
||||
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"]
|
||||
|
||||
def removal():
|
||||
cs.execute("SELECT * FROM files WHERE deletion < ?;", (int(time.time()),))
|
||||
@ -31,7 +30,7 @@ def removal():
|
||||
print(f"[{int(time.time())}]: DELETED #{id}")
|
||||
|
||||
sched = BackgroundScheduler(daemon=True)
|
||||
sched.add_job(removal,'interval',seconds=1)
|
||||
sched.add_job(removal,'interval',seconds=5)
|
||||
sched.start()
|
||||
|
||||
@app.template_filter('expirein')
|
||||
@ -50,20 +49,6 @@ 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():
|
||||
@ -102,7 +87,7 @@ def upload():
|
||||
os.remove(os.path.join('tmp', filename))
|
||||
flash('File too large')
|
||||
return redirect(url_for('index'))
|
||||
if filename.lower().split('.')[-1] not in allowedFormats:
|
||||
if filename.split('.')[-1] not in allowedFormats:
|
||||
os.remove(os.path.join('tmp', filename))
|
||||
flash('File format not allowed')
|
||||
return redirect(url_for('index'))
|
||||
|
@ -27,7 +27,5 @@
|
||||
</select>
|
||||
<button class="upload-button">Upload</button><br> max file size: 134mb (temporary), 32mb (forever)
|
||||
</form>
|
||||
{% include 'stats.html' %}
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
|
@ -1 +0,0 @@
|
||||
<p class="center">{{ ""|totalfiles }} files uploaded // {{ ""|totalfilesize }} occupied</p>
|
Loading…
Reference in New Issue
Block a user