Add cleanup script to fix any problems arising from restarting the server mid-stream.

This may cause further problems if the user manages to reconnect before the cleanup script has finished, but the server *shouldn't* start listening until after the script is done.
Increment version I guess, I don't really know how versioning works.
This commit is contained in:
knotteye
2019-10-22 18:24:10 -05:00
parent 8cc8083361
commit 61bf54de95
4 changed files with 38 additions and 4 deletions

23
src/cleanup.ts Normal file
View File

@ -0,0 +1,23 @@
import * as db from "./database";
import * as read from "recursive-readdir";
import * as fs from "fs";
async function init(siteDir: string) {
//If satyr is restarted in the middle of a stream
//it causes problems
//Live flags in the database stay live
await db.query('update user_meta set live=false');
//and stray m3u8 files will play the last
//few seconds of a stream back
try {
var files = await read(siteDir+'/live', ['!*.m3u8']);
}
catch (error) {}
if(files === undefined || files.length == 0) return;
for(let i=0;i<files.length;i++){
fs.unlinkSync(files[i]);
}
return;
}
export { init };

View File

@ -2,9 +2,10 @@ import * as mediaserver from "./server";
import * as db from "./database";
import * as api from "./api";
import * as http from "./http";
import * as cleanup from "./cleanup"
import * as config from "config";
function run(): void{
async function run() {
const dbcfg: object = config.database;
const bcryptcfg: object = config.bcrypt;
const satyr: object = {
@ -52,9 +53,10 @@ function run(): void{
}
};
db.init(dbcfg, bcryptcfg);
await cleanup.init(config.server.http.directory);
api.init(satyr);
http.init(satyr, config.server.http.port);
db.init(dbcfg, bcryptcfg);
mediaserver.init(nms, satyr);
}
run();