add full sync
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user