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
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
import markdown
|
import markdown
|
||||||
import shutil
|
import shutil
|
||||||
from pathlib import Path
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
db = sqlite3.connect('wastetape.db', check_same_thread=False)
|
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
|
maxFileSize = 1024 * 1024 * 128
|
||||||
maxExpiry = 60 * 60 * 24 * 7
|
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():
|
def removal():
|
||||||
cs.execute("SELECT * FROM files WHERE deletion < ?;", (int(time.time()),))
|
cs.execute("SELECT * FROM files WHERE deletion < ?;", (int(time.time()),))
|
||||||
@ -31,7 +30,7 @@ def removal():
|
|||||||
print(f"[{int(time.time())}]: DELETED #{id}")
|
print(f"[{int(time.time())}]: DELETED #{id}")
|
||||||
|
|
||||||
sched = BackgroundScheduler(daemon=True)
|
sched = BackgroundScheduler(daemon=True)
|
||||||
sched.add_job(removal,'interval',seconds=1)
|
sched.add_job(removal,'interval',seconds=5)
|
||||||
sched.start()
|
sched.start()
|
||||||
|
|
||||||
@app.template_filter('expirein')
|
@app.template_filter('expirein')
|
||||||
@ -50,20 +49,6 @@ def gettxt(value):
|
|||||||
with open(os.path.join('static/files', value), 'r') as f:
|
with open(os.path.join('static/files', value), 'r') as f:
|
||||||
return f.read()
|
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('/')
|
@app.route('/')
|
||||||
def index():
|
def index():
|
||||||
@ -102,7 +87,7 @@ def upload():
|
|||||||
os.remove(os.path.join('tmp', filename))
|
os.remove(os.path.join('tmp', filename))
|
||||||
flash('File too large')
|
flash('File too large')
|
||||||
return redirect(url_for('index'))
|
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))
|
os.remove(os.path.join('tmp', filename))
|
||||||
flash('File format not allowed')
|
flash('File format not allowed')
|
||||||
return redirect(url_for('index'))
|
return redirect(url_for('index'))
|
||||||
|
@ -27,7 +27,5 @@
|
|||||||
</select>
|
</select>
|
||||||
<button class="upload-button">Upload</button><br> max file size: 134mb (temporary), 32mb (forever)
|
<button class="upload-button">Upload</button><br> max file size: 134mb (temporary), 32mb (forever)
|
||||||
</form>
|
</form>
|
||||||
{% include 'stats.html' %}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
<p class="center">{{ ""|totalfiles }} files uploaded // {{ ""|totalfilesize }} occupied</p>
|
|
Loading…
Reference in New Issue
Block a user