Server autocloses on crash

Thumbnails are now retrieved using file UID
This commit is contained in:
Isaac Abadi
2021-07-31 15:51:16 -06:00
parent b8e1117ff6
commit c789ba9553
2 changed files with 11 additions and 10 deletions

View File

@@ -327,9 +327,14 @@ async function startServer() {
await setPortItemFromENV();
}
app.listen(backendPort,function(){
const server = app.listen(backendPort,function(){
logger.info(`YoutubeDL-Material ${CONSTS['CURRENT_VERSION']} started on PORT ${backendPort}`);
});
process.on('uncaughtException', err => {
logger.error('Server has crashed!');
logger.error(err);
server.close();
})
}
async function restartServer(is_update = false) {
@@ -616,23 +621,18 @@ async function setConfigFromEnv() {
}
async function loadConfig() {
logger.info('loading config')
loadConfigValues();
// connect to DB
logger.info('connecting to db')
await db_api.connectToDB();
// creates archive path if missing
logger.info('ensuring archive path of ' + archivePath)
await fs.ensureDir(archivePath);
// check migrations
logger.info('checking migrations')
await checkMigrations();
// now this is done here due to youtube-dl's repo takedown
logger.info('starting youtube dl')
await startYoutubeDL();
// get subscriptions
@@ -2479,9 +2479,10 @@ app.get('/api/stream', optionalJwt, async (req, res) => {
}
});
app.get('/api/thumbnail/:path', optionalJwt, async (req, res) => {
let file_path = decodeURIComponent(req.params.path);
if (fs.existsSync(file_path)) path.isAbsolute(file_path) ? res.sendFile(file_path) : res.sendFile(path.join('./', file_path));
app.get('/api/thumbnail/:uid', optionalJwt, async (req, res) => {
const file_obj = await db_api.getRecord('files', {uid: req.params.uid});
const file_path = file_obj['thumbnailPath'];
if (fs.existsSync(file_path)) res.sendFile(file_path, { root: '.' });
else res.sendStatus(404);
});

View File

@@ -72,7 +72,7 @@ export class UnifiedFileCardComponent implements OnInit {
}
if (this.file_obj && this.file_obj.thumbnailPath) {
this.thumbnailBlobURL = `${this.baseStreamPath}thumbnail/${encodeURIComponent(this.file_obj.thumbnailPath)}${this.jwtString}`;
this.thumbnailBlobURL = `${this.baseStreamPath}thumbnail/${this.file_obj.uid}${this.jwtString}`;
/*const mime = getMimeByFilename(this.file_obj.thumbnailPath);
const blob = new Blob([new Uint8Array(this.file_obj.thumbnailBlob.data)], {type: mime});
const bloburl = URL.createObjectURL(blob);