mirror of
https://github.com/ajayyy/SponsorBlockServer.git
synced 2024-11-10 09:07:47 +01: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:
commit
60dfec3375
2 changed files with 14 additions and 3 deletions
|
@ -1,4 +1,6 @@
|
|||
{
|
||||
// Remove all comments from the config when using it!
|
||||
|
||||
"port": 80,
|
||||
"globalSalt": "[global salt (pepper) that is added to every ip before hashing to make it even harder for someone to decode the ip]",
|
||||
"adminUserID": "[the hashed id of the user who can perform admin actions]",
|
||||
|
@ -8,6 +10,9 @@
|
|||
"behindProxy": true,
|
||||
"db": "./databases/sponsorTimes.db",
|
||||
"privateDB": "./databases/private.db",
|
||||
"createDatabaseIfNotExist": true, //This will run on startup every time (unless readOnly is true) - so ensure "create table if not exists" is used in the schema
|
||||
"dbSchema": "./databases/_sponsorTimes.db.sql",
|
||||
"privateDBSchema": "./databases/_private.db.sql",
|
||||
"mode": "development",
|
||||
"readOnly": false
|
||||
}
|
||||
}
|
||||
|
|
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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue