<commit_before>## The applications routes are loaded from inside of `app.coffee` after
## the app is configured.
##
## There's not a good reason to ever require this manually, require `./app` isntead

app = require './app'
Comic = require './comic'

## Application routes
app.get '/', (request, response) ->
  Comic.latest (err, comic) =>
    # TODO: Better error handling
    return response.status(404).send "I am literally on fire, and I can't find the latest" if err
    response.render 'strip', comic: comic

app.get '/feed.xml', (request, response) ->
  Comic.archive 'latest', 100, (err, archive) ->
    return response.status(500).send "Sorry, my programming broke building the feed" if err

    response.set 'Content-Type', 'application/rss+xml'
    return response.render 'feed',
      layout: null
      archive: archive.archive

app.get '/top/:page?', (request, response) ->
  failHome = -> return response.redirect('/')

  # If the page is bullshit, we go to one.
  page = parseInt(request.params.page || 1)
  page = 1 if isNaN(page)

  perPage = 10
  skipTotal = ((page - 1) * perPage)

  # We fetch one more than we ask for, so that we can know if we
  # have a potential next page
  Comic.top (perPage + 1), skipTotal, (err, comics) =>
    return response.status(400).send JSON.stringify err: err if err
    response.render 'top',
      top: comics[0...perPage]
      page: page
      nextPage: if (comics[perPage..].length > 0) then page + 1
      prevPage: if (page > 1) then page - 1

app.get '/archive/:start?', (request, response) ->
  Comic.archive request.params.start, 10, (err, archive) =>
    return response.redirect("/archive/") if err
    return response.render 'archive', archive

app.get '/random/', (request, response) ->
  Comic.random (err, comic) =>
    # If we fuck up, go back to /
    return response.redirect('/') if err
    return response.redirect("/at/#{comic.time}/")

app.get '/at/:stamp?', (request, response) ->
  failHome = ->
    return response.redirect('/')
  return failHome() if isNaN(stamp = parseInt(request.params.stamp))

  Comic.at stamp, (err, comic) ->
    return failHome() if err
    response.render 'strip', comic: comic

app.post "/vote/:stamp?", (req, res) ->
  fail = (why, status=400) ->
    res.status(status).send JSON.stringify error: why
  res.set 'Content-Type', 'application/json'
<commit_msg>My error. Not yours.<commit_after>## The applications routes are loaded from inside of `app.coffee` after
## the app is configured.
##
## There's not a good reason to ever require this manually, require `./app` isntead

app = require './app'
Comic = require './comic'

## Application routes
app.get '/', (request, response) ->
  Comic.latest (err, comic) =>
    # TODO: Better error handling
    return response.status(404).send "I am literally on fire, and I can't find the latest" if err
    response.render 'strip', comic: comic

app.get '/feed.xml', (request, response) ->
  Comic.archive 'latest', 100, (err, archive) ->
    return response.status(500).send "Sorry, my programming broke building the feed" if err

    response.set 'Content-Type', 'application/rss+xml'
    return response.render 'feed',
      layout: null
      archive: archive.archive

app.get '/top/:page?', (request, response) ->
  failHome = -> return response.redirect('/')

  # If the page is bullshit, we go to one.
  page = parseInt(request.params.page || 1)
  page = 1 if isNaN(page)

  perPage = 10
  skipTotal = ((page - 1) * perPage)

  # We fetch one more than we ask for, so that we can know if we
  # have a potential next page
  Comic.top (perPage + 1), skipTotal, (err, comics) =>
    return response.redirect("/") if err
    response.render 'top',
      top: comics[0...perPage]
      page: page
      nextPage: if (comics[perPage..].length > 0) then page + 1
      prevPage: if (page > 1) then page - 1

app.get '/archive/:start?', (request, response) ->
  Comic.archive request.params.start, 10, (err, archive) =>
    return response.redirect("/archive/") if err
    return response.render 'archive', archive

app.get '/random/', (request, response) ->
  Comic.random (err, comic) =>
    # If we fuck up, go back to /
    return response.redirect('/') if err
    return response.redirect("/at/#{comic.time}/")

app.get '/at/:stamp?', (request, response) ->
  failHome = ->
    return response.redirect('/')
  return failHome() if isNaN(stamp = parseInt(request.params.stamp))

  Comic.at stamp, (err, comic) ->
    return failHome() if err
    response.render 'strip', comic: comic

app.post "/vote/:stamp?", (req, res) ->
  fail = (why, status=400) ->
    res.status(status).send JSON.stringify error: why
  res.set 'Content-Type', 'application/json'

{'fraction_non_alphanumeric': 0.14819532908704883, 'fraction_numerical': 0.011252653927813163, 'mean_word_length': 3.290528233151184, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 2, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3466467', 'n_tokens_mistral': 1515, 'n_tokens_neox': 1460, 'n_words': 504}