fix(link): sync no loopback artwork from older statistics

History sync sends artwork as http(s) URLs, and statistics rows from
older builds hold loopback URLs of the author's cover proxy. A first
sync with a new peer copied those into the peer's statistics, where
they name the peer's own loopback server instead. Sent and received
artwork now drops loopback URLs, so peers store none.
This commit is contained in:
zarzet committed 2026-10-30 15:46:59 +07:00
1 parent 28ff305699
commit bb7dd1e833
2 files changed
+34 -2

No files matched your search

@@ -1,3 +1,5 @@
import 'package:mornye/services/cover_store.dart';
/// Mornye Link collections and history sync (unit L4). Both directions use
/// the same JSON, so the desktop (server) and the phone (client) share one
/// store implementation per database.
@@ -224,13 +226,14 @@ class LinkHistoryEvent {
}
}
/// Artwork another device can load: http and https URLs only.
/// Artwork another device can load: http and https URLs only, without the
/// loopback URLs older builds recorded, which named the author's own proxy.
String? linkSyncRemoteArtwork(Object? value) {
final artwork = _string(value);
if (artwork == null) return null;
final lower = artwork.toLowerCase();
return lower.startsWith('https://') || lower.startsWith('http://')
? artwork
? durableCoverReference(artwork)
: null;
}
+29
View File
@@ -186,4 +186,33 @@ void main() {
isNull,
);
});
test('loopback artwork an older build recorded is never synced', () async {
final directory = await linkSyncTempDirectory();
final db = await openLinkListeningDatabase(directory, 'phone');
final store = LinkHistorySyncStore(() async => db);
const loopback = 'http://127.0.0.1:41234/7f3a';
await db.insert('listening', {
'day': '2026-10-20',
'track_key': '/a.flac',
'title': 'Song',
'artist': 'Artist',
'album': 'Album',
'artwork': loopback,
'milliseconds': 1000,
'plays': 0,
});
final page = await store.eventsSince(0);
expect(page.items.single.trackKey, '/a.flac');
expect(page.items.single.artwork, isNull);
final event = LinkHistoryEvent.fromJson({
'origin': 'peer',
'day': '2026-10-20',
'trackKey': '/b.flac',
'artwork': loopback,
'ms': 1000,
'plays': 0,
});
expect(event!.artwork, isNull);
});
}