diff --git a/package.json b/package.json index 8294458b..9002d45d 100644 --- a/package.json +++ b/package.json @@ -39,9 +39,9 @@ }, "scripts": { "build-player": "$npm_node_execpath build-player.js", - "build-server": "babel --source-maps --out-dir lib/ src/", + "build-server": "babel --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/", "postinstall": "./postinstall.sh", - "server-dev": "babel --watch --source-maps --out-dir lib/ src/" + "server-dev": "babel --watch --source-maps --loose es6.destructuring,es6.forOf --out-dir lib/ src/" }, "devDependencies": { "coffee-script": "^1.9.2" diff --git a/src/channel-storage/channelstore.js b/src/channel-storage/channelstore.js index 247565d3..278dab46 100644 --- a/src/channel-storage/channelstore.js +++ b/src/channel-storage/channelstore.js @@ -1,14 +1,27 @@ import { FileStore } from './filestore'; import { DatabaseStore } from './dbstore'; import Config from '../config'; +import Promise from 'bluebird'; -const CHANNEL_STORE = loadChannelStore(); +var CHANNEL_STORE = null; + +export function init() { + CHANNEL_STORE = loadChannelStore(); +} export function load(channelName) { + if (CHANNEL_STORE === null) { + return Promise.reject(new Error('ChannelStore not initialized yet')); + } + return CHANNEL_STORE.load(channelName); } export function save(channelName, data) { + if (CHANNEL_STORE === null) { + return Promise.reject(new Error('ChannelStore not initialized yet')); + } + return CHANNEL_STORE.save(channelName, data); } diff --git a/src/channel-storage/dbstore.js b/src/channel-storage/dbstore.js index 00f34864..163ff27d 100644 --- a/src/channel-storage/dbstore.js +++ b/src/channel-storage/dbstore.js @@ -45,14 +45,14 @@ export class DatabaseStore { return queryAsync(QUERY_CHANNEL_DATA, [rows[0].id]); }).then(rows => { const data = {}; - for (const row of rows) { + rows.forEach(row => { try { data[row.key] = JSON.parse(row.value); } catch (e) { Logger.errlog.log(`Channel data for channel "${channelName}", ` + `key "${row.key}" is invalid: ${e}`); } - } + }); return data; }); @@ -68,7 +68,7 @@ export class DatabaseStore { let rowCount = 0; const id = rows[0].id; const substitutions = []; - for (const key of Object.keys(data)) { + for (const key in data) { if (typeof data[key] === 'undefined') { continue; } diff --git a/src/channel-storage/migrator.js b/src/channel-storage/migrator.js index 46e462c5..25ae82ef 100644 --- a/src/channel-storage/migrator.js +++ b/src/channel-storage/migrator.js @@ -39,9 +39,9 @@ function queryAsync(query, substitutions) { function fixOldChandump(data) { const converted = {}; - for (const key of EXPECTED_KEYS) { + EXPECTED_KEYS.forEach(key => { converted[key] = data[key]; - } + }); if (data.queue) { converted.playlist = { diff --git a/src/database.js b/src/database.js index 129f7912..d6c23bef 100644 --- a/src/database.js +++ b/src/database.js @@ -556,7 +556,8 @@ module.exports.listStats = function (callback) { /* Misc */ module.exports.loadAnnouncement = function () { - if (!Server.getServer()) { + // Temporary workaround + if (!Server.getServer || !Server.getServer()) { return; } diff --git a/src/server.js b/src/server.js index 79250e56..31e5bfbe 100644 --- a/src/server.js +++ b/src/server.js @@ -2,6 +2,7 @@ const VERSION = require("../package.json").version; var singleton = null; var Config = require("./config"); var Promise = require("bluebird"); +import * as ChannelStore from './channel-storage/channelstore'; module.exports = { init: function () { @@ -56,6 +57,7 @@ var Server = function () { var Database = require("./database"); self.db = Database; self.db.init(); + ChannelStore.init(); // webserver init ----------------------------------------------------- self.express = express();