Use redirect on cdn

This commit is contained in:
franzap
2026-03-26 21:39:13 -03:00
parent 6f338c5a02
commit cbdeaec676
@@ -348,8 +348,7 @@ abstract class PackageManager extends StateNotifier<PackageManagerState> {
} }
} }
final downloadUrl = target.urls.firstOrNull; if (target.urls.firstOrNull == null || target.urls.firstOrNull!.isEmpty) {
if (downloadUrl == null || downloadUrl.isEmpty) {
setOperation( setOperation(
appId, appId,
OperationFailed( OperationFailed(
@@ -387,9 +386,8 @@ abstract class PackageManager extends StateNotifier<PackageManagerState> {
// Queue items with staggered delays to prevent UI flood // Queue items with staggered delays to prevent UI flood
for (var i = 0; i < toQueue.length; i++) { for (var i = 0; i < toQueue.length; i++) {
final item = toQueue[i]; final item = toQueue[i];
final downloadUrl = item.target.urls.firstOrNull; if (item.target.urls.firstOrNull == null ||
item.target.urls.firstOrNull!.isEmpty) {
if (downloadUrl == null || downloadUrl.isEmpty) {
setOperation( setOperation(
item.appId, item.appId,
OperationFailed( OperationFailed(
@@ -706,6 +704,18 @@ abstract class PackageManager extends StateNotifier<PackageManagerState> {
// DOWNLOAD INTERNALS // DOWNLOAD INTERNALS
// ═══════════════════════════════════════════════════════════════════════════ // ═══════════════════════════════════════════════════════════════════════════
/// Returns the effective download URL for [target].
///
/// If the first URL is already on cdn.zapstore.dev it is used as-is.
/// Otherwise we route through the CDN redirect endpoint so that downloads
/// are tracked regardless of the original host (e.g. GitHub releases).
String? _resolveDownloadUrl(Installable target) {
final first = target.urls.firstOrNull;
if (first == null || first.isEmpty) return null;
if (Uri.tryParse(first)?.host == 'cdn.zapstore.dev') return first;
return 'https://cdn.zapstore.dev/${target.hash}?redirect=true';
}
Future<void> _startDownloadTask( Future<void> _startDownloadTask(
String appId, String appId,
Installable target, Installable target,
@@ -978,7 +988,7 @@ abstract class PackageManager extends StateNotifier<PackageManagerState> {
continue; continue;
} }
final downloadUrl = op.target.urls.firstOrNull; final downloadUrl = _resolveDownloadUrl(op.target);
if (downloadUrl == null) { if (downloadUrl == null) {
setOperation( setOperation(
appId, appId,