add delete option to upload form
This commit is contained in:
parent
62c444f703
commit
a760b40718
18
fileHost.py
18
fileHost.py
|
@ -3,6 +3,7 @@
|
|||
Simple file host using Flask.
|
||||
"""
|
||||
import os
|
||||
import time
|
||||
import string
|
||||
import secrets
|
||||
import sqlite3
|
||||
|
@ -49,6 +50,14 @@ class ReverseProxied(object):
|
|||
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.wsgi_app = ReverseProxied(app.wsgi_app)
|
||||
app.config['MAX_CONTENT_LENGTH'] = 128 * 1024 * 1024
|
||||
|
@ -98,8 +107,11 @@ def init():
|
|||
"admin BOOL DEFAULT FALSE)")
|
||||
|
||||
db_execute("CREATE TABLE uploads("
|
||||
"filename TEXT, uploaded_by TEXT,"
|
||||
"uploaded_date INT DEFAULT (STRFTIME('%s', 'now')))")
|
||||
"filename TEXT,"
|
||||
"uploaded_by TEXT,"
|
||||
"uploaded_date INTEGER DEFAULT (STRFTIME('%s', 'now')),"
|
||||
"delete_date INTEGER)")
|
||||
|
||||
|
||||
|
||||
def add_user(username, password, admin="FALSE"):
|
||||
|
@ -283,7 +295,7 @@ def manage_uploads():
|
|||
new_uploads.append((file, date))
|
||||
|
||||
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.remove("submit")
|
||||
|
|
|
@ -11,9 +11,15 @@
|
|||
<a href="{{ url_for('manage_uploads') }}">Manage Uploads</a><br />
|
||||
<p>Select file to upload:
|
||||
<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="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>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</tr>
|
||||
{% for file, date in uploads %}
|
||||
<tr>
|
||||
<td><a href="{{ upload_dir + file }}">{{ file }}</a></td>
|
||||
<td><a href="{{ upload_url + file }}">{{ file }}</a></td>
|
||||
<td>{{ date }}</td>
|
||||
<td><input type="checkbox" name="{{ file }}"/></td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue
Block a user