status.nim 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import asyncdispatch, strutils, sequtils, uri, options
  2. import jester, karax/vdom
  3. import router_utils
  4. import ".."/[types, formatters, api]
  5. import ../views/[general, status]
  6. export uri, sequtils, options
  7. export router_utils
  8. export api, formatters
  9. export status
  10. proc createStatusRouter*(cfg: Config) =
  11. router status:
  12. get "/@name/status/@id/?":
  13. cond '.' notin @"name"
  14. let prefs = cookiePrefs()
  15. if @"scroll".len > 0:
  16. let replies = await getReplies(@"id", getCursor())
  17. if replies.content.len == 0:
  18. resp Http404, ""
  19. resp $renderReplies(replies, prefs, getPath())
  20. let conv = await getTweet(@"id", getCursor())
  21. if conv == nil:
  22. echo "nil conv"
  23. if conv == nil or conv.tweet == nil or conv.tweet.id == 0:
  24. var error = "Tweet not found"
  25. if conv != nil and conv.tweet != nil and conv.tweet.tombstone.len > 0:
  26. error = conv.tweet.tombstone
  27. resp Http404, showError(error, cfg)
  28. var
  29. title = pageTitle(conv.tweet)
  30. ogTitle = pageTitle(conv.tweet.profile)
  31. desc = conv.tweet.text
  32. images = conv.tweet.photos
  33. video = ""
  34. if conv.tweet.video.isSome():
  35. images = @[get(conv.tweet.video).thumb]
  36. video = getVideoEmbed(cfg, conv.tweet.id)
  37. elif conv.tweet.gif.isSome():
  38. images = @[get(conv.tweet.gif).thumb]
  39. video = getPicUrl(get(conv.tweet.gif).url)
  40. elif conv.tweet.card.isSome():
  41. let card = conv.tweet.card.get()
  42. if card.image.len > 0:
  43. images = @[card.image]
  44. elif card.video.isSome():
  45. images = @[card.video.get().thumb]
  46. let html = renderConversation(conv, prefs, getPath() & "#m")
  47. resp renderMain(html, request, cfg, prefs, title, desc, ogTitle,
  48. images=images, video=video)
  49. get "/@name/@s/@id/@m/?@i?":
  50. cond @"s" in ["status", "statuses"]
  51. cond @"m" in ["video", "photo"]
  52. redirect("/$1/status/$2" % [@"name", @"id"])
  53. get "/@name/statuses/@id/?":
  54. redirect("/$1/status/$2" % [@"name", @"id"])
  55. get "/i/web/status/@id":
  56. redirect("/i/status/" & @"id")