Skip to content

Commit a535131

Browse files
committed
test
1 parent 31e041d commit a535131

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

lib/main.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import 'package:hive_flutter/hive_flutter.dart';
3333
import 'package:musify/extensions/l10n.dart';
3434
import 'package:musify/localization/app_localizations.dart';
3535
import 'package:musify/services/audio_service.dart';
36+
import 'package:musify/services/common_services.dart';
3637
import 'package:musify/services/data_manager.dart';
3738
import 'package:musify/services/io_service.dart';
3839
import 'package:musify/services/logger_service.dart';
@@ -296,6 +297,9 @@ Future<void> initialisation() async {
296297

297298
applicationDirPath = (await getApplicationDocumentsDirectory()).path;
298299
await FilePaths.ensureDirectoriesExist();
300+
301+
unawaited(recentlyPlayedMigration);
302+
unawaited(customPlaylistsImageMigration);
299303
}
300304

301305
void handleIncomingLink(Uri? uri) async {

lib/services/playlists_manager.dart

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,56 @@ final userPlaylists = ValueNotifier<List>(
4343
final userCustomPlaylists = ValueNotifier<List>(
4444
Hive.box('user').get('customPlaylists', defaultValue: []),
4545
);
46+
47+
final customPlaylistsImageMigration = Future.microtask(() async {
48+
try {
49+
var needsPersist = false;
50+
for (final playlist in userCustomPlaylists.value) {
51+
final songs = playlist['list'];
52+
if (songs is! List) continue;
53+
for (final song in songs) {
54+
if (song is! Map) continue;
55+
final ytid = song['ytid']?.toString();
56+
if (ytid == null || ytid.isEmpty) continue;
57+
58+
final highRes = song['highResImage']?.toString() ?? '';
59+
final lowRes = song['lowResImage']?.toString() ?? '';
60+
61+
// A corrupted entry starts with '/' (absolute local path) or is
62+
// otherwise not an HTTP URL.
63+
final highResCorrupted =
64+
highRes.isNotEmpty && !highRes.startsWith('http');
65+
final lowResCorrupted = lowRes.isNotEmpty && !lowRes.startsWith('http');
66+
67+
if (highResCorrupted) {
68+
song['highResImage'] =
69+
'https://i.ytimg.com/vi/$ytid/maxresdefault.jpg';
70+
needsPersist = true;
71+
}
72+
if (lowResCorrupted) {
73+
song['lowResImage'] = 'https://i.ytimg.com/vi/$ytid/default.jpg';
74+
needsPersist = true;
75+
}
76+
}
77+
}
78+
79+
if (needsPersist) {
80+
unawaited(
81+
addOrUpdateData('user', 'customPlaylists', userCustomPlaylists.value),
82+
);
83+
logger.log(
84+
'customPlaylistsImageMigration: repaired corrupted image URLs',
85+
);
86+
}
87+
} catch (e, st) {
88+
logger.log(
89+
'Error migrating custom playlist image URLs',
90+
error: e,
91+
stackTrace: st,
92+
);
93+
}
94+
});
95+
4696
List userLikedPlaylists = Hive.box(
4797
'user',
4898
).get('likedPlaylists', defaultValue: []);

0 commit comments

Comments
 (0)