add full sync

This commit is contained in:
shenlong-tanwen
2024-09-02 02:16:47 +05:30
parent 877c3b028b
commit e81b61c98b
30 changed files with 333 additions and 179 deletions
@@ -1,6 +1,8 @@
import 'dart:convert';
import 'dart:io';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:flutter/foundation.dart';
import 'package:http/http.dart';
import 'package:immich_mobile/domain/interfaces/store.interface.dart';
import 'package:immich_mobile/domain/models/store.model.dart';
@@ -10,9 +12,21 @@ import 'package:immich_mobile/utils/constants/globals.dart';
import 'package:immich_mobile/utils/mixins/log_context.mixin.dart';
import 'package:openapi/api.dart';
@immutable
class ImmichApiClientData {
final String endpoint;
final Map<String, String> headersMap;
const ImmichApiClientData({required this.endpoint, required this.headersMap});
}
class ImmichApiClient extends ApiClient with LogContext {
ImmichApiClient({required String endpoint}) : super(basePath: endpoint);
/// Used to recreate the client in Isolates
ImmichApiClientData get clientData =>
ImmichApiClientData(endpoint: basePath, headersMap: defaultHeaderMap);
Future<void> init({String? accessToken}) async {
final token =
accessToken ?? (await di<IStoreRepository>().get(StoreKey.accessToken));
@@ -33,6 +47,15 @@ class ImmichApiClient extends ApiClient with LogContext {
addDefaultHeader(kImmichHeaderDeviceType, Platform.operatingSystem);
}
factory ImmichApiClient.clientData(ImmichApiClientData data) {
final client = ImmichApiClient(endpoint: data.endpoint);
for (final entry in data.headersMap.entries) {
client.addDefaultHeader(entry.key, entry.value);
}
return client;
}
@override
Future<Response> invokeAPI(
String path,
@@ -85,8 +108,35 @@ class ImmichApiClient extends ApiClient with LogContext {
return ApiClient.fromJson(value, targetType, growable: growable);
}
@override
// ignore: avoid-dynamic
Future<dynamic> deserializeAsync(
String value,
String targetType, {
bool growable = false,
}) =>
deserialize(value, targetType, growable: growable);
@override
// ignore: avoid-dynamic
Future<dynamic> deserialize(
String value,
String targetType, {
bool growable = false,
}) async {
targetType = targetType.replaceAll(' ', '');
return targetType == 'String'
? value
: fromJson(
await compute((String j) => json.decode(j), value),
targetType,
growable: growable,
);
}
UsersApi getUsersApi() => UsersApi(this);
ServerApi getServerApi() => ServerApi(this);
AuthenticationApi getAuthenticationApi() => AuthenticationApi(this);
OAuthApi getOAuthApi() => OAuthApi(this);
SyncApi getSyncApi() => SyncApi(this);
}