Compare commits
2 Commits
168272761a
...
ba9ea87aaa
Author | SHA1 | Date | |
---|---|---|---|
ba9ea87aaa | |||
eb3679a005 |
14
saddle.py
14
saddle.py
|
@ -31,6 +31,7 @@ async def index(request):
|
||||||
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'))
|
rand_name = bool(data.get('rand_name'))
|
||||||
|
response_type = data.get('reponse_type')
|
||||||
|
|
||||||
files = []
|
files = []
|
||||||
for filefield in data.getall('files'):
|
for filefield in data.getall('files'):
|
||||||
|
@ -59,13 +60,20 @@ async def index(request):
|
||||||
for file in files:
|
for file in files:
|
||||||
t = (int(request.cookies.get('userid')), file[0], file[1], expiration_date)
|
t = (int(request.cookies.get('userid')), file[0], file[1], expiration_date)
|
||||||
files_insert.append(t)
|
files_insert.append(t)
|
||||||
async with request.app['pool'] as conn:
|
|
||||||
|
async with request.app['pool'].acquire() 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) "
|
||||||
"VALUES ($1, $2, $3, $4)",
|
"VALUES ($1, $2, $3, $4)",
|
||||||
files_insert)
|
files_insert)
|
||||||
|
|
||||||
urls = [config.upload_url + f[1] for f in files]
|
urls = [config.upload_url + f[1] for f in files]
|
||||||
return render_template("result.html", request, locals())
|
if response_type == 'html':
|
||||||
|
return render_template("result.html", request, locals())
|
||||||
|
elif response_type == 'plain':
|
||||||
|
return web.Response(body='\n'.join(urls))
|
||||||
|
elif response_type == 'json':
|
||||||
|
return web.json_response(urls)
|
||||||
|
|
||||||
|
|
||||||
@routes.get('/gallery/{user_id}', name='gallery')
|
@routes.get('/gallery/{user_id}', name='gallery')
|
||||||
|
@ -76,7 +84,7 @@ async def gallery(request):
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise web.HTTPNotFound
|
raise web.HTTPNotFound
|
||||||
|
|
||||||
async with request.app['pool'] as conn:
|
async with request.app['pool'].acquire() as conn:
|
||||||
uploads = await conn.fetch(
|
uploads = await conn.fetch(
|
||||||
"SELECT * FROM upload WHERE user_id = $1",
|
"SELECT * FROM upload WHERE user_id = $1",
|
||||||
user_id)
|
user_id)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1>Saddle</h1>
|
{% include 'header.html' %}
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
|
|
5
templates/header.html
Normal file
5
templates/header.html
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<div id="logo_line">
|
||||||
|
<object id="logo" title="Saddle Logo" data="/static/saddle.svg"></object>
|
||||||
|
<h1>Saddle</h1>
|
||||||
|
</div>
|
||||||
|
<nav><span><a href="./gallery/{{ request.cookies.get('userid') }}">Gallery</a></span></nav>
|
|
@ -8,11 +8,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<div id="logo_line">
|
{% include 'header.html' %}
|
||||||
<object id="logo" title="Saddle Logo" data="/static/saddle.svg"></object>
|
|
||||||
<h1>Saddle</h1>
|
|
||||||
</div>
|
|
||||||
<nav><span><a href="./gallery/{{ request.cookies.get('userid') }}">Gallery</a></span></nav>
|
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<h1>Saddle</h1>
|
{% include 'header.html' %}
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<section>
|
<section>
|
||||||
|
|
Loading…
Reference in New Issue
Block a user