Refactored DI, serialization, added feedback to document download

This commit is contained in:
Anton Stubenbord
2022-12-06 00:39:18 +01:00
parent d79682a011
commit 75fa2f7713
51 changed files with 711 additions and 366 deletions

View File

@@ -4,7 +4,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_mobile/core/service/connectivity_status.service.dart';
import 'package:injectable/injectable.dart';
@singleton
@prod
@test
@lazySingleton
class ConnectivityCubit extends Cubit<ConnectivityState> {
final ConnectivityStatusService connectivityStatusService;
StreamSubscription<bool>? _sub;

View File

@@ -2,7 +2,9 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:paperless_mobile/core/model/document_processing_status.dart';
import 'package:injectable/injectable.dart';
@singleton
@prod
@test
@lazySingleton
class DocumentStatusCubit extends Cubit<DocumentProcessingStatus?> {
DocumentStatusCubit() : super(null);

View File

@@ -3,7 +3,9 @@ import 'package:injectable/injectable.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/bloc/paperless_server_information_state.dart';
@singleton
@prod
@test
@lazySingleton
class PaperlessServerInformationCubit
extends Cubit<PaperlessServerInformationState> {
final PaperlessServerStatsApi service;

View File

@@ -1,14 +1,12 @@
import 'dart:developer';
import 'package:flutter/foundation.dart';
import 'package:paperless_api/paperless_api.dart';
import 'package:paperless_mobile/core/store/local_vault.dart';
import 'package:http_interceptor/http_interceptor.dart';
import 'package:injectable/injectable.dart';
import 'package:paperless_mobile/core/store/local_vault.dart';
@injectable
@dev
@prod
@injectable
class AuthenticationInterceptor implements InterceptorContract {
final LocalVault _localVault;
AuthenticationInterceptor(this._localVault);
@@ -20,15 +18,15 @@ class AuthenticationInterceptor implements InterceptorContract {
if (kDebugMode) {
log("Intercepted ${request.method} request to ${request.url.toString()}");
}
if (auth == null) {
throw const PaperlessServerException(ErrorCode.notAuthenticated);
}
return request.copyWith(
//Append server Url
url: Uri.parse(auth.serverUrl + request.url.toString()),
headers: auth.token.isEmpty
headers: auth?.token?.isEmpty ?? true
? request.headers
: {...request.headers, 'Authorization': 'Token ${auth.token}'},
: {
...request.headers,
'Authorization': 'Token ${auth!.token}',
},
);
}

View File

@@ -0,0 +1,28 @@
import 'package:http_interceptor/http_interceptor.dart';
import 'package:injectable/injectable.dart';
import 'package:paperless_mobile/core/store/local_vault.dart';
@prod
@injectable
class BaseUrlInterceptor implements InterceptorContract {
final LocalVault _localVault;
BaseUrlInterceptor(this._localVault);
@override
Future<BaseRequest> interceptRequest({required BaseRequest request}) async {
final auth = await _localVault.loadAuthenticationInformation();
if (auth == null) {
throw Exception(
"Authentication information not available, cannot perform request!",
);
}
return request.copyWith(
url: Uri.parse(auth.serverUrl + request.url.toString()),
);
}
@override
Future<BaseResponse> interceptResponse(
{required BaseResponse response}) async =>
response;
}

View File

@@ -5,7 +5,6 @@ import 'package:injectable/injectable.dart';
const interceptedRoutes = ['thumb/'];
@injectable
@dev
@prod
class ResponseConversionInterceptor implements InterceptorContract {
@override

View File

@@ -12,10 +12,9 @@ import 'package:injectable/injectable.dart';
///
/// Convenience class which handles timeout errors.
///
@Injectable(as: BaseClient)
@dev
@prod
@Named("timeoutClient")
@Injectable(as: BaseClient)
class TimeoutClient implements BaseClient {
final ConnectivityStatusService connectivityStatusService;
static const Duration requestTimeout = Duration(seconds: 25);

View File

@@ -9,7 +9,8 @@ abstract class ConnectivityStatusService {
Stream<bool> connectivityChanges();
}
@Injectable(as: ConnectivityStatusService, env: ['prod', 'dev'])
@prod
@Injectable(as: ConnectivityStatusService)
class ConnectivityStatusServiceImpl implements ConnectivityStatusService {
final Connectivity connectivity;

View File

@@ -56,7 +56,7 @@ class FileService {
}
}
static Future<Directory?> get downloadsDirectory async {
static Future<Directory> get downloadsDirectory async {
if (Platform.isAndroid) {
return (await getExternalStorageDirectories(
type: StorageDirectory.downloads))!

View File

@@ -17,9 +17,8 @@ abstract class LocalVault {
Future<void> clear();
}
@Injectable(as: LocalVault)
@prod
@dev
@Injectable(as: LocalVault)
class LocalVaultImpl implements LocalVault {
static const applicationSettingsKey = "applicationSettings";
static const authenticationKey = "authentication";