diff --git a/backend/app.js b/backend/app.js index 210d5e0..ba05197 100644 --- a/backend/app.js +++ b/backend/app.js @@ -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); }); diff --git a/src/app/components/unified-file-card/unified-file-card.component.ts b/src/app/components/unified-file-card/unified-file-card.component.ts index 0f92bf0..a4a0dc0 100644 --- a/src/app/components/unified-file-card/unified-file-card.component.ts +++ b/src/app/components/unified-file-card/unified-file-card.component.ts @@ -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);