mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2025-12-25 17:08:35 +03:00
Merge pull request #59 from Joe-Dowd/createDBFromSchema
Create DB from schema on start if config option is set
This commit is contained in:
10
index.js
10
index.js
@@ -21,7 +21,8 @@ YouTubeAPI.authenticate({
|
||||
var Sqlite3 = require('better-sqlite3');
|
||||
|
||||
let options = {
|
||||
readonly: config.readOnly
|
||||
readonly: config.readOnly,
|
||||
fileMustExist: !config.createDatabaseIfNotExist
|
||||
};
|
||||
|
||||
//load database
|
||||
@@ -29,6 +30,11 @@ var db = new Sqlite3(config.db, options);
|
||||
//where the more sensitive data such as IP addresses are stored
|
||||
var privateDB = new Sqlite3(config.privateDB, options);
|
||||
|
||||
if (config.createDatabaseIfNotExist && !config.readOnly) {
|
||||
if (fs.existsSync(config.dbSchema)) db.exec(fs.readFileSync(config.dbSchema).toString());
|
||||
if (fs.existsSync(config.privateDBSchema)) privateDB.exec(fs.readFileSync(config.privateDBSchema).toString());
|
||||
}
|
||||
|
||||
// Create an HTTP service.
|
||||
http.createServer(app).listen(config.port);
|
||||
|
||||
@@ -1055,4 +1061,4 @@ function getFormattedTime(seconds) {
|
||||
let formatted = minutes+ ":" + secondsDisplay;
|
||||
|
||||
return formatted;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user