Compare commits
No commits in common. "ec4a034581e6ec86eca60a27ae47c6c12a086b16" and "5afded89ce52560e712bcd3f5369116fed450d7d" have entirely different histories.
ec4a034581
...
5afded89ce
36
saddle.py
36
saddle.py
|
@ -6,7 +6,6 @@ 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
|
||||||
|
@ -181,46 +180,11 @@ 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:
|
||||||
|
|
|
@ -5,9 +5,6 @@ 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');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user