mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-10 04:08:03 -06:00
Externalized API and models as own package
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:paperless_mobile/core/model/error_message.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:uuid/uuid.dart';
|
||||
|
||||
@@ -12,7 +12,7 @@ class FileService {
|
||||
) async {
|
||||
final dir = await documentsDirectory;
|
||||
if (dir == null) {
|
||||
throw const ErrorMessage.unknown(); //TODO: better handling
|
||||
throw const PaperlessServerException.unknown(); //TODO: better handling
|
||||
}
|
||||
File file = File("${dir.path}/$filename");
|
||||
return file..writeAsBytes(bytes);
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:paperless_mobile/core/model/paperless_server_information.dart';
|
||||
import 'package:paperless_mobile/core/store/local_vault.dart';
|
||||
|
||||
@injectable
|
||||
class PaperlessServerInformationService {
|
||||
final BaseClient client;
|
||||
final LocalVault localStore;
|
||||
|
||||
PaperlessServerInformationService(
|
||||
@Named("timeoutClient") this.client,
|
||||
this.localStore,
|
||||
);
|
||||
|
||||
Future<PaperlessServerInformation> getInformation() async {
|
||||
final response = await client.get(Uri.parse("/api/ui_settings/"));
|
||||
final version =
|
||||
response.headers[PaperlessServerInformation.versionHeader] ?? 'unknown';
|
||||
final apiVersion = int.tryParse(
|
||||
response.headers[PaperlessServerInformation.apiVersionHeader] ?? '1');
|
||||
final String username =
|
||||
jsonDecode(utf8.decode(response.bodyBytes))['username'];
|
||||
final String? host =
|
||||
response.headers[PaperlessServerInformation.hostHeader] ??
|
||||
response.request?.headers[PaperlessServerInformation.hostHeader] ??
|
||||
('${response.request?.url.host}:${response.request?.url.port}');
|
||||
return PaperlessServerInformation(
|
||||
username: username,
|
||||
version: version,
|
||||
apiVersion: apiVersion,
|
||||
host: host,
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:http/http.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:paperless_mobile/core/model/error_message.dart';
|
||||
import 'package:paperless_mobile/core/model/paperless_statistics.dart';
|
||||
import 'package:paperless_mobile/core/type/types.dart';
|
||||
|
||||
abstract class PaperlessStatisticsService {
|
||||
Future<PaperlessStatistics> getStatistics();
|
||||
}
|
||||
|
||||
@Injectable(as: PaperlessStatisticsService)
|
||||
class PaperlessStatisticsServiceImpl extends PaperlessStatisticsService {
|
||||
final BaseClient client;
|
||||
|
||||
PaperlessStatisticsServiceImpl(@Named('timeoutClient') this.client);
|
||||
|
||||
@override
|
||||
Future<PaperlessStatistics> getStatistics() async {
|
||||
final response = await client.get(Uri.parse('/api/statistics/'));
|
||||
if (response.statusCode == 200) {
|
||||
return PaperlessStatistics.fromJson(
|
||||
jsonDecode(utf8.decode(response.bodyBytes)) as JSON,
|
||||
);
|
||||
}
|
||||
throw const ErrorMessage.unknown();
|
||||
}
|
||||
}
|
||||
@@ -3,14 +3,13 @@ import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/bloc/document_status_cubit.dart';
|
||||
import 'package:paperless_mobile/core/model/document_processing_status.dart';
|
||||
import 'package:paperless_mobile/di_initializer.dart';
|
||||
import 'package:paperless_mobile/features/documents/model/document.model.dart';
|
||||
import 'package:paperless_mobile/features/documents/model/paged_search_result.dart';
|
||||
import 'package:paperless_mobile/features/login/model/authentication_information.dart';
|
||||
import 'package:paperless_mobile/util.dart';
|
||||
import 'package:injectable/injectable.dart';
|
||||
import 'package:web_socket_channel/io.dart';
|
||||
|
||||
abstract class StatusService {
|
||||
|
||||
Reference in New Issue
Block a user