mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-09 12:08:05 -06:00
Refactored DI, serialization, added feedback to document download
This commit is contained in:
@@ -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}',
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
28
lib/core/interceptor/base_url_interceptor.dart
Normal file
28
lib/core/interceptor/base_url_interceptor.dart
Normal 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;
|
||||
}
|
||||
@@ -5,7 +5,6 @@ import 'package:injectable/injectable.dart';
|
||||
const interceptedRoutes = ['thumb/'];
|
||||
|
||||
@injectable
|
||||
@dev
|
||||
@prod
|
||||
class ResponseConversionInterceptor implements InterceptorContract {
|
||||
@override
|
||||
|
||||
Reference in New Issue
Block a user