expiration dates work

This commit is contained in:
iou1name 2019-10-02 19:47:27 -04:00
parent 4e52414845
commit 793c3c8646
4 changed files with 43 additions and 5 deletions

View File

@ -5,6 +5,7 @@ A file hosting service similar to Pomf and Uguu but without the public nature.
import os import os
import string import string
import random import random
import datetime
from aiohttp import web from aiohttp import web
import jinja2 import jinja2
@ -27,13 +28,29 @@ async def index(request):
if request.method == 'GET': if request.method == 'GET':
return render_template("index.html", request, locals()) return render_template("index.html", request, locals())
data = await request.post() data = await request.post()
rand_name = bool(data.get('rand_name'))
files = [] files = []
for filefield in data.getall('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 = [] files_insert = []
for file in files: 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: async with request.app['pool'] as conn:
await conn.executemany( await conn.executemany(
"INSERT INTO upload (user_id, id, filename, expiration_date) " "INSERT INTO upload (user_id, id, filename, expiration_date) "

View File

@ -3,5 +3,5 @@ CREATE TABLE IF NOT EXISTS upload (
id TEXT PRIMARY KEY, id TEXT PRIMARY KEY,
filename TEXT NOT NULL, filename TEXT NOT NULL,
upload_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(), upload_date TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
expiration_date TIMESTAMP expiration_date TIMESTAMP WITH TIME ZONE DEFAULT NULL
) )

View File

@ -5,3 +5,12 @@ body {
font-family: Helvetica,sans-serif; font-family: Helvetica,sans-serif;
font-size: 14px; 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);
}

View File

@ -13,8 +13,20 @@
<main> <main>
<section> <section>
<form method="POST" enctype="multipart/form-data"> <form method="POST" enctype="multipart/form-data">
<input type="file" name="files" multiple> <input type="file" name="files" multiple><br>
<input type="submit"> <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> </form>
</section> </section>
</main> </main>