add reset button to admin: wipes pictures, previews, and db
This commit is contained in:
15
Slideshow.py
15
Slideshow.py
@@ -8,7 +8,7 @@ import uuid
|
||||
from flask import Flask, render_template, request, redirect, url_for, Response, send_from_directory
|
||||
from werkzeug.middleware.proxy_fix import ProxyFix
|
||||
|
||||
from db import init_db, search_images, get_image_count
|
||||
from db import init_db, search_images, get_image_count, reset_db
|
||||
|
||||
app = Flask(__name__, static_folder='Pictures', static_url_path='/pictures')
|
||||
app.wsgi_app = ProxyFix(app.wsgi_app, x_prefix=1)
|
||||
@@ -101,6 +101,19 @@ def admin():
|
||||
)
|
||||
|
||||
|
||||
@app.route('/admin/reset', methods=['POST'])
|
||||
def admin_reset():
|
||||
base_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
for folder in ('Pictures', 'Previews'):
|
||||
folder_path = os.path.join(base_dir, folder)
|
||||
for dirpath, _, filenames in os.walk(folder_path):
|
||||
for f in filenames:
|
||||
if f != '.gitkeep':
|
||||
os.remove(os.path.join(dirpath, f))
|
||||
reset_db()
|
||||
return redirect(url_for('admin'))
|
||||
|
||||
|
||||
@app.route('/download', methods=['POST'])
|
||||
def download():
|
||||
tags = request.form.get('tags', '').strip()
|
||||
|
||||
5
db.py
5
db.py
@@ -60,6 +60,11 @@ def insert_image(post_id, site, filename, tags, file_url, post_url, preview_file
|
||||
)
|
||||
|
||||
|
||||
def reset_db():
|
||||
with get_conn() as c:
|
||||
c.execute('DELETE FROM images')
|
||||
|
||||
|
||||
def get_image_count():
|
||||
with get_conn() as c:
|
||||
return c.execute('SELECT COUNT(*) FROM images').fetchone()[0]
|
||||
|
||||
@@ -60,6 +60,33 @@
|
||||
text-transform: uppercase;
|
||||
}
|
||||
a.back:hover { color: #999; }
|
||||
.danger-zone {
|
||||
margin-top: 40px;
|
||||
width: 100%;
|
||||
max-width: 420px;
|
||||
border-top: 1px solid #2a2a2a;
|
||||
padding-top: 32px;
|
||||
}
|
||||
.danger-label {
|
||||
font-size: 0.75rem;
|
||||
color: #555;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.1em;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
.btn-reset {
|
||||
width: 100%;
|
||||
padding: 14px;
|
||||
background: #2a1010;
|
||||
color: #c55;
|
||||
border: 1px solid #4a2020;
|
||||
border-radius: 8px;
|
||||
font-size: 0.9rem;
|
||||
letter-spacing: 0.06em;
|
||||
text-transform: uppercase;
|
||||
cursor: pointer;
|
||||
}
|
||||
.btn-reset:hover { background: #3a1515; border-color: #c55; color: #e77; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@@ -78,6 +105,12 @@
|
||||
<span class="stat-value">{{ previews_size }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="danger-zone">
|
||||
<div class="danger-label">danger zone</div>
|
||||
<form method="post" action="/admin/reset" onsubmit="return confirm('delete ALL pictures, previews and db records? this cannot be undone.')">
|
||||
<button type="submit" class="btn-reset">reset everything</button>
|
||||
</form>
|
||||
</div>
|
||||
<a class="back" href="/">← back to slideshow</a>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user