|
@ -1,4 +1,4 @@ |
|
|
import strutils, options, sugar, sequtils, asyncdispatch, threadpool, db_sqlite, json |
|
|
import strutils, options, sugar, sequtils, asyncdispatch, threadpool, db_sqlite, json, strformat, uri, strscans |
|
|
import twitter |
|
|
import twitter |
|
|
import templates |
|
|
import templates |
|
|
import jester |
|
|
import jester |
|
@ -12,6 +12,15 @@ type TwitterThread = ref object of RootObj |
|
|
author: string |
|
|
author: string |
|
|
tweets: string |
|
|
tweets: string |
|
|
|
|
|
|
|
|
|
|
|
proc parseTweetUrl(url : string) : Option[ThreadRequest] = |
|
|
|
|
|
let path = url.parseUri.path |
|
|
|
|
|
var author : string |
|
|
|
|
|
var tweetID : int |
|
|
|
|
|
if scanf(path, "/$w/status/$i", author, tweetID): |
|
|
|
|
|
some(ThreadRequest(tweetID : $tweetID, author: author)) |
|
|
|
|
|
else: |
|
|
|
|
|
none(ThreadRequest) |
|
|
|
|
|
|
|
|
var chan : Channel[ThreadRequest] |
|
|
var chan : Channel[ThreadRequest] |
|
|
|
|
|
|
|
|
# Max 20 items processing |
|
|
# Max 20 items processing |
|
@ -60,17 +69,16 @@ router twitblog: |
|
|
resp authors.mainPage |
|
|
resp authors.mainPage |
|
|
|
|
|
|
|
|
post "/thread": |
|
|
post "/thread": |
|
|
let params = request.formData |
|
|
let params = request.params |
|
|
if not ("tweetID" in params and "author" in params): |
|
|
if not ("tweetURL" in params): |
|
|
resp "nope" |
|
|
resp "Invalid" |
|
|
|
|
|
|
|
|
let tweetID = params["tweetID"].body |
|
|
let threadURL = params["tweetURL"].parseTweetUrl |
|
|
let author = params["author"].body |
|
|
|
|
|
|
|
|
|
|
|
let thread = threadExists(tweetID, author) |
|
|
|
|
|
|
|
|
|
|
|
chan.send(ThreadRequest(tweetID: tweetID, author: author)) |
|
|
if threadURL.isSome: |
|
|
resp checkBack() |
|
|
redirect (fmt"/thread/{threadURL.get.author}/status/{threadURL.get.tweetID}") |
|
|
|
|
|
else: |
|
|
|
|
|
resp "Invalid" |
|
|
|
|
|
|
|
|
get "/thread/@author/status/@tweetID": |
|
|
get "/thread/@author/status/@tweetID": |
|
|
let tweetID = @"tweetID" |
|
|
let tweetID = @"tweetID" |
|
|