add delete option to upload form

This commit is contained in:
iou1name 2018-05-21 14:27:51 -04:00
parent 62c444f703
commit a760b40718
3 changed files with 25 additions and 7 deletions

View File

@ -3,6 +3,7 @@
Simple file host using Flask. Simple file host using Flask.
""" """
import os import os
import time
import string import string
import secrets import secrets
import sqlite3 import sqlite3
@ -49,6 +50,14 @@ class ReverseProxied(object):
return self.app(environ, start_response) return self.app(environ, start_response)
class CronThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
db_execute("SELECT filename, delete_date FROM uploads WHERE delete_date")
app = Flask(__name__) app = Flask(__name__)
app.wsgi_app = ReverseProxied(app.wsgi_app) app.wsgi_app = ReverseProxied(app.wsgi_app)
app.config['MAX_CONTENT_LENGTH'] = 128 * 1024 * 1024 app.config['MAX_CONTENT_LENGTH'] = 128 * 1024 * 1024
@ -98,8 +107,11 @@ def init():
"admin BOOL DEFAULT FALSE)") "admin BOOL DEFAULT FALSE)")
db_execute("CREATE TABLE uploads(" db_execute("CREATE TABLE uploads("
"filename TEXT, uploaded_by TEXT," "filename TEXT,"
"uploaded_date INT DEFAULT (STRFTIME('%s', 'now')))") "uploaded_by TEXT,"
"uploaded_date INTEGER DEFAULT (STRFTIME('%s', 'now')),"
"delete_date INTEGER)")
def add_user(username, password, admin="FALSE"): def add_user(username, password, admin="FALSE"):
@ -283,7 +295,7 @@ def manage_uploads():
new_uploads.append((file, date)) new_uploads.append((file, date))
return render_template("manage_uploads.html", uploads=new_uploads, return render_template("manage_uploads.html", uploads=new_uploads,
upload_dir=app.config.get("UPLOAD_URL")) upload_url=app.config.get("UPLOAD_URL"))
deletes = [fname for fname,_ in request.form.items()] deletes = [fname for fname,_ in request.form.items()]
deletes.remove("submit") deletes.remove("submit")

View File

@ -11,9 +11,15 @@
<a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br /> <a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br />
<p>Select file to upload: <p>Select file to upload:
<p><input type="file" name="file" required/><br /> <p><input type="file" name="file" required/><br />
<input type="checkbox" name="randname"> Generate random filename. <input type="checkbox" name="randname"/> Generate random filename.
<p><input type="submit" value="Upload File" name="submit"/> <p><input type="checkbox" name="delete"/> Delete this file in <input type="number" value="1"/>
<select>
<option value="minute">Minute</option>
<option value="hour">Hour</option>
<option value="day">Day</option>
<option value="month">Month</option>
</select>
<p><input type="submit" value="Upload File" name="submit"/>
</form> </form>
</body> </body>
</html> </html>

View File

@ -13,7 +13,7 @@
</tr> </tr>
{% for file, date in uploads %} {% for file, date in uploads %}
<tr> <tr>
<td><a href="{{ upload_dir + file }}">{{ file }}</a></td> <td><a href="{{ upload_url + file }}">{{ file }}</a></td>
<td>{{ date }}</td> <td>{{ date }}</td>
<td><input type="checkbox" name="{{ file }}"/></td> <td><input type="checkbox" name="{{ file }}"/></td>
</tr> </tr>