fix(ui): fetch covers via the Go backend instead of raw HttpClient

Both call sites used a bare dart:io HttpClient with no timeout, retry, or
cache; downloadCoverToFile provides all three (plus the singleflight cover
cache) and can hang-proof the embed path.
This commit is contained in:
zarzet
2026-07-14 12:49:57 +07:00
parent cdc1ba0a68
commit c6e012b23d
2 changed files with 16 additions and 20 deletions
@@ -903,22 +903,18 @@ extension _DownloadQueueEmbedding on DownloadQueueNotifier {
'${DateTime.now().millisecondsSinceEpoch}_${Random().nextInt(10000)}';
final coverPath = '${tempDir.path}/cover_embed_$uniqueId.jpg';
final httpClient = HttpClient();
try {
final request = await httpClient.getUrl(Uri.parse(coverUrl));
final response = await request.close();
if (response.statusCode != 200) {
_log.w('Failed to download cover: HTTP ${response.statusCode}');
return null;
}
final sink = File(coverPath).openWrite();
await response.pipe(sink);
await sink.close();
_log.d('Cover downloaded for embedding: $coverPath');
return coverPath;
} finally {
httpClient.close();
// Go's cover pipeline: shared cache/singleflight, retries, timeouts.
final result = await PlatformBridge.downloadCoverToFile(
coverUrl,
coverPath,
maxQuality: false,
);
if (result['error'] != null) {
_log.w('Failed to download cover: ${result['error']}');
return null;
}
_log.d('Cover downloaded for embedding: $coverPath');
return coverPath;
} catch (e) {
_log.e('Failed to download cover for embedding: $e');
return null;
+5 -5
View File
@@ -938,12 +938,12 @@ class _EditMetadataSheetState extends State<_EditMetadataSheet> {
);
final coverOutput =
'${tempDir.path}${Platform.pathSeparator}cover.jpg';
final response = await HttpClient()
.getUrl(Uri.parse(coverUrl))
.then((req) => req.close());
await PlatformBridge.downloadCoverToFile(
coverUrl,
coverOutput,
maxQuality: false,
);
final file = File(coverOutput);
final sink = file.openWrite();
await response.pipe(sink);
if (await file.exists() && await file.length() > 0) {
await _cleanupSelectedCoverTemp();
if (mounted) {