|
@ -1,6 +1,8 @@ |
|
|
import strutils, options, sugar, sequtils, asyncdispatch, threadpool, db_sqlite, strformat |
|
|
import strutils, options, sugar, sequtils, asyncdispatch, threadpool, db_sqlite, strformat |
|
|
import twitter |
|
|
import twitter |
|
|
import xander |
|
|
import jester |
|
|
|
|
|
|
|
|
|
|
|
from htmlgen import nil |
|
|
|
|
|
|
|
|
# one thread just receives messages with thread ID / username |
|
|
# one thread just receives messages with thread ID / username |
|
|
# thread then passes messages to worker threads in round-robin fashion |
|
|
# thread then passes messages to worker threads in round-robin fashion |
|
@ -57,37 +59,61 @@ proc insertThread(thread : TwitterThread) = |
|
|
thread.author, |
|
|
thread.author, |
|
|
thread.tweets) |
|
|
thread.tweets) |
|
|
|
|
|
|
|
|
get "/thread/:author/status/:tweetID": |
|
|
router twitblog: |
|
|
let tweetID = data{"tweetID"}.getStr() |
|
|
get "/thread/@author/status/@tweetID": |
|
|
let author = data{"author"}.getStr() |
|
|
let tweetID = @"tweetID" |
|
|
|
|
|
let author = @"author" |
|
|
let thread = threadExists(tweetID, author) |
|
|
let thread = threadExists(tweetID, author) |
|
|
|
|
|
|
|
|
if thread.isSome: |
|
|
if thread.isSome: |
|
|
data["title"] = fmt"Thread by {author}" |
|
|
let title = fmt"Thread by {author}" |
|
|
data["tweets"] = thread.get.tweets.split("\n") |
|
|
let tweets = thread.get.tweets.split("\n") |
|
|
respond tmplt("thread", data) |
|
|
resp htmlgen.body( |
|
|
|
|
|
htmlgen.a(href=fmt"/author/{author}/threads", fmt"See all of {author}'s threads"), |
|
|
|
|
|
htmlgen.h4(title), |
|
|
|
|
|
htmlgen.ul(tweets.map((t) => htmlgen.p(htmlgen.li(t))).join("")) |
|
|
|
|
|
) |
|
|
else: |
|
|
else: |
|
|
chan.send(ThreadRequest(tweetID: tweetID, author: author)) |
|
|
chan.send(ThreadRequest(tweetID: tweetID, author: author)) |
|
|
data["title"] = "Check back later" |
|
|
resp htmlgen.h4("Check back later") |
|
|
respond tmplt("nonexistent", data) |
|
|
|
|
|
|
|
|
|
|
|
get "/": |
|
|
get "/": |
|
|
# lists all authors |
|
|
# lists all authors |
|
|
data["authors"] = allAuthors.toSeq |
|
|
let authors = allAuthors.toSeq |
|
|
data["title"] = "Authors" |
|
|
let title = "Authors" |
|
|
respond tmplt("authors", data) |
|
|
resp htmlgen.body( |
|
|
|
|
|
htmlgen.h4(title), |
|
|
|
|
|
htmlgen.ul( |
|
|
|
|
|
authors.map((author) => |
|
|
|
|
|
htmlgen.li( |
|
|
|
|
|
htmlgen.a(href=fmt"/author/{author}/threads", author) |
|
|
|
|
|
) |
|
|
|
|
|
).join("") |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
get "/author/:author/threads": |
|
|
get "/author/@author/threads": |
|
|
let author = data{"author"}.getStr() |
|
|
let author = @"author" |
|
|
data["author"] = author |
|
|
let title = fmt"Threads for {author}" |
|
|
data["title"] = fmt"Threads for {author}" |
|
|
let threads = toSeq(threadIDs(author)) |
|
|
data["threads"] = toSeq(threadIDs(author)) |
|
|
resp htmlgen.body( |
|
|
respond tmplt("threads", data) |
|
|
htmlgen.h4(title), |
|
|
|
|
|
htmlgen.ul( |
|
|
|
|
|
threads.map((thread) => |
|
|
|
|
|
htmlgen.li( |
|
|
|
|
|
htmlgen.a(href=fmt"/thread/{author}/status/{thread}", thread) |
|
|
|
|
|
) |
|
|
|
|
|
).join("") |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
proc startServer* = |
|
|
proc startServer* = |
|
|
createTweetTable() |
|
|
createTweetTable() |
|
|
defer: db.close() |
|
|
defer: db.close() |
|
|
runForever(8080) |
|
|
let port = 8080.Port |
|
|
|
|
|
let settings = newSettings(port=port) |
|
|
|
|
|
var jester = initJester(twitblog, settings=settings) |
|
|
|
|
|
jester.serve() |
|
|
|
|
|
|
|
|
proc handleRenders* = |
|
|
proc handleRenders* = |
|
|
while true: |
|
|
while true: |
|
|