Compare commits

..

2 Commits

Author SHA1 Message Date
ec4a034581 expiration dates work 2019-11-06 13:09:07 -05:00
a8c4ddd787 switching tabs clears previous tab input 2019-11-06 13:08:55 -05:00
2 changed files with 39 additions and 0 deletions

View File

@ -6,6 +6,7 @@ import os
import time import time
import string import string
import random import random
import asyncio
import datetime import datetime
from aiohttp import web from aiohttp import web
@ -180,11 +181,46 @@ def download_file(url, timeout=10, max_file_size=config.client_max_size):
return (fname, temp) return (fname, temp)
async def cleaner(app):
"""Removes files marked for deletion."""
async with app['pool'].acquire() as conn:
expired = await conn.fetch(
"SELECT * FROM upload WHERE expiration_date < NOW()")
if not expired:
return
for record in expired:
os.remove(os.path.join(config.upload_dir, record['filename']))
await conn.executemany(
"DELETE FROM upload WHERE id = $1",
[(record['id'],) for record in expired])
async def cleaner_loop(app):
"""Loops cleaner() continuously until shutdown."""
try:
while True:
await cleaner(app)
await asyncio.sleep(60)
except asyncio.CancelledError:
return
async def start_background_tasks(app):
app['cleaner'] = asyncio.create_task(cleaner_loop(app))
async def cleanup_background_tasks(app):
app['cleaner'].cancel()
await app['cleaner']
async def init_app(): async def init_app():
"""Initializes the application.""" """Initializes the application."""
app = web.Application(middlewares=[buckler_aiohttp.buckler_session]) app = web.Application(middlewares=[buckler_aiohttp.buckler_session])
aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('templates')) aiohttp_jinja2.setup(app, loader=jinja2.FileSystemLoader('templates'))
app['pool'] = await asyncpg.create_pool(**config.db) app['pool'] = await asyncpg.create_pool(**config.db)
app.on_startup.append(start_background_tasks)
app.on_cleanup.append(cleanup_background_tasks)
async with app['pool'].acquire() as conn: async with app['pool'].acquire() as conn:
with open('saddle.sql', 'r') as file: with open('saddle.sql', 'r') as file:

View File

@ -5,6 +5,9 @@ function switchFileTab(span, window_id) {
let old_window = document.querySelector('.tabWindowSelected'); let old_window = document.querySelector('.tabWindowSelected');
old_window.classList.remove('tabWindowSelected'); old_window.classList.remove('tabWindowSelected');
for (let input of old_window.querySelectorAll('input')) {
input.value = '';
}
let tab_window = document.querySelector('#' + window_id); let tab_window = document.querySelector('#' + window_id);
tab_window.classList.add('tabWindowSelected'); tab_window.classList.add('tabWindowSelected');
} }