2024-12-05 15:11:48 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2024-11-26 18:43:44 +00:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
|
|
import 'package:immich_mobile/entities/album.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/etag.entity.dart';
|
|
|
|
import 'package:immich_mobile/entities/exif_info.entity.dart';
|
2024-12-05 15:11:48 +00:00
|
|
|
import 'package:immich_mobile/entities/store.entity.dart';
|
2024-11-26 18:43:44 +00:00
|
|
|
import 'package:immich_mobile/entities/user.entity.dart';
|
|
|
|
import 'package:immich_mobile/interfaces/auth.interface.dart';
|
2024-12-05 15:11:48 +00:00
|
|
|
import 'package:immich_mobile/models/auth/auxilary_endpoint.model.dart';
|
2024-11-26 18:43:44 +00:00
|
|
|
import 'package:immich_mobile/providers/db.provider.dart';
|
|
|
|
import 'package:immich_mobile/repositories/database.repository.dart';
|
|
|
|
|
|
|
|
final authRepositoryProvider = Provider<IAuthRepository>(
|
|
|
|
(ref) => AuthRepository(ref.watch(dbProvider)),
|
|
|
|
);
|
|
|
|
|
|
|
|
class AuthRepository extends DatabaseRepository implements IAuthRepository {
|
|
|
|
AuthRepository(super.db);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Future<void> clearLocalData() {
|
2024-11-26 19:36:12 +00:00
|
|
|
return db.writeTxn(() {
|
|
|
|
return Future.wait([
|
|
|
|
db.assets.clear(),
|
|
|
|
db.exifInfos.clear(),
|
|
|
|
db.albums.clear(),
|
|
|
|
db.eTags.clear(),
|
|
|
|
db.users.clear(),
|
|
|
|
]);
|
2024-11-26 18:43:44 +00:00
|
|
|
});
|
|
|
|
}
|
2024-12-05 15:11:48 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
String getAccessToken() {
|
|
|
|
return Store.get(StoreKey.accessToken);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool getEndpointSwitchingFeature() {
|
|
|
|
return Store.tryGet(StoreKey.autoEndpointSwitching) ?? false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String? getPreferredWifiName() {
|
|
|
|
return Store.tryGet(StoreKey.preferredWifiName);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
String? getLocalEndpoint() {
|
|
|
|
return Store.tryGet(StoreKey.localEndpoint);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
List<AuxilaryEndpoint> getExternalEndpointList() {
|
|
|
|
final jsonString = Store.tryGet(StoreKey.externalEndpointList);
|
|
|
|
|
|
|
|
if (jsonString == null) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
final List<dynamic> jsonList = jsonDecode(jsonString);
|
|
|
|
final endpointList =
|
|
|
|
jsonList.map((e) => AuxilaryEndpoint.fromJson(e)).toList();
|
|
|
|
|
|
|
|
return endpointList;
|
|
|
|
}
|
2024-11-26 18:43:44 +00:00
|
|
|
}
|