mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Clean code of shared folder (#249)
* optimize android side gradle settings * android minsdk back to 21 * remove unused package, update linter and fix lint error * clean code of 'shared module' with offical dart style guide * restore uploadProfileImage method in UserService
This commit is contained in:
@@ -4,8 +4,8 @@ import 'dart:io' show Platform;
|
||||
class DeviceInfoService {
|
||||
Future<Map<String, dynamic>> getDeviceInfo() async {
|
||||
// Get device info
|
||||
String deviceId = await FlutterUdid.consistentUdid;
|
||||
String deviceType = "";
|
||||
var deviceId = await FlutterUdid.consistentUdid;
|
||||
var deviceType = "";
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
deviceType = "ANDROID";
|
||||
|
||||
@@ -4,15 +4,22 @@ import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:immich_mobile/constants/hive_box.dart';
|
||||
import 'package:immich_mobile/utils/dio_http_interceptor.dart';
|
||||
import 'package:immich_mobile/utils/files_helper.dart';
|
||||
|
||||
class NetworkService {
|
||||
late final Dio dio;
|
||||
|
||||
NetworkService() {
|
||||
dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
}
|
||||
|
||||
Future<dynamic> deleteRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
Response res = await dio.delete('$savedEndpoint/$url', data: data);
|
||||
|
||||
@@ -26,11 +33,11 @@ class NetworkService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<dynamic> getRequest({required String url, bool isByteResponse = false, bool isStreamReponse = false}) async {
|
||||
Future<dynamic> getRequest(
|
||||
{required String url,
|
||||
bool isByteResponse = false,
|
||||
bool isStreamReponse = false}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
|
||||
if (isByteResponse) {
|
||||
@@ -66,12 +73,9 @@ class NetworkService {
|
||||
|
||||
Future<dynamic> postRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
String validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
Response res = await dio.post(validUrl, data: data);
|
||||
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
var res = await dio.post(validUrl, data: data);
|
||||
|
||||
return res;
|
||||
} on DioError catch (e) {
|
||||
@@ -85,12 +89,9 @@ class NetworkService {
|
||||
|
||||
Future<dynamic> putRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
String validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
Response res = await dio.put(validUrl, data: data);
|
||||
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
var res = await dio.put(validUrl, data: data);
|
||||
|
||||
return res;
|
||||
} on DioError catch (e) {
|
||||
@@ -104,13 +105,9 @@ class NetworkService {
|
||||
|
||||
Future<dynamic> patchRequest({required String url, dynamic data}) async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
|
||||
String validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
Response res = await dio.patch(validUrl, data: data);
|
||||
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
|
||||
var res = await dio.patch(validUrl, data: data);
|
||||
|
||||
return res;
|
||||
} on DioError catch (e) {
|
||||
@@ -122,21 +119,15 @@ class NetworkService {
|
||||
|
||||
Future<bool> pingServer() async {
|
||||
try {
|
||||
var dio = Dio();
|
||||
|
||||
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||
|
||||
String validUrl = Uri.parse('$savedEndpoint/server-info/ping').toString();
|
||||
var validUrl = Uri.parse('$savedEndpoint/server-info/ping').toString();
|
||||
|
||||
debugPrint("ping server at url $validUrl");
|
||||
Response res = await dio.get(validUrl);
|
||||
|
||||
var res = await dio.get(validUrl);
|
||||
var jsonRespsonse = jsonDecode(res.toString());
|
||||
|
||||
if (jsonRespsonse["res"] == "pong") {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return jsonRespsonse["res"] == "pong";
|
||||
} on DioError catch (e) {
|
||||
debugPrint("[PING SERVER] DioError: ${e.response} - $e");
|
||||
return false;
|
||||
|
||||
@@ -3,6 +3,7 @@ import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
import 'package:image_picker/image_picker.dart';
|
||||
import 'package:immich_mobile/constants/hive_box.dart';
|
||||
import 'package:immich_mobile/shared/models/upload_profile_image_repsonse.model.dart';
|
||||
@@ -10,14 +11,13 @@ import 'package:immich_mobile/shared/models/user.model.dart';
|
||||
import 'package:immich_mobile/shared/services/network.service.dart';
|
||||
import 'package:immich_mobile/utils/dio_http_interceptor.dart';
|
||||
import 'package:immich_mobile/utils/files_helper.dart';
|
||||
import 'package:http_parser/http_parser.dart';
|
||||
|
||||
class UserService {
|
||||
final NetworkService _networkService = NetworkService();
|
||||
|
||||
Future<List<User>> getAllUsersInfo() async {
|
||||
try {
|
||||
Response res = await _networkService.getRequest(url: 'user');
|
||||
var res = await _networkService.getRequest(url: 'user');
|
||||
List<dynamic> decodedData = jsonDecode(res.toString());
|
||||
List<User> result = List.from(decodedData.map((e) => User.fromMap(e)));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user