<commit_before>import express = require('express');
const app: express.Router = express.Router();
import dropbox from '../dropbox';
import { UserService } from '../models';

// These two routes have to come before bodyParser to be able
// to read the raw body and confirm the request signature
app.get('/dropbox/webhook', function(req, res) {
  res.set({
    'Content-Type': 'text/plain',
    'X-Content-Type-Options': 'nosniff',
  });
  res.send(req.query.challenge || 'OK');
});

import {
  shouldSortUser,
  startQueueProcessor,
  onUserReadyForSort,
  disableSorting,
} from '../redis';
import crypto = require('crypto');

import { reportError } from '../raven';

async function processUser(userDbxId: string) {
  let user = await UserService.findByDropboxId(userDbxId);
  if (user) {
    let dbx = dropbox(user.dropboxV2Token);
    try {
      if (user.periodicSort) {
        await dbx.runRulesAndUpdateUserAndFileMoves(user, true);
      } else {
        // TODO debug message
        // console.error(`Not sorting user, periodic sort disabled: ${user.id}`);
        await disableSorting(userDbxId);
      }
    } catch (e) {
      if (dbx.isNotFoundError(e)) {
        console.log(`Sorting folder missing for user ${user.id}, disabling periodic sync`);
        await disableSorting(userDbxId);
        user.periodicSort = false;
        await UserService.save([user]);
      } else {
        throw e;
      }
    }
  } else {
    console.error(`Attempting to sort user that is not in our Database: ${userDbxId}`);
  }
}


app.post('/dropbox/webhook', function(req, res, next) {
  let chunks: Buffer[] = [];
  req.on('data', function(chunk) {
    chunks.push(chunk as Buffer);
  });
  req.on('end', reportError(async function() {
    const body = Buffer.concat(chunks).toString('utf8');
    let hmac = crypto.createHmac('sha256', process.env.DROPBOX_SECRET as string);<commit_msg>Disable sorting if User is not in DB<commit_after>import express = require('express');
const app: express.Router = express.Router();
import dropbox from '../dropbox';
import { UserService } from '../models';

// These two routes have to come before bodyParser to be able
// to read the raw body and confirm the request signature
app.get('/dropbox/webhook', function(req, res) {
  res.set({
    'Content-Type': 'text/plain',
    'X-Content-Type-Options': 'nosniff',
  });
  res.send(req.query.challenge || 'OK');
});

import {
  shouldSortUser,
  startQueueProcessor,
  onUserReadyForSort,
  disableSorting,
} from '../redis';
import crypto = require('crypto');

import { reportError } from '../raven';

async function processUser(userDbxId: string) {
  let user = await UserService.findByDropboxId(userDbxId);
  if (user) {
    let dbx = dropbox(user.dropboxV2Token);
    try {
      if (user.periodicSort) {
        await dbx.runRulesAndUpdateUserAndFileMoves(user, true);
      } else {
        // TODO debug message
        // console.error(`Not sorting user, periodic sort disabled: ${user.id}`);
        await disableSorting(userDbxId);
      }
    } catch (e) {
      if (dbx.isNotFoundError(e)) {
        console.log(`Sorting folder missing for user ${user.id}, disabling periodic sync`);
        await disableSorting(userDbxId);
        user.periodicSort = false;
        await UserService.save([user]);
      } else {
        throw e;
      }
    }
  } else {
    console.error(`Attempting to sort user that is not in our Database: ${userDbxId}`);
    await disableSorting(userDbxId);
  }
}


app.post('/dropbox/webhook', function(req, res, next) {
  let chunks: Buffer[] = [];
  req.on('data', function(chunk) {
    chunks.push(chunk as Buffer);
  });
  req.on('end', reportError(async function() {
    const body = Buffer.concat(chunks).toString('utf8');
    let hmac = crypto.createHmac('sha256', process.env.DROPBOX_SECRET as string);
{'fraction_non_alphanumeric': 0.1421491914449661, 'fraction_numerical': 0.0026082420448617634, 'mean_word_length': 3.3284424379232505, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1181489', 'n_tokens_mistral': 1209, 'n_tokens_neox': 1204, 'n_words': 308}