Add config key for selecting storage mode

This commit is contained in:
calzoneman 2015-09-30 21:55:45 -07:00
parent e91635b6f9
commit 9c5ada6134
3 changed files with 25 additions and 1 deletions

View file

@ -219,3 +219,13 @@ setuid:
user: 'user'
# how long to wait in ms before changing uid/gid
timeout: 15
# Determines channel data storage mechanism.
# Defaults to 'file', in which channel data is JSON stringified and saved to a file
# in the `chandump/` folder. This is the legacy behavior of CyTube.
# The other possible option is 'database', in which case each key-value pair of
# channel data is stored as a row in the `channel_data` database table.
# To migrate legacy chandump files to the database, shut down CyTube (to prevent
# concurrent updates), then run `node lib/channel-storage/migrate.js`.
channel-storage:
type: 'file'

View file

@ -1,7 +1,8 @@
import { FileStore } from './filestore';
import { DatabaseStore } from './dbstore';
import Config from '../config';
const CHANNEL_STORE = new FileStore();
const CHANNEL_STORE = loadChannelStore();
export function load(channelName) {
return CHANNEL_STORE.load(channelName);
@ -10,3 +11,13 @@ export function load(channelName) {
export function save(channelName, data) {
return CHANNEL_STORE.save(channelName, data);
}
function loadChannelStore() {
switch (Config.get('channel-storage.type')) {
case 'database':
return new DatabaseStore();
case 'file':
default:
return new FileStore();
}
}

View file

@ -110,6 +110,9 @@ var defaults = {
"user": "nobody",
"timeout": 15
},
"channel-storage": {
type: "file"
}
};
/**