mirror of
https://git.waldn.net/git/knotteye/satyr.git
synced 2025-09-16 00:24:57 +00:00
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:
23
src/cleanup.ts
Normal file
23
src/cleanup.ts
Normal 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 };
|
@ -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();
|
||||
|
Reference in New Issue
Block a user