quote submission
This commit is contained in:
parent
427c7f5858
commit
38bb2c3ac0
|
@ -6,6 +6,7 @@ const
|
|||
browseTemplate*: string = staticRead "./templates/browse.mustache"
|
||||
errorTemplate*: string = staticRead "./templates/error.mustache"
|
||||
channelTemplate*: string = staticRead "./templates/channel.mustache"
|
||||
submitTemplate*: string = staticRead "./templates/submit.mustache"
|
||||
|
||||
testTemplate*: string = """<p>hi!</p>"""
|
||||
|
||||
|
@ -26,6 +27,18 @@ except:
|
|||
echo getCurrentExceptionMsg()
|
||||
raise
|
||||
|
||||
proc validItem(s: string, channel: bool = false) =
|
||||
if channel:
|
||||
if s.startsWith "#":
|
||||
echo "fuck"
|
||||
else:
|
||||
raise newException(ValueError, "invalid layout of channel name")
|
||||
else: discard
|
||||
|
||||
if s.contains " ":
|
||||
raise newException(ValueError, "invalid layout of quote")
|
||||
else: discard
|
||||
|
||||
template renderMustache*(title: string, templ: string, ctx: Context): expr =
|
||||
var
|
||||
layoutCtx = moustachu.newContext()
|
||||
|
@ -95,6 +108,31 @@ routes:
|
|||
except:
|
||||
fail()
|
||||
|
||||
get "/submit":
|
||||
renderMustache "submit", submitTemplate, newContext()
|
||||
|
||||
post "/submit":
|
||||
try:
|
||||
var
|
||||
channel = $(request.formData.mget "channel").body
|
||||
nick = $(request.formData.mget "nick").body
|
||||
adder = $(request.formData.mget "adder").body
|
||||
quote = $(request.formData.mget "quote").body
|
||||
|
||||
channel.validItem()
|
||||
nick.validItem()
|
||||
adder.validItem()
|
||||
|
||||
let
|
||||
now = $(getTime().toSeconds())
|
||||
data = now.split(".")[0].parseInt()
|
||||
|
||||
db.exec(sql"INSERT INTO quotes VALUES(null, ?, ?, ?, ?, ?, 0);", channel, nick, adder, quote, data)
|
||||
|
||||
redirect (channel.replace("#", "hashtag-") & "/0")
|
||||
except:
|
||||
fail()
|
||||
|
||||
get "/@kind/@id":
|
||||
var
|
||||
title: string = ""
|
||||
|
@ -127,6 +165,8 @@ routes:
|
|||
else:
|
||||
halt Http404, "not found"
|
||||
|
||||
echo request.headers.getOrDefault "X-Forwarded-For"
|
||||
|
||||
ctx = newContext()
|
||||
var quoteSeq = newSeq[Context]()
|
||||
|
||||
|
|
|
@ -1,3 +0,0 @@
|
|||
--opt:size
|
||||
--define:release
|
||||
--deadCodeElim:on
|
|
@ -7,7 +7,7 @@
|
|||
<div class=metanav>
|
||||
<a href="/">home</a>
|
||||
<a href="/channel">channel</a>
|
||||
<!-- <a href="/submit">submit</a> -->
|
||||
<a href="/submit">submit</a>
|
||||
</div>
|
||||
|
||||
<h2>{{ title }}</h2>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<form method="POST" action="/submit" enctype="multipart/form-data">
|
||||
<dl>
|
||||
<dt>channel</dt>
|
||||
<dd><input type="text" name="channel" /></dd>
|
||||
|
||||
<dt>nickname</dt>
|
||||
<dd><input type="text" name="nick" /></dd>
|
||||
|
||||
<dt>your nick</dd>
|
||||
<dd><input type="text" name="adder" /></dd>
|
||||
|
||||
<dt>quote</dt>
|
||||
<dd><input type="text" name="quote" /></dd>
|
||||
|
||||
<dd><input type=submit value="submit"></dd>
|
||||
</form>
|
Loading…
Reference in New Issue