Initial commit
This commit is contained in:
75
src/nitter.nim
Normal file
75
src/nitter.nim
Normal file
@ -0,0 +1,75 @@
|
||||
import asyncdispatch, httpclient, times, strutils, hashes, random, uri
|
||||
import jester, regex
|
||||
|
||||
import api, utils, types
|
||||
import views/[user, general, conversation]
|
||||
|
||||
proc showTimeline(name: string; num=""): Future[string] {.async.} =
|
||||
let
|
||||
username = name.strip(chars={'/'})
|
||||
profileFut = getProfile(username)
|
||||
tweetsFut = getTimeline(username, after=num)
|
||||
|
||||
let profile = await profileFut
|
||||
if profile.username == "":
|
||||
return ""
|
||||
|
||||
return renderMain(renderProfile(profile, await tweetsFut, num == ""))
|
||||
|
||||
routes:
|
||||
get "/":
|
||||
resp renderMain(renderSearchPanel())
|
||||
|
||||
post "/search":
|
||||
if @"query".len == 0:
|
||||
resp Http404, showError("Please enter a username.")
|
||||
|
||||
redirect("/" & @"query")
|
||||
|
||||
get "/@name/?":
|
||||
cond '.' notin @"name"
|
||||
let timeline = await showTimeline(@"name", @"after")
|
||||
if timeline == "":
|
||||
resp Http404, showError("User \"" & @"name" & "\" not found")
|
||||
|
||||
resp timeline
|
||||
|
||||
get "/@name/status/@id":
|
||||
cond '.' notin @"name"
|
||||
let conversation = await getTweet(@"id")
|
||||
if conversation.tweet.id == "":
|
||||
resp Http404, showError("Tweet not found")
|
||||
|
||||
resp renderMain(renderConversation(conversation))
|
||||
|
||||
get "/pic/@sig/@url":
|
||||
cond "http" in @"url"
|
||||
cond "twimg" in @"url"
|
||||
let url = decodeUrl(@"url")
|
||||
|
||||
if getHmac(url) != @"sig":
|
||||
resp showError("Failed to verify signature")
|
||||
|
||||
let
|
||||
client = newAsyncHttpClient()
|
||||
pic = await client.getContent(url)
|
||||
|
||||
defer: client.close()
|
||||
resp pic, mimetype(url)
|
||||
|
||||
get "/video/@sig/@url":
|
||||
cond "http" in @"url"
|
||||
cond "video.twimg" in @"url"
|
||||
let url = decodeUrl(@"url")
|
||||
|
||||
if getHmac(url) != @"sig":
|
||||
resp showError("Failed to verify signature")
|
||||
|
||||
let
|
||||
client = newAsyncHttpClient()
|
||||
pic = await client.getContent(url)
|
||||
|
||||
defer: client.close()
|
||||
resp pic, mimetype(url)
|
||||
|
||||
runForever()
|
Reference in New Issue
Block a user