mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-11 04:07:56 -06:00
Hooked notifications to status changes on document upload - some refactorings
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:paperless_mobile/core/model/document_processing_status.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
|
||||
@prod
|
||||
@test
|
||||
@lazySingleton
|
||||
class DocumentStatusCubit extends Cubit<DocumentProcessingStatus?> {
|
||||
DocumentStatusCubit() : super(null);
|
||||
|
||||
|
||||
@@ -1,20 +1,17 @@
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/bloc/paperless_server_information_state.dart';
|
||||
import 'package:paperless_mobile/core/security/session_manager.dart';
|
||||
|
||||
@prod
|
||||
@test
|
||||
@lazySingleton
|
||||
class PaperlessServerInformationCubit
|
||||
extends Cubit<PaperlessServerInformationState> {
|
||||
final PaperlessServerStatsApi service;
|
||||
final PaperlessServerStatsApi _api;
|
||||
|
||||
PaperlessServerInformationCubit(this.service)
|
||||
PaperlessServerInformationCubit(this._api)
|
||||
: super(PaperlessServerInformationState());
|
||||
|
||||
Future<void> updateInformtion() async {
|
||||
final information = await service.getServerInformation();
|
||||
final information = await _api.getServerInformation();
|
||||
emit(PaperlessServerInformationState(
|
||||
isLoaded: true,
|
||||
information: information,
|
||||
|
||||
@@ -68,5 +68,9 @@ String translateError(BuildContext context, ErrorCode code) {
|
||||
return S.of(context).errorMessageUnsupportedFileFormat;
|
||||
case ErrorCode.missingClientCertificate:
|
||||
return S.of(context).errorMessageMissingClientCertificate;
|
||||
case ErrorCode.suggestionsQueryError:
|
||||
return S.of(context).errorMessageSuggestionsQueryError;
|
||||
case ErrorCode.acknowledgeTasksError:
|
||||
return S.of(context).errorMessageAcknowledgeTasksError;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,20 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/adapter.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/interceptor/dio_http_error_interceptor.dart';
|
||||
import 'package:paperless_mobile/core/interceptor/retry_on_connection_change_interceptor.dart';
|
||||
import 'package:paperless_mobile/features/login/model/client_certificate.dart';
|
||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||
|
||||
class AuthenticationAwareDioManager {
|
||||
class SessionManager {
|
||||
final Dio client;
|
||||
final List<Interceptor> interceptors;
|
||||
PaperlessServerInformationModel serverInformation;
|
||||
|
||||
AuthenticationAwareDioManager([this.interceptors = const []])
|
||||
: client = _initDio(interceptors);
|
||||
SessionManager([this.interceptors = const []])
|
||||
: client = _initDio(interceptors),
|
||||
serverInformation = PaperlessServerInformationModel();
|
||||
|
||||
static Dio _initDio(List<Interceptor> interceptors) {
|
||||
//en- and decoded by utf8 by default
|
||||
@@ -19,8 +24,19 @@ class AuthenticationAwareDioManager {
|
||||
dio.options.responseType = ResponseType.json;
|
||||
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||
(client) => client..badCertificateCallback = (cert, host, port) => true;
|
||||
dio.interceptors.addAll(interceptors);
|
||||
dio.interceptors.add(RetryOnConnectionChangeInterceptor(dio: dio));
|
||||
dio.interceptors.addAll([
|
||||
...interceptors,
|
||||
DioHttpErrorInterceptor(),
|
||||
PrettyDioLogger(
|
||||
compact: true,
|
||||
responseBody: false,
|
||||
responseHeader: false,
|
||||
request: false,
|
||||
requestBody: false,
|
||||
requestHeader: false,
|
||||
),
|
||||
RetryOnConnectionChangeInterceptor(dio: dio)
|
||||
]);
|
||||
return dio;
|
||||
}
|
||||
|
||||
@@ -28,6 +44,7 @@ class AuthenticationAwareDioManager {
|
||||
String? baseUrl,
|
||||
String? authToken,
|
||||
ClientCertificate? clientCertificate,
|
||||
PaperlessServerInformationModel? serverInformation,
|
||||
}) {
|
||||
if (clientCertificate != null) {
|
||||
final context = SecurityContext()
|
||||
@@ -58,11 +75,16 @@ class AuthenticationAwareDioManager {
|
||||
if (authToken != null) {
|
||||
client.options.headers.addAll({'Authorization': 'Token $authToken'});
|
||||
}
|
||||
|
||||
if (serverInformation != null) {
|
||||
this.serverInformation = serverInformation;
|
||||
}
|
||||
}
|
||||
|
||||
void resetSettings() {
|
||||
client.httpClientAdapter = DefaultHttpClientAdapter();
|
||||
client.options.baseUrl = '';
|
||||
client.options.headers.remove('Authorization');
|
||||
serverInformation = PaperlessServerInformationModel();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user