mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-11 17:30:00 +02:00
fix(backend): move GET /recordings/logs/<id> to main router to avoid shelf_router collision with DELETE /<id>
This commit is contained in:
1 parent
989303db77
commit
d91be43f27
2 files changed
+42
-26
No files matched your search
+39
-25
@@ -11,6 +11,42 @@ class RecordingsApi {
|
||||
|
||||
RecordingsApi(this._db, this._scheduler);
|
||||
|
||||
/// Handler pour GET /api/recordings/logs/<id>
|
||||
/// Exposé séparément car shelf_router a un conflit entre DELETE /<id> et GET /logs/<id>
|
||||
Future<Response> 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/<id>', (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/<id> est déclarée directement dans server.dart
|
||||
// car shelf_router a un conflit interne entre DELETE /<id> et GET /logs/<id>
|
||||
// dans le même routeur.
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
+3
-1
@@ -116,7 +116,9 @@ void main(List<String> 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 /<id>)
|
||||
..get('/api/recordings/logs/<id>', recordingsApi.getLogHandler)
|
||||
// TV Recordings endpoints (GET /, POST /, DELETE /<id>)
|
||||
..mount(
|
||||
'/api/recordings',
|
||||
const Pipeline()
|
||||
|
||||
Reference in new issue
Block a user