Add config key for selecting storage mode
This commit is contained in:
parent
e91635b6f9
commit
9c5ada6134
|
@ -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'
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -110,6 +110,9 @@ var defaults = {
|
|||
"user": "nobody",
|
||||
"timeout": 15
|
||||
},
|
||||
"channel-storage": {
|
||||
type: "file"
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue