diff --git a/bin/api/recordings_api.dart b/bin/api/recordings_api.dart index 0cf2af0..f080014 100644 --- a/bin/api/recordings_api.dart +++ b/bin/api/recordings_api.dart @@ -11,6 +11,42 @@ class RecordingsApi { RecordingsApi(this._db, this._scheduler); + /// Handler pour GET /api/recordings/logs/ + /// Exposé séparément car shelf_router a un conflit entre DELETE / et GET /logs/ + Future getLogHandler(Request request, String id) async { + final recording = _db.getRecordingById(id); + + if (recording == null) { + return Response.notFound( + json.encode({'error': 'Enregistrement non trouvé'}), + headers: {'Content-Type': 'application/json'}, + ); + } + + if (recording.filePath == null) { + return Response.notFound( + json.encode({'error': 'Aucun fichier ni log associé pour le moment.'}), + headers: {'Content-Type': 'application/json'}, + ); + } + + final logFilePath = recording.filePath!.replaceAll('.mp4', '.log'); + final logFile = File(logFilePath); + + if (!await logFile.exists()) { + return Response.notFound( + json.encode({'error': 'Le fichier de log est introuvable. Chemin: $logFilePath'}), + headers: {'Content-Type': 'application/json'}, + ); + } + + final logs = await logFile.readAsString(); + return Response.ok( + json.encode({'logs': logs}), + headers: {'Content-Type': 'application/json'}, + ); + } + Router get router { final router = Router(); @@ -86,31 +122,9 @@ class RecordingsApi { ); }); - // Consulter les logs d'un enregistrement - router.get('/logs/', (Request request, String id) async { - final recording = _db.getRecordingById(id); - - if (recording == null) { - return Response.notFound(json.encode({'error': 'Enregistrement non trouvé'})); - } - - if (recording.filePath == null) { - return Response.notFound(json.encode({'error': 'Aucun fichier ni log associé pour le moment.'})); - } - - final logFilePath = recording.filePath!.replaceAll('.mp4', '.log'); - final logFile = File(logFilePath); - - if (!await logFile.exists()) { - return Response.notFound(json.encode({'error': 'Le fichier de log est introuvable.'})); - } - - final logs = await logFile.readAsString(); - return Response.ok( - json.encode({'logs': logs}), - headers: {'Content-Type': 'application/json'}, - ); - }); + // Note: La route GET /logs/ est déclarée directement dans server.dart + // car shelf_router a un conflit interne entre DELETE / et GET /logs/ + // dans le même routeur. return router; } diff --git a/bin/server.dart b/bin/server.dart index a3ae400..562974d 100644 --- a/bin/server.dart +++ b/bin/server.dart @@ -116,7 +116,9 @@ void main(List args) async { .addMiddleware(authMiddleware(db)) .addHandler(settingsHandler.router.call), ) - // TV Recordings endpoints + // TV Recordings - Route des logs AVANT le mount general (évite collision shelf_router avec /) + ..get('/api/recordings/logs/', recordingsApi.getLogHandler) + // TV Recordings endpoints (GET /, POST /, DELETE /) ..mount( '/api/recordings', const Pipeline()