Refactor geo assets

This commit is contained in:
problematicconsumer
2023-11-25 22:00:40 +03:30
parent 6040eae6ce
commit e2d9d5e53e
29 changed files with 594 additions and 507 deletions

View File

@@ -0,0 +1,39 @@
import 'package:hiddify/features/geo_asset/model/geo_asset_entity.dart';
/// default geoip asset bundled with the app
const defaultGeoip = GeoAssetEntity(
id: "sing-box-geoip",
name: "geoip.db",
type: GeoAssetType.geoip,
active: true,
providerName: "SagerNet/sing-geoip",
);
/// default geosite asset bundled with the app
const defaultGeosite = GeoAssetEntity(
id: "sing-box-geosite",
name: "geosite.db",
type: GeoAssetType.geosite,
active: true,
providerName: "SagerNet/sing-geosite",
);
const defaultGeoAssets = [defaultGeoip, defaultGeosite];
const recommendedGeoAssets = [
...defaultGeoAssets,
GeoAssetEntity(
id: "chocolate4U-geoip",
name: "geoip.db",
type: GeoAssetType.geoip,
active: false,
providerName: "Chocolate4U/Iran-sing-box-rules",
),
GeoAssetEntity(
id: "chocolate4U-geosite",
name: "geosite.db",
type: GeoAssetType.geosite,
active: false,
providerName: "Chocolate4U/Iran-sing-box-rules",
),
];

View File

@@ -0,0 +1,27 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'geo_asset_entity.freezed.dart';
enum GeoAssetType { geoip, geosite }
typedef GeoAssetWithFileSize = (GeoAssetEntity geoAsset, int? size);
@freezed
class GeoAssetEntity with _$GeoAssetEntity {
const GeoAssetEntity._();
const factory GeoAssetEntity({
required String id,
required String name,
required GeoAssetType type,
required bool active,
required String providerName,
String? version,
DateTime? lastCheck,
}) = _GeoAssetEntity;
String get fileName => name;
String get repositoryUrl =>
"https://api.github.com/repos/$providerName/releases/latest";
}

View File

@@ -0,0 +1,39 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:hiddify/core/prefs/prefs.dart';
import 'package:hiddify/domain/failures.dart';
part 'geo_asset_failure.freezed.dart';
@freezed
sealed class GeoAssetFailure with _$GeoAssetFailure, Failure {
const GeoAssetFailure._();
const factory GeoAssetFailure.unexpected([
Object? error,
StackTrace? stackTrace,
]) = GeoAssetUnexpectedFailure;
@With<ExpectedFailure>()
const factory GeoAssetFailure.noUpdateAvailable() = GeoAssetNoUpdateAvailable;
const factory GeoAssetFailure.activeAssetNotFound() =
GeoAssetActiveAssetNotFound;
@override
({String type, String? message}) present(TranslationsEn t) {
return switch (this) {
GeoAssetUnexpectedFailure() => (
type: t.failure.geoAssets.unexpected,
message: null,
),
GeoAssetNoUpdateAvailable() => (
type: t.failure.geoAssets.notUpdate,
message: null
),
GeoAssetActiveAssetNotFound() => (
type: t.failure.geoAssets.activeNotFound,
message: null,
),
};
}
}