2015-09-21 06:17:06 +00:00
|
|
|
import { FileStore } from './filestore';
|
2015-09-26 21:21:42 +00:00
|
|
|
import { DatabaseStore } from './dbstore';
|
2015-10-01 04:55:45 +00:00
|
|
|
import Config from '../config';
|
2015-10-02 05:02:59 +00:00
|
|
|
import Promise from 'bluebird';
|
2015-09-21 06:17:06 +00:00
|
|
|
|
2015-10-02 05:02:59 +00:00
|
|
|
var CHANNEL_STORE = null;
|
|
|
|
|
|
|
|
export function init() {
|
|
|
|
CHANNEL_STORE = loadChannelStore();
|
|
|
|
}
|
2015-09-21 06:17:06 +00:00
|
|
|
|
2016-09-27 05:20:58 +00:00
|
|
|
export function load(id, channelName) {
|
2015-10-02 05:02:59 +00:00
|
|
|
if (CHANNEL_STORE === null) {
|
|
|
|
return Promise.reject(new Error('ChannelStore not initialized yet'));
|
|
|
|
}
|
|
|
|
|
2016-09-27 05:20:58 +00:00
|
|
|
return CHANNEL_STORE.load(id, channelName);
|
2015-09-21 06:17:06 +00:00
|
|
|
}
|
|
|
|
|
2016-09-27 05:20:58 +00:00
|
|
|
export function save(id, channelName, data) {
|
2015-10-02 05:02:59 +00:00
|
|
|
if (CHANNEL_STORE === null) {
|
|
|
|
return Promise.reject(new Error('ChannelStore not initialized yet'));
|
|
|
|
}
|
|
|
|
|
2016-09-27 05:20:58 +00:00
|
|
|
return CHANNEL_STORE.save(id, channelName, data);
|
2015-09-21 06:17:06 +00:00
|
|
|
}
|
2015-10-01 04:55:45 +00:00
|
|
|
|
|
|
|
function loadChannelStore() {
|
|
|
|
switch (Config.get('channel-storage.type')) {
|
|
|
|
case 'database':
|
|
|
|
return new DatabaseStore();
|
|
|
|
case 'file':
|
|
|
|
default:
|
|
|
|
return new FileStore();
|
|
|
|
}
|
|
|
|
}
|