From 793c3c8646debbcdff04211788fd87fb2206c959 Mon Sep 17 00:00:00 2001 From: iou1name Date: Wed, 2 Oct 2019 19:47:27 -0400 Subject: [PATCH] expiration dates work --- saddle.py | 21 +++++++++++++++++++-- saddle.sql | 2 +- static/saddle.css | 9 +++++++++ templates/index.html | 16 ++++++++++++++-- 4 files changed, 43 insertions(+), 5 deletions(-) diff --git a/saddle.py b/saddle.py index d418d42..ebaf99e 100644 --- a/saddle.py +++ b/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) " diff --git a/saddle.sql b/saddle.sql index 2e81596..88397f0 100644 --- a/saddle.sql +++ b/saddle.sql @@ -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 ) diff --git a/static/saddle.css b/static/saddle.css index 70e50c6..8aae01a 100644 --- a/static/saddle.css +++ b/static/saddle.css @@ -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); +} diff --git a/templates/index.html b/templates/index.html index 90f75e0..fe1e78a 100644 --- a/templates/index.html +++ b/templates/index.html @@ -13,8 +13,20 @@
- - +
+ +
+ + + + + +