@@ -452,13 +452,32 @@ class SubsonicService {
452452 required String name,
453453 List <String >? songIds,
454454 }) async {
455- final params = < String , String > {'name' : name};
455+ // songId must be appended directly, using it as a map key would produce
456+ // songId[i]=x which Navidrome doesn't recognize
457+ String url = _buildUrl ('createPlaylist' , {'name' : name});
456458 if (songIds != null && songIds.isNotEmpty) {
457- for (int i = 0 ; i < songIds.length; i ++ ) {
458- params[ ' songId[$ i ]' ] = songIds[i] ;
459+ for (final songId in songIds) {
460+ url += '& songId=${ Uri . encodeComponent ( songId )}' ;
459461 }
460462 }
461- await _request ('createPlaylist' , params);
463+
464+ try {
465+ final response = await _dio.get (url);
466+ final data = response.data;
467+
468+ final decoded = data is String ? json.decode (data) : data;
469+ final subsonicResponse = decoded['subsonic-response' ];
470+ if (subsonicResponse == null ) {
471+ throw Exception ('Invalid response format' );
472+ }
473+
474+ if (subsonicResponse['status' ] != 'ok' ) {
475+ final error = subsonicResponse['error' ];
476+ throw Exception (error? ['message' ] ?? 'Unknown error' );
477+ }
478+ } on DioException catch (e) {
479+ throw Exception ('Network error: ${e .message }' );
480+ }
462481 }
463482
464483 Future <void > updatePlaylist ({
@@ -486,15 +505,14 @@ class SubsonicService {
486505 }
487506 }
488507
489- debugPrint ('updatePlaylist URL: $url ' );
508+ debugPrint ('updatePlaylist URL: ${ _sanitizeUrl ( url )} ' );
490509
491510 try {
492511 final response = await _dio.get (url);
493512 final data = response.data;
494513
495- final subsonicResponse = data is String
496- ? json.decode (data)
497- : data['subsonic-response' ];
514+ final decoded = data is String ? json.decode (data) : data;
515+ final subsonicResponse = decoded['subsonic-response' ];
498516 if (subsonicResponse == null ) {
499517 throw Exception ('Invalid response format' );
500518 }
0 commit comments