This commit is contained in:
calzoneman 2015-10-01 22:02:59 -07:00
parent 0e66875d27
commit 56a2a52bdd
6 changed files with 25 additions and 9 deletions

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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 = {