<commit_before>(function (settingsController) {
    var config = require('../config'),
        request = require('request'),
        bodyParser = require('body-parser'),
        JsonDB = require('node-json-db');

    var db = new JsonDB('instances', true, false);        

    var defaultSettings = {
        'CommitStream.Availability': 'unavailable',
        'CommitStream.Toggle': 'off',
        'CommitStream.AppUrl': 'http://v1commitstream-staging.azurewebsites.net/app.js'
    };

    settingsController.init = function (app) {

        app.get('/api/settings', function(req, res) {
            var instance = req.query.instance;
            if (!instance) {
                res.end(defaultSettings);
            }
            try {
                var settings = db.getData('/' + instance);
                res.end(JSON.stringify(settings));
            } catch (ex) {
                res.end(JSON.stringify(defaultSettings));
            }
        });
        
        app.post('/api/settings', bodyParser.json(), function(req, res) {
            var instance = req.query.instance;
            if (!instance) {
                res.end('No instance sent');<commit_msg>S-48201 Make JsonDB write human-readable JSON documents<commit_after>(function (settingsController) {
    var config = require('../config'),
        request = require('request'),
        bodyParser = require('body-parser'),
        JsonDB = require('node-json-db');

    var db = new JsonDB('instances', true, true);        

    var defaultSettings = {
        'CommitStream.Availability': 'unavailable',
        'CommitStream.Toggle': 'off',
        'CommitStream.AppUrl': 'http://v1commitstream-staging.azurewebsites.net/app.js'
    };

    settingsController.init = function (app) {

        app.get('/api/settings', function(req, res) {
            var instance = req.query.instance;
            if (!instance) {
                res.end(defaultSettings);
            }
            try {
                var settings = db.getData('/' + instance);
                res.end(JSON.stringify(settings));
            } catch (ex) {
                res.end(JSON.stringify(defaultSettings));
            }
        });
        
        app.post('/api/settings', bodyParser.json(), function(req, res) {
            var instance = req.query.instance;
            if (!instance) {
                res.end('No instance sent');
{'fraction_non_alphanumeric': 0.14052697616060225, 'fraction_numerical': 0.0029276453366792136, 'mean_word_length': 1.9064398541919805, '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': '5304493', 'n_tokens_mistral': 645, 'n_tokens_neox': 626, 'n_words': 121}