<commit_before>express = require("express")
Firebase = require('firebase')
table = new Firebase('https://thetable.firebaseio.com/')

mytoken = require("./private-token")

FirebaseTokenGenerator = require("firebase-token-generator")
tokenGenerator = new FirebaseTokenGenerator(mytoken)
token = tokenGenerator.createToken({name: "table-api"}, {admin: true})

table.auth(token, (error) ->
  if(error)
    console.log("failed to auth", error)
   else
    console.log("authed.")
)

app = express()
app.get "/match", (req, res) ->
  current = table.child('current_games')
  current.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    home = game[id].home_score
    away = game[id].away_score
    res.send [
      home: home
      away: away
    ]
  )
  return
app.get "/match/away", (req, res) ->
  away = table.child('current_games')
  away.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    away = game[id].away
    awayName = table.child('people/' + away)
    awayName.once('value', (nameSnapshot) ->
      person = nameSnapshot.val()
      res.send [
        name: person.name
      ]
    )
  )
  return
app.get "/match/away/add", (req, res) ->
  awayAdd = table.child('current_games')
  awayAdd.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].away_score
    score = score + 1
    game[id].away_score = score
    awayAdd.child(id).set(game[id], =>
      res.send [
        away_score: score
      ]
    )
  )
  return

app.get "/match/home", (req, res) ->
  home = table.child('current_games')
  home.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    home = game[id].home
    homeName = table.child('people/' + home)
    homeName.once('value', (nameSnapshot) ->
      person = nameSnapshot.val()
      res.send [
        name: person.name
      ]
    )
  )
  return

app.get "/match/home/add", (req, res) ->
  add = table.child('current_games')
  add.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].home_score
    score = score + 1
    game[id].home_score = score
    add.child(id).set(game[id], =>
      res.send [
        home_score: score
      ]
    )
  )
  return

app.get "/match/home/sub", (req, res) ->
  add = table.child('current_games')
  add.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].home_score
    score = score - 1<commit_msg>feat: adding auth as query param<commit_after>express = require("express")
Firebase = require('firebase')
table = new Firebase('https://thetable.firebaseio.com/')

auth = (req) ->
  mytoken = req.params.token
  if mytoken == "" or mytoken is null or mytoken is undefined
   return false
  FirebaseTokenGenerator = require("firebase-token-generator")
  tokenGenerator = new FirebaseTokenGenerator(mytoken)
  token = tokenGenerator.createToken({name: "table-api"})
  table.auth(token, (error) ->
    if(error)
      console.log("failed to auth", error)
    else
      console.log("authed.")
  )

app = express()
app.get "/:token/match", (req, res) ->
  auth req
  current = table.child('current_games')
  current.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    home = game[id].home_score
    away = game[id].away_score
    res.send [
      home: home
      away: away
    ]
  )
  return
app.get "/:token/match/away", (req, res) ->
  auth req
  away = table.child('current_games')
  away.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    away = game[id].away
    awayName = table.child('people/' + away)
    awayName.once('value', (nameSnapshot) ->
      person = nameSnapshot.val()
      res.send [
        name: person.name
      ]
    )
  )
  return
app.get "/:token/match/away/add", (req, res) ->
  auth req
  awayAdd = table.child('current_games')
  awayAdd.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].away_score
    score = score + 1
    game[id].away_score = score
    awayAdd.child(id).set(game[id], =>
      res.send [
        away_score: score
      ]
    )
  )
  return
app.get "/:token/match/away/sub", (req, res) ->
  auth req
  add = table.child('current_games')
  add.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].away_score
    score = score - 1
    if score < 0
      res.send [
        error: "You can't go negative."
      ]
      return
    game[id].away_score = score
    add.child(id).set(game[id], =>
      res.send [
        away_score: score
      ]
    )
  )
  return
app.get "/:token/match/home", (req, res) ->
  auth req
  home = table.child('current_games')
  home.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    home = game[id].home
    homeName = table.child('people/' + home)
    homeName.once('value', (nameSnapshot) ->
      person = nameSnapshot.val()
      res.send [
        name: person.name
      ]
    )
  )
  return

app.get "/:token/match/home/add", (req, res) ->
  auth req
  add = table.child('current_games')
  add.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].home_score
    score = score + 1
    game[id].home_score = score
    add.child(id).set(game[id], =>
      res.send [
        home_score: score
      ]
    )
  )
  return

app.get "/:token/match/home/sub", (req, res) ->
  auth req
  add = table.child('current_games')
  add.once('value', (nameSnapshot) ->
    game = nameSnapshot.val()
    id = Object.keys(game)[0]
    score = game[id].home_score
    score = score - 1
{'fraction_non_alphanumeric': 0.16386986301369863, 'fraction_numerical': 0.003595890410958904, 'mean_word_length': 2.7322683706070285, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 41, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5854351', 'n_tokens_mistral': 2014, 'n_tokens_neox': 1994, 'n_words': 398}