expiration dates work
This commit is contained in:
parent
4e52414845
commit
793c3c8646
21
saddle.py
21
saddle.py
|
@ -5,6 +5,7 @@ A file hosting service similar to Pomf and Uguu but without the public nature.
|
|||
import os
|
||||
import string
|
||||
import random
|
||||
import datetime
|
||||
|
||||
from aiohttp import web
|
||||
import jinja2
|
||||
|
@ -27,13 +28,29 @@ async def index(request):
|
|||
if request.method == 'GET':
|
||||
return render_template("index.html", request, locals())
|
||||
data = await request.post()
|
||||
rand_name = bool(data.get('rand_name'))
|
||||
files = []
|
||||
for filefield in data.getall('files'):
|
||||
files.append(handle_filefield(filefield))
|
||||
files.append(handle_filefield(filefield, rand_name=rand_name))
|
||||
if data.get('delete_this'):
|
||||
delete_num = data.get('delete_num', '')
|
||||
delete_type = data.get('delete_type', '')
|
||||
|
||||
try:
|
||||
delete_num = int(delete_num)
|
||||
assert delete_num >= 1 and delete_num <= 59
|
||||
assert delete_type in ['minutes', 'hours', 'days', 'weeks']
|
||||
except (ValueError, AssertionError):
|
||||
return 'ur ghey' # TODO: return error
|
||||
delta = datetime.timedelta(**{delete_type: delete_num})
|
||||
expiration_date = datetime.datetime.now() + delta
|
||||
else:
|
||||
expiration_date = None
|
||||
|
||||
files_insert = []
|
||||
for file in files:
|
||||
t = (request.cookies.get('userid'), file[0], file[1], 'DEFAUlT')
|
||||
t = (int(request.cookies.get('userid')), file[0], file[1], expiration_date)
|
||||
files_insert.append(t)
|
||||
async with request.app['pool'] as conn:
|
||||
await conn.executemany(
|
||||
"INSERT INTO upload (user_id, id, filename, expiration_date) "
|
||||
|
|
|
@ -3,5 +3,5 @@ CREATE TABLE IF NOT EXISTS upload (
|
|||
id TEXT PRIMARY KEY,
|
||||
filename TEXT NOT NULL,
|
||||
upload_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
|
||||
expiration_date TIMESTAMP
|
||||
expiration_date TIMESTAMP WITH TIME ZONE DEFAULT NULL
|
||||
)
|
||||
|
|
|
@ -5,3 +5,12 @@ body {
|
|||
font-family: Helvetica,sans-serif;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
section {
|
||||
background-color: whitesmoke;
|
||||
padding: 5%;
|
||||
border-radius: 0.5em;
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.14),
|
||||
0 3px 1px -2px rgba(0, 0, 0, 0.2),
|
||||
0 1px 5px 0 rgba(0, 0, 0, 0.12);
|
||||
}
|
||||
|
|
|
@ -13,8 +13,20 @@
|
|||
<main>
|
||||
<section>
|
||||
<form method="POST" enctype="multipart/form-data">
|
||||
<input type="file" name="files" multiple>
|
||||
<input type="submit">
|
||||
<input type="file" name="files" multiple><br>
|
||||
<input type="checkbox" name="rand_name" id="rand_name" checked>
|
||||
<label for="rand_name">Generate random filename.</label><br>
|
||||
<input type="hidden" name="reponse_type" value="html">
|
||||
<input type="checkbox" name="delete_this" id="delete_this">
|
||||
<label for="delete_this">Delete this file in</label>
|
||||
<input type="number" name="delete_num" min="1" max="59" value="1">
|
||||
<select name="delete_type">
|
||||
<option value="minutes">Minute</option>
|
||||
<option value="hours">Hour</option>
|
||||
<option value="days" selected="selected">Day</option>
|
||||
<option value="weeks">Week</option>
|
||||
</select>
|
||||
<p><input type="submit" value="Submit">
|
||||
</form>
|
||||
</section>
|
||||
</main>
|
||||
|
|
Loading…
Reference in New Issue
Block a user