2015-09-26 14:21:42 -07:00
|
|
|
import { DatabaseStore } from './dbstore';
|
2015-09-30 21:55:45 -07:00
|
|
|
import Config from '../config';
|
2015-10-01 22:02:59 -07:00
|
|
|
import Promise from 'bluebird';
|
2015-09-20 23:17:06 -07:00
|
|
|
|
2015-10-01 22:02:59 -07:00
|
|
|
var CHANNEL_STORE = null;
|
|
|
|
|
|
|
|
|
|
export function init() {
|
|
|
|
|
CHANNEL_STORE = loadChannelStore();
|
|
|
|
|
}
|
2015-09-20 23:17:06 -07:00
|
|
|
|
2016-09-26 22:20:58 -07:00
|
|
|
export function load(id, channelName) {
|
2015-10-01 22:02:59 -07:00
|
|
|
if (CHANNEL_STORE === null) {
|
|
|
|
|
return Promise.reject(new Error('ChannelStore not initialized yet'));
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 22:20:58 -07:00
|
|
|
return CHANNEL_STORE.load(id, channelName);
|
2015-09-20 23:17:06 -07:00
|
|
|
}
|
|
|
|
|
|
2016-09-26 22:20:58 -07:00
|
|
|
export function save(id, channelName, data) {
|
2015-10-01 22:02:59 -07:00
|
|
|
if (CHANNEL_STORE === null) {
|
|
|
|
|
return Promise.reject(new Error('ChannelStore not initialized yet'));
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 22:20:58 -07:00
|
|
|
return CHANNEL_STORE.save(id, channelName, data);
|
2015-09-20 23:17:06 -07:00
|
|
|
}
|
2015-09-30 21:55:45 -07:00
|
|
|
|
|
|
|
|
function loadChannelStore() {
|
2020-02-15 16:17:49 -08:00
|
|
|
if (Config.get('channel-storage.type') === 'file') {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'channel-storage type "file" is no longer supported. Please see ' +
|
|
|
|
|
'NEWS.md for instructions on upgrading.'
|
|
|
|
|
);
|
2015-09-30 21:55:45 -07:00
|
|
|
}
|
2020-02-15 16:17:49 -08:00
|
|
|
|
|
|
|
|
return new DatabaseStore();
|
2015-09-30 21:55:45 -07:00
|
|
|
}
|