Upgrade to jsli 2.0

This commit is contained in:
Calvin Montgomery 2017-07-08 20:11:54 -07:00
parent 486ce04a3e
commit 07179d6c83
33 changed files with 42 additions and 76 deletions

View File

@ -8,7 +8,7 @@
}, },
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@calzoneman/jsli": "^1.0.1", "@calzoneman/jsli": "^2.0.1",
"bcrypt": "^0.8.5", "bcrypt": "^0.8.5",
"bluebird": "^2.10.1", "bluebird": "^2.10.1",
"body-parser": "^1.14.0", "body-parser": "^1.14.0",

View File

@ -8,9 +8,8 @@
var Config = require("./config"); var Config = require("./config");
var db = require("./database"); var db = require("./database");
var Promise = require("bluebird"); var Promise = require("bluebird");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('bgtask'); const LOGGER = require('@calzoneman/jsli')('bgtask');
var init = null; var init = null;

View File

@ -1,10 +1,9 @@
// @flow // @flow
import crypto from 'crypto'; import crypto from 'crypto';
import { LoggerFactory } from '@calzoneman/jsli';
import * as urlparse from 'url'; import * as urlparse from 'url';
import { CamoConfig } from './configuration/camoconfig'; import { CamoConfig } from './configuration/camoconfig';
const LOGGER = LoggerFactory.getLogger('camo'); const LOGGER = require('@calzoneman/jsli')('camo');
function isWhitelisted(camoConfig: CamoConfig, url: string): boolean { function isWhitelisted(camoConfig: CamoConfig, url: string): boolean {
const whitelistedDomains = camoConfig.getWhitelistedDomains(); const whitelistedDomains = camoConfig.getWhitelistedDomains();

View File

@ -1,10 +1,8 @@
import Promise from 'bluebird'; import Promise from 'bluebird';
import { ChannelStateSizeError } from '../errors'; import { ChannelStateSizeError } from '../errors';
import db from '../database'; import db from '../database';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('dbstore');
const LOGGER = require('@calzoneman/jsli')('dbstore');
const SIZE_LIMIT = 1048576; const SIZE_LIMIT = 1048576;
const QUERY_CHANNEL_DATA = 'SELECT `key`, `value` FROM channel_data WHERE channel_id = ?'; const QUERY_CHANNEL_DATA = 'SELECT `key`, `value` FROM channel_data WHERE channel_id = ?';

View File

@ -10,9 +10,8 @@ import Promise from 'bluebird';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { throttle } from '../util/throttle'; import { throttle } from '../util/throttle';
import Logger from '../logger'; import Logger from '../logger';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('channel'); const LOGGER = require('@calzoneman/jsli')('channel');
const USERCOUNT_THROTTLE = 10000; const USERCOUNT_THROTTLE = 10000;

View File

@ -1,8 +1,7 @@
var FilterList = require("cytubefilters"); var FilterList = require("cytubefilters");
var ChannelModule = require("./module"); var ChannelModule = require("./module");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('filters'); const LOGGER = require('@calzoneman/jsli')('filters');
/* /*
* Converts JavaScript-style replacements ($1, $2, etc.) with * Converts JavaScript-style replacements ($1, $2, etc.) with

View File

@ -2,9 +2,8 @@ var Vimeo = require("cytube-mediaquery/lib/provider/vimeo");
var ChannelModule = require("./module"); var ChannelModule = require("./module");
var Config = require("../config"); var Config = require("../config");
var InfoGetter = require("../get-info"); var InfoGetter = require("../get-info");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('mediarefresher'); const LOGGER = require('@calzoneman/jsli')('mediarefresher');
function MediaRefresherModule(channel) { function MediaRefresherModule(channel) {
ChannelModule.apply(this, arguments); ChannelModule.apply(this, arguments);

View File

@ -8,9 +8,8 @@ var Flags = require("../flags");
var db = require("../database"); var db = require("../database");
var CustomEmbedFilter = require("../customembed").filter; var CustomEmbedFilter = require("../customembed").filter;
var XSS = require("../xss"); var XSS = require("../xss");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('playlist'); const LOGGER = require('@calzoneman/jsli')('playlist');
const MAX_ITEMS = Config.get("playlist.max-items"); const MAX_ITEMS = Config.get("playlist.max-items");
// Limit requestPlaylist to once per 60 seconds // Limit requestPlaylist to once per 60 seconds

View File

@ -4,11 +4,10 @@ var nodemailer = require("nodemailer");
var net = require("net"); var net = require("net");
var YAML = require("yamljs"); var YAML = require("yamljs");
import { LoggerFactory } from '@calzoneman/jsli';
import { loadFromToml } from 'cytube-common/lib/configuration/configloader'; import { loadFromToml } from 'cytube-common/lib/configuration/configloader';
import { CamoConfig } from './configuration/camoconfig'; import { CamoConfig } from './configuration/camoconfig';
const LOGGER = LoggerFactory.getLogger('config'); const LOGGER = require('@calzoneman/jsli')('config');
var defaults = { var defaults = {
mysql: { mysql: {

View File

@ -2,9 +2,8 @@ import io from 'socket.io';
import Socket from 'socket.io/lib/socket'; import Socket from 'socket.io/lib/socket';
import * as Metrics from 'cytube-common/lib/metrics/metrics'; import * as Metrics from 'cytube-common/lib/metrics/metrics';
import { JSONFileMetricsReporter } from 'cytube-common/lib/metrics/jsonfilemetricsreporter'; import { JSONFileMetricsReporter } from 'cytube-common/lib/metrics/jsonfilemetricsreporter';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('counters'); const LOGGER = require('@calzoneman/jsli')('counters');
var counters = {}; var counters = {};
var server = null; var server = null;

View File

@ -5,11 +5,10 @@ var tables = require("./database/tables");
var net = require("net"); var net = require("net");
var util = require("./utilities"); var util = require("./utilities");
import * as Metrics from 'cytube-common/lib/metrics/metrics'; import * as Metrics from 'cytube-common/lib/metrics/metrics';
import { LoggerFactory } from '@calzoneman/jsli';
import knex from 'knex'; import knex from 'knex';
import { GlobalBanDB } from './db/globalban'; import { GlobalBanDB } from './db/globalban';
const LOGGER = LoggerFactory.getLogger('database'); const LOGGER = require('@calzoneman/jsli')('database');
let db = null; let db = null;
let globalBanDB = null; let globalBanDB = null;

View File

@ -2,9 +2,8 @@ var $util = require("../utilities");
var bcrypt = require("bcrypt"); var bcrypt = require("bcrypt");
var db = require("../database"); var db = require("../database");
var Config = require("../config"); var Config = require("../config");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/accounts'); const LOGGER = require('@calzoneman/jsli')('database/accounts');
var registrationLock = {}; var registrationLock = {};
var blackHole = function () { }; var blackHole = function () { };

View File

@ -5,9 +5,8 @@ var path = require("path");
var tables = require("./tables"); var tables = require("./tables");
var Flags = require("../flags"); var Flags = require("../flags");
var util = require("../utilities"); var util = require("../utilities");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/channels'); const LOGGER = require('@calzoneman/jsli')('database/channels');
var blackHole = function () { }; var blackHole = function () { };

View File

@ -1,9 +1,8 @@
var db = require("../database"); var db = require("../database");
var Q = require("q"); var Q = require("q");
import Promise from 'bluebird'; import Promise from 'bluebird';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/update'); const LOGGER = require('@calzoneman/jsli')('database/update');
const DB_VERSION = 11; const DB_VERSION = 11;
var hasUpdates = []; var hasUpdates = [];

View File

@ -1,10 +1,9 @@
// @flow // @flow
import { Database } from '../database'; import { Database } from '../database';
import { LoggerFactory } from '@calzoneman/jsli';
import net from 'net'; import net from 'net';
const LOGGER = LoggerFactory.getLogger('AliasesDB'); const LOGGER = require('@calzoneman/jsli')('AliasesDB');
class AliasesDB { class AliasesDB {
db: Database; db: Database;

View File

@ -1,8 +1,7 @@
import { LoggerFactory } from '@calzoneman/jsli';
import util from '../utilities'; import util from '../utilities';
import Promise from 'bluebird'; import Promise from 'bluebird';
const LOGGER = LoggerFactory.getLogger('GlobalBanDB'); const LOGGER = require('@calzoneman/jsli')('GlobalBanDB');
class GlobalBanDB { class GlobalBanDB {
constructor(db) { constructor(db) {

View File

@ -6,9 +6,8 @@ var http = require("http");
var urlparse = require("url"); var urlparse = require("url");
var path = require("path"); var path = require("path");
require("status-message-polyfill"); require("status-message-polyfill");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('ffmpeg'); const LOGGER = require('@calzoneman/jsli')('ffmpeg');
var USE_JSON = true; var USE_JSON = true;
var TIMEOUT = 30000; var TIMEOUT = 30000;

View File

@ -13,9 +13,8 @@ var Streamable = require("cytube-mediaquery/lib/provider/streamable");
var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive"); var GoogleDrive = require("cytube-mediaquery/lib/provider/googledrive");
var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod"); var TwitchVOD = require("cytube-mediaquery/lib/provider/twitch-vod");
var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip"); var TwitchClip = require("cytube-mediaquery/lib/provider/twitch-clip");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('get-info'); const LOGGER = require('@calzoneman/jsli')('get-info');
var urlRetrieve = function (transport, options, callback) { var urlRetrieve = function (transport, options, callback) {
var req = transport.request(options, function (res) { var req = transport.request(options, function (res) {

View File

@ -5,8 +5,7 @@ var path = require('path');
var querystring = require('querystring'); var querystring = require('querystring');
var crypto = require('crypto'); var crypto = require('crypto');
import { LoggerFactory } from '@calzoneman/jsli'; const LOGGER = require('@calzoneman/jsli')('google2vtt');
const LOGGER = LoggerFactory.getLogger('google2vtt');
function md5(input) { function md5(input) {
var hash = crypto.createHash('md5'); var hash = crypto.createHash('md5');

View File

@ -1,7 +1,6 @@
import { LoggerFactory } from '@calzoneman/jsli';
import { getIPRange, getWideIPRange } from '../utilities'; import { getIPRange, getWideIPRange } from '../utilities';
const LOGGER = LoggerFactory.getLogger('CachingGlobalBanlist'); const LOGGER = require('@calzoneman/jsli')('CachingGlobalBanlist');
class CachingGlobalBanlist { class CachingGlobalBanlist {
constructor(globalBanDB) { constructor(globalBanDB) {

View File

@ -15,13 +15,12 @@ var session = require("../session");
import counters from '../counters'; import counters from '../counters';
import { verifyIPSessionCookie } from '../web/middleware/ipsessioncookie'; import { verifyIPSessionCookie } from '../web/middleware/ipsessioncookie';
import Promise from 'bluebird'; import Promise from 'bluebird';
import { LoggerFactory } from '@calzoneman/jsli';
const verifySession = Promise.promisify(session.verifySession); const verifySession = Promise.promisify(session.verifySession);
const getAliases = Promise.promisify(db.getAliases); const getAliases = Promise.promisify(db.getAliases);
import { CachingGlobalBanlist } from './globalban'; import { CachingGlobalBanlist } from './globalban';
import proxyaddr from 'proxy-addr'; import proxyaddr from 'proxy-addr';
const LOGGER = LoggerFactory.getLogger('ioserver'); const LOGGER = require('@calzoneman/jsli')('ioserver');
var CONNECT_RATE = { var CONNECT_RATE = {
burst: 5, burst: 5,

View File

@ -2,8 +2,9 @@
var fs = require("graceful-fs"); var fs = require("graceful-fs");
var path = require("path"); var path = require("path");
import { LoggerFactory, Logger as JsliLogger, LogLevel } from '@calzoneman/jsli';
import { sprintf } from 'sprintf-js'; import { sprintf } from 'sprintf-js';
import { Logger as JsliLogger, LogLevel } from '@calzoneman/jsli';
import jsli from '@calzoneman/jsli';
function getTimeString() { function getTimeString() {
var d = new Date(); var d = new Date();
@ -65,25 +66,22 @@ exports.syslog = syslog;
exports.eventlog = eventlog; exports.eventlog = eventlog;
class LegacyLogger extends JsliLogger { class LegacyLogger extends JsliLogger {
constructor(level: LogLevel, loggerName: string) { constructor(loggerName: string, level: LogLevel) {
super(level, loggerName); super(loggerName, level);
} }
log(level: LogLevel, ...args: any[]) { emitMessage(level: LogLevel, message: string) {
var message: string = "[" + level.name + "] " + this.loggerName + ": "; var output: string = `[${level.name}] ${this.loggerName}: ${message}`;
message += sprintf(String(args[0]), ...args.slice(1));
if (level.shouldLogAtLevel(LogLevel.ERROR)) { if (level.shouldLogAtLevel(LogLevel.ERROR)) {
errlog.log(message); errlog.log(output);
} else { } else {
syslog.log(message); syslog.log(output);
} }
} }
} }
const level: LogLevel = !!process.env.DEBUG ? LogLevel.DEBUG : LogLevel.INFO; const level: LogLevel = !!process.env.DEBUG ? LogLevel.DEBUG : LogLevel.INFO;
LoggerFactory.setLoggerImplFactory({ jsli.setLogBackend((loggerName) => {
getLogger(loggerName: string): LegacyLogger { return new LegacyLogger(loggerName, level);
return new LegacyLogger(level, loggerName);
}
}); });

View File

@ -1,7 +1,6 @@
import uuid from 'uuid'; import uuid from 'uuid';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('announcementrefresher'); const LOGGER = require('@calzoneman/jsli')('announcementrefresher');
var SERVER; var SERVER;
const SERVER_ANNOUNCEMENTS = 'serverAnnouncements'; const SERVER_ANNOUNCEMENTS = 'serverAnnouncements';

View File

@ -2,9 +2,8 @@ import Promise from 'bluebird';
import uuid from 'uuid'; import uuid from 'uuid';
import { runLuaScript } from 'cytube-common/lib/redis/lualoader'; import { runLuaScript } from 'cytube-common/lib/redis/lualoader';
import path from 'path'; import path from 'path';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('partitionchannelindex'); const LOGGER = require('@calzoneman/jsli')('partitionchannelindex');
var SERVER = null; var SERVER = null;
const CHANNEL_INDEX = 'publicChannelList'; const CHANNEL_INDEX = 'publicChannelList';

View File

@ -3,7 +3,6 @@ import { PartitionConfig } from './partitionconfig';
import { PartitionDecider } from './partitiondecider'; import { PartitionDecider } from './partitiondecider';
import { PartitionClusterClient } from '../io/cluster/partitionclusterclient'; import { PartitionClusterClient } from '../io/cluster/partitionclusterclient';
import RedisClientProvider from 'cytube-common/lib/redis/redisclientprovider'; import RedisClientProvider from 'cytube-common/lib/redis/redisclientprovider';
import { LoggerFactory } from '@calzoneman/jsli';
import LegacyConfig from '../config'; import LegacyConfig from '../config';
import path from 'path'; import path from 'path';
import { AnnouncementRefresher } from './announcementrefresher'; import { AnnouncementRefresher } from './announcementrefresher';
@ -11,7 +10,7 @@ import { RedisPartitionMapReloader } from './redispartitionmapreloader';
const PARTITION_CONFIG_PATH = path.resolve(__dirname, '..', '..', 'conf', const PARTITION_CONFIG_PATH = path.resolve(__dirname, '..', '..', 'conf',
'partitions.toml'); 'partitions.toml');
const logger = LoggerFactory.getLogger('PartitionModule'); const logger = require('@calzoneman/jsli')('PartitionModule');
class PartitionModule { class PartitionModule {
constructor() { constructor() {

View File

@ -1,8 +1,7 @@
import { PartitionMap } from './partitionmap'; import { PartitionMap } from './partitionmap';
import { LoggerFactory } from '@calzoneman/jsli';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
const logger = LoggerFactory.getLogger('RedisPartitionMapReloader'); const logger = require('@calzoneman/jsli')('RedisPartitionMapReloader');
class RedisPartitionMapReloader extends EventEmitter { class RedisPartitionMapReloader extends EventEmitter {
constructor(config, redisClient, subClient) { constructor(config, redisClient, subClient) {

View File

@ -4,9 +4,8 @@ var Config = require("./config");
var Promise = require("bluebird"); var Promise = require("bluebird");
import * as ChannelStore from './channel-storage/channelstore'; import * as ChannelStore from './channel-storage/channelstore';
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('server'); const LOGGER = require('@calzoneman/jsli')('server');
module.exports = { module.exports = {
init: function () { init: function () {

View File

@ -1,12 +1,11 @@
import https from 'https'; import https from 'https';
import path from 'path'; import path from 'path';
import fs from 'fs'; import fs from 'fs';
import { LoggerFactory } from '@calzoneman/jsli';
import Promise from 'bluebird'; import Promise from 'bluebird';
Promise.promisifyAll(fs); Promise.promisifyAll(fs);
const LOGGER = LoggerFactory.getLogger('torlist'); const LOGGER = require('@calzoneman/jsli')('torlist');
const TOR_EXIT_LIST_URL = 'https://check.torproject.org/exit-addresses'; const TOR_EXIT_LIST_URL = 'https://check.torproject.org/exit-addresses';
const TOR_EXIT_LIST_FILE = path.join(__dirname, '..', 'tor-exit-list.json'); const TOR_EXIT_LIST_FILE = path.join(__dirname, '..', 'tor-exit-list.json');
const ONE_DAY = 24 * 3600 * 1000; const ONE_DAY = 24 * 3600 * 1000;

View File

@ -6,10 +6,9 @@ var ACP = require("./acp");
var Account = require("./account"); var Account = require("./account");
var Flags = require("./flags"); var Flags = require("./flags");
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { LoggerFactory } from '@calzoneman/jsli';
import Logger from './logger'; import Logger from './logger';
const LOGGER = LoggerFactory.getLogger('user'); const LOGGER = require('@calzoneman/jsli')('user');
function User(socket) { function User(socket) {
var self = this; var self = this;

View File

@ -14,9 +14,8 @@ var Server = require("../server");
var session = require("../session"); var session = require("../session");
var csrf = require("./csrf"); var csrf = require("./csrf");
const url = require("url"); const url = require("url");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('database/accounts'); const LOGGER = require('@calzoneman/jsli')('database/accounts');
/** /**
* Handles a GET request for /account/edit * Handles a GET request for /account/edit

View File

@ -15,9 +15,8 @@ var Config = require("../config");
var url = require("url"); var url = require("url");
var session = require("../session"); var session = require("../session");
var csrf = require("./csrf"); var csrf = require("./csrf");
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('web/auth'); const LOGGER = require('@calzoneman/jsli')('web/auth');
/** /**
* Processes a login request. Sets a cookie upon successful authentication * Processes a login request. Sets a cookie upon successful authentication

View File

@ -1,8 +1,7 @@
import CyTubeUtil from '../../utilities'; import CyTubeUtil from '../../utilities';
import * as HTTPStatus from '../httpstatus'; import * as HTTPStatus from '../httpstatus';
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('web/routes/socketconfig'); const LOGGER = require('@calzoneman/jsli')('web/routes/socketconfig');
export default function initialize(app, clusterClient) { export default function initialize(app, clusterClient) {
app.get('/socketconfig/:channel.json', (req, res) => { app.get('/socketconfig/:channel.json', (req, res) => {

View File

@ -11,9 +11,8 @@ import csrf from './csrf';
import * as HTTPStatus from './httpstatus'; import * as HTTPStatus from './httpstatus';
import { CSRFError, HTTPError } from '../errors'; import { CSRFError, HTTPError } from '../errors';
import counters from "../counters"; import counters from "../counters";
import { LoggerFactory } from '@calzoneman/jsli';
const LOGGER = LoggerFactory.getLogger('webserver'); const LOGGER = require('@calzoneman/jsli')('webserver');
function initializeLog(app) { function initializeLog(app) {
const logFormat = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"'; const logFormat = ':real-address - :remote-user [:date] ":method :url HTTP/:http-version" :status :res[content-length] ":referrer" ":user-agent"';