<commit_before>'use strict'

const Express = require('express')
const useragent = require('useragent')
const redis = require('./redis.js')
const requestVerifier = require('./lib/request-verifier.js')
const router = Express.Router()
const serializer = require('../lib/serializer.js')
const config = require('config')
const Util = require('./lib/util.js')
// TODO: This returns a Promise; we may want to block requests until it resolves
serializer.init()

const UserAwsCredentialGenerator = require('./lib/user-aws-credential-generator')
const UserAwsS3PostAuthenticator = require('./lib/user-aws-s3-post-authenticator')

const BUCKET = config.awsS3Bucket
const REGION = config.awsRegion

router.param('userId', requestVerifier)

// Generate temporary AWS credentials allowing user to access their Sync data.
router.post('/:userId/credentials', (request, response) => {
  const credentialPromise = new UserAwsCredentialGenerator(request.userId, BUCKET).perform()
  const postAuthenticatorPromise = new Promise((resolve, reject) => {
    try {
      const s3PostParams = new UserAwsS3PostAuthenticator(request.userId, BUCKET).perform()
      resolve(s3PostParams)
    } catch (exception) {
      reject(exception)
    }
  })

  const date = new Date().toISOString().split('T')[0]
  const agent = useragent.lookup(request.headers['user-agent'])
  const platform = agent.toString()
  const key = ['sync', 'dau', date, platform].join('-')
  redis.pfadd(key, request.userId, function (err, reply) {
    if (err) {
      Util.logger.error('error recording DAU in redis')
    }
  })

  Promise.all([credentialPromise, postAuthenticatorPromise])
    .then(([aws, s3Post]) => {
      const serialized = serializer.serializer.credentialsToByteArray({aws, s3Post, bucket: BUCKET, region: REGION})
      response.send(serialized)
    })
    .catch((error) => { response.status(401).send(error) })
})

router.get('/', (_request, response) => {
  response.send('☁️🎬✌️')
})

module.exports = router
<commit_msg>added family check to ua. formatted as browser version / os version<commit_after>'use strict'

const Express = require('express')
const useragent = require('useragent')
const redis = require('./redis.js')
const requestVerifier = require('./lib/request-verifier.js')
const router = Express.Router()
const serializer = require('../lib/serializer.js')
const config = require('config')
const Util = require('./lib/util.js')
// TODO: This returns a Promise; we may want to block requests until it resolves
serializer.init()

const UserAwsCredentialGenerator = require('./lib/user-aws-credential-generator')
const UserAwsS3PostAuthenticator = require('./lib/user-aws-s3-post-authenticator')

const BUCKET = config.awsS3Bucket
const REGION = config.awsRegion

router.param('userId', requestVerifier)

// Generate temporary AWS credentials allowing user to access their Sync data.
router.post('/:userId/credentials', (request, response) => {
  const credentialPromise = new UserAwsCredentialGenerator(request.userId, BUCKET).perform()
  const postAuthenticatorPromise = new Promise((resolve, reject) => {
    try {
      const s3PostParams = new UserAwsS3PostAuthenticator(request.userId, BUCKET).perform()
      resolve(s3PostParams)
    } catch (exception) {
      reject(exception)
    }
  })

  const date = new Date().toISOString().split('T')[0]
  const ua = useragent.lookup(request.headers['user-agent'])
  const platform = ua.family === 'Chrome' ? ua.toString() : 'Other'
  const key = ['sync', 'dau', date, platform].join('-')
  redis.pfadd(key, request.userId, function (err, reply) {
    if (err) {
      Util.logger.error('error recording DAU in redis')
    }
  })

  Promise.all([credentialPromise, postAuthenticatorPromise])
    .then(([aws, s3Post]) => {
      const serialized = serializer.serializer.credentialsToByteArray({aws, s3Post, bucket: BUCKET, region: REGION})
      response.send(serialized)
    })
    .catch((error) => { response.status(401).send(error) })
})

router.get('/', (_request, response) => {
  response.send('☁️🎬✌️')
})

module.exports = router

{'fraction_non_alphanumeric': 0.14738393515106854, 'fraction_numerical': 0.0058953574060427415, 'mean_word_length': 4.585733882030178, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '4069485', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1259, 'n_words': 289}