1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-01-16 16:56:46 +01: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:
xpwmaosldk 2022-06-23 13:14:14 +09:00 committed by GitHub
parent caaa474c23
commit ef097d15dd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 100 additions and 103 deletions

View file

@ -3,7 +3,7 @@ version: "3.8"
services: services:
immich-server: immich-server:
image: altran1502/immich-server:latest image: altran1502/immich-server:latest
entrypoint: ["/bin/sh", "./start-server.sh"] entrypoint: [ "/bin/sh", "./start-server.sh" ]
expose: expose:
- "3000" - "3000"
volumes: volumes:
@ -21,7 +21,7 @@ services:
immich-microservices: immich-microservices:
image: altran1502/immich-server:latest image: altran1502/immich-server:latest
entrypoint: ["/bin/sh", "./start-microservices.sh"] entrypoint: [ "/bin/sh", "./start-microservices.sh" ]
volumes: volumes:
- ${UPLOAD_LOCATION}:/usr/src/app/upload - ${UPLOAD_LOCATION}:/usr/src/app/upload
env_file: env_file:
@ -37,7 +37,7 @@ services:
immich-machine-learning: immich-machine-learning:
image: altran1502/immich-machine-learning:latest image: altran1502/immich-machine-learning:latest
entrypoint: ["/bin/sh", "./entrypoint.sh"] entrypoint: [ "/bin/sh", "./entrypoint.sh" ]
expose: expose:
- "3001" - "3001"
volumes: volumes:
@ -54,7 +54,7 @@ services:
immich-web: immich-web:
image: altran1502/immich-web:latest image: altran1502/immich-web:latest
entrypoint: ["/bin/sh", "./entrypoint.sh"] entrypoint: [ "/bin/sh", "./entrypoint.sh" ]
env_file: env_file:
- .env - .env
ports: ports:

View file

@ -4,18 +4,19 @@ import 'package:hive_flutter/hive_flutter.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/constants/immich_colors.dart'; import 'package:immich_mobile/constants/immich_colors.dart';
import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart'; import 'package:immich_mobile/modules/backup/models/hive_backup_albums.model.dart';
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart';
import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart'; import 'package:immich_mobile/modules/login/models/hive_saved_login_info.model.dart';
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart'; import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
import 'package:immich_mobile/shared/providers/asset.provider.dart';
import 'package:immich_mobile/routing/router.dart'; import 'package:immich_mobile/routing/router.dart';
import 'package:immich_mobile/routing/tab_navigation_observer.dart'; import 'package:immich_mobile/routing/tab_navigation_observer.dart';
import 'package:immich_mobile/shared/providers/app_state.provider.dart'; import 'package:immich_mobile/shared/providers/app_state.provider.dart';
import 'package:immich_mobile/modules/backup/providers/backup.provider.dart'; import 'package:immich_mobile/shared/providers/asset.provider.dart';
import 'package:immich_mobile/shared/providers/release_info.provider.dart'; import 'package:immich_mobile/shared/providers/release_info.provider.dart';
import 'package:immich_mobile/shared/providers/server_info.provider.dart'; import 'package:immich_mobile/shared/providers/server_info.provider.dart';
import 'package:immich_mobile/shared/providers/websocket.provider.dart'; import 'package:immich_mobile/shared/providers/websocket.provider.dart';
import 'package:immich_mobile/shared/views/immich_loading_overlay.dart'; import 'package:immich_mobile/shared/views/immich_loading_overlay.dart';
import 'package:immich_mobile/shared/views/version_announcement_overlay.dart'; import 'package:immich_mobile/shared/views/version_announcement_overlay.dart';
import 'constants/hive_box.dart'; import 'constants/hive_box.dart';
void main() async { void main() async {
@ -39,7 +40,7 @@ void main() async {
} }
class ImmichApp extends ConsumerStatefulWidget { class ImmichApp extends ConsumerStatefulWidget {
const ImmichApp({Key? key}) : super(key: key); const ImmichApp({super.key});
@override @override
ImmichAppState createState() => ImmichAppState(); ImmichAppState createState() => ImmichAppState();

View file

@ -33,12 +33,12 @@ class AssetNotifier extends StateNotifier<List<ImmichAsset>> {
deleteAssets(Set<ImmichAsset> deleteAssets) async { deleteAssets(Set<ImmichAsset> deleteAssets) async {
var deviceInfo = await _deviceInfoService.getDeviceInfo(); var deviceInfo = await _deviceInfoService.getDeviceInfo();
var deviceId = deviceInfo["deviceId"]; var deviceId = deviceInfo["deviceId"];
List<String> deleteIdList = []; var deleteIdList = <String>[];
// Delete asset from device // Delete asset from device
for (var asset in deleteAssets) { for (var asset in deleteAssets) {
// Delete asset on device if present // Delete asset on device if present
if (asset.deviceId == deviceId) { if (asset.deviceId == deviceId) {
AssetEntity? localAsset = await AssetEntity.fromId(asset.deviceAssetId); var localAsset = await AssetEntity.fromId(asset.deviceAssetId);
if (localAsset != null) { if (localAsset != null) {
deleteIdList.add(localAsset.id); deleteIdList.add(localAsset.id);

View file

@ -15,7 +15,7 @@ class ReleaseInfoNotifier extends StateNotifier<String> {
try { try {
String? localReleaseVersion = box.get(githubReleaseInfoKey); String? localReleaseVersion = box.get(githubReleaseInfoKey);
Response res = await dio.get( var res = await dio.get(
"https://api.github.com/repos/alextran1502/immich/releases/latest", "https://api.github.com/repos/alextran1502/immich/releases/latest",
options: Options( options: Options(
headers: {"Accept": "application/vnd.github.v3+json"}, headers: {"Accept": "application/vnd.github.v3+json"},

View file

@ -11,7 +11,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
: super( : super(
ServerInfoState( ServerInfoState(
mapboxInfo: MapboxInfo(isEnable: false, mapboxSecret: ""), mapboxInfo: MapboxInfo(isEnable: false, mapboxSecret: ""),
serverVersion: ServerVersion(major: 0, patch: 0, minor: 0, build: 0), serverVersion:
ServerVersion(major: 0, patch: 0, minor: 0, build: 0),
isVersionMismatch: false, isVersionMismatch: false,
versionMismatchErrorMessage: "", versionMismatchErrorMessage: "",
), ),
@ -33,7 +34,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
state = state.copyWith(serverVersion: serverVersion); state = state.copyWith(serverVersion: serverVersion);
PackageInfo packageInfo = await PackageInfo.fromPlatform(); var packageInfo = await PackageInfo.fromPlatform();
Map<String, int> appVersion = _getDetailVersion(packageInfo.version); Map<String, int> appVersion = _getDetailVersion(packageInfo.version);
@ -57,7 +58,8 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
return; return;
} }
state = state.copyWith(isVersionMismatch: false, versionMismatchErrorMessage: ""); state = state.copyWith(
isVersionMismatch: false, versionMismatchErrorMessage: "");
} }
Map<String, int> _getDetailVersion(String version) { Map<String, int> _getDetailVersion(String version) {
@ -75,6 +77,7 @@ class ServerInfoNotifier extends StateNotifier<ServerInfoState> {
} }
} }
final serverInfoProvider = StateNotifierProvider<ServerInfoNotifier, ServerInfoState>((ref) { final serverInfoProvider =
StateNotifierProvider<ServerInfoNotifier, ServerInfoState>((ref) {
return ServerInfoNotifier(); return ServerInfoNotifier();
}); });

View file

@ -4,8 +4,8 @@ import 'dart:io' show Platform;
class DeviceInfoService { class DeviceInfoService {
Future<Map<String, dynamic>> getDeviceInfo() async { Future<Map<String, dynamic>> getDeviceInfo() async {
// Get device info // Get device info
String deviceId = await FlutterUdid.consistentUdid; var deviceId = await FlutterUdid.consistentUdid;
String deviceType = ""; var deviceType = "";
if (Platform.isAndroid) { if (Platform.isAndroid) {
deviceType = "ANDROID"; deviceType = "ANDROID";

View file

@ -4,15 +4,22 @@ import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:hive/hive.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/constants/hive_box.dart';
import 'package:immich_mobile/utils/dio_http_interceptor.dart'; import 'package:immich_mobile/utils/dio_http_interceptor.dart';
import 'package:immich_mobile/utils/files_helper.dart';
class NetworkService { class NetworkService {
late final Dio dio;
NetworkService() {
dio = Dio();
dio.interceptors.add(AuthenticatedRequestInterceptor());
}
Future<dynamic> deleteRequest({required String url, dynamic data}) async { Future<dynamic> deleteRequest({required String url, dynamic data}) async {
try { try {
var dio = Dio();
dio.interceptors.add(AuthenticatedRequestInterceptor());
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
Response res = await dio.delete('$savedEndpoint/$url', data: data); 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 { try {
var dio = Dio();
dio.interceptors.add(AuthenticatedRequestInterceptor());
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
if (isByteResponse) { if (isByteResponse) {
@ -66,12 +73,9 @@ class NetworkService {
Future<dynamic> postRequest({required String url, dynamic data}) async { Future<dynamic> postRequest({required String url, dynamic data}) async {
try { try {
var dio = Dio();
dio.interceptors.add(AuthenticatedRequestInterceptor());
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
String validUrl = Uri.parse('$savedEndpoint/$url').toString(); var validUrl = Uri.parse('$savedEndpoint/$url').toString();
Response res = await dio.post(validUrl, data: data); var res = await dio.post(validUrl, data: data);
return res; return res;
} on DioError catch (e) { } on DioError catch (e) {
@ -85,12 +89,9 @@ class NetworkService {
Future<dynamic> putRequest({required String url, dynamic data}) async { Future<dynamic> putRequest({required String url, dynamic data}) async {
try { try {
var dio = Dio();
dio.interceptors.add(AuthenticatedRequestInterceptor());
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
String validUrl = Uri.parse('$savedEndpoint/$url').toString(); var validUrl = Uri.parse('$savedEndpoint/$url').toString();
Response res = await dio.put(validUrl, data: data); var res = await dio.put(validUrl, data: data);
return res; return res;
} on DioError catch (e) { } on DioError catch (e) {
@ -104,13 +105,9 @@ class NetworkService {
Future<dynamic> patchRequest({required String url, dynamic data}) async { Future<dynamic> patchRequest({required String url, dynamic data}) async {
try { try {
var dio = Dio();
dio.interceptors.add(AuthenticatedRequestInterceptor());
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
var validUrl = Uri.parse('$savedEndpoint/$url').toString();
String validUrl = Uri.parse('$savedEndpoint/$url').toString(); var res = await dio.patch(validUrl, data: data);
Response res = await dio.patch(validUrl, data: data);
return res; return res;
} on DioError catch (e) { } on DioError catch (e) {
@ -122,21 +119,15 @@ class NetworkService {
Future<bool> pingServer() async { Future<bool> pingServer() async {
try { try {
var dio = Dio();
var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey); var savedEndpoint = Hive.box(userInfoBox).get(serverEndpointKey);
var validUrl = Uri.parse('$savedEndpoint/server-info/ping').toString();
String validUrl = Uri.parse('$savedEndpoint/server-info/ping').toString();
debugPrint("ping server at url $validUrl"); debugPrint("ping server at url $validUrl");
Response res = await dio.get(validUrl);
var res = await dio.get(validUrl);
var jsonRespsonse = jsonDecode(res.toString()); var jsonRespsonse = jsonDecode(res.toString());
if (jsonRespsonse["res"] == "pong") { return jsonRespsonse["res"] == "pong";
return true;
} else {
return false;
}
} on DioError catch (e) { } on DioError catch (e) {
debugPrint("[PING SERVER] DioError: ${e.response} - $e"); debugPrint("[PING SERVER] DioError: ${e.response} - $e");
return false; return false;

View file

@ -3,6 +3,7 @@ import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:hive/hive.dart'; import 'package:hive/hive.dart';
import 'package:http_parser/http_parser.dart';
import 'package:image_picker/image_picker.dart'; import 'package:image_picker/image_picker.dart';
import 'package:immich_mobile/constants/hive_box.dart'; import 'package:immich_mobile/constants/hive_box.dart';
import 'package:immich_mobile/shared/models/upload_profile_image_repsonse.model.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/shared/services/network.service.dart';
import 'package:immich_mobile/utils/dio_http_interceptor.dart'; import 'package:immich_mobile/utils/dio_http_interceptor.dart';
import 'package:immich_mobile/utils/files_helper.dart'; import 'package:immich_mobile/utils/files_helper.dart';
import 'package:http_parser/http_parser.dart';
class UserService { class UserService {
final NetworkService _networkService = NetworkService(); final NetworkService _networkService = NetworkService();
Future<List<User>> getAllUsersInfo() async { Future<List<User>> getAllUsersInfo() async {
try { try {
Response res = await _networkService.getRequest(url: 'user'); var res = await _networkService.getRequest(url: 'user');
List<dynamic> decodedData = jsonDecode(res.toString()); List<dynamic> decodedData = jsonDecode(res.toString());
List<User> result = List.from(decodedData.map((e) => User.fromMap(e))); List<User> result = List.from(decodedData.map((e) => User.fromMap(e)));

View file

@ -10,12 +10,10 @@ class ImmichToast {
ToastType toastType = ToastType.info, ToastType toastType = ToastType.info,
ToastGravity gravity = ToastGravity.TOP, ToastGravity gravity = ToastGravity.TOP,
}) { }) {
FToast fToast; final fToast = FToast();
fToast = FToast();
fToast.init(context); fToast.init(context);
_getColor(ToastType type, BuildContext context) { Color _getColor(ToastType type, BuildContext context) {
switch (type) { switch (type) {
case ToastType.info: case ToastType.info:
return Theme.of(context).primaryColor; return Theme.of(context).primaryColor;
@ -26,6 +24,26 @@ class ImmichToast {
} }
} }
Icon _getIcon(ToastType type) {
switch (type) {
case ToastType.info:
return Icon(
Icons.info_outline_rounded,
color: Theme.of(context).primaryColor,
);
case ToastType.success:
return const Icon(
Icons.check_circle_rounded,
color: Color.fromARGB(255, 78, 140, 124),
);
case ToastType.error:
return const Icon(
Icons.error_outline_rounded,
color: Color.fromARGB(255, 240, 162, 156),
);
}
}
fToast.showToast( fToast.showToast(
child: Container( child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0), padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
@ -40,24 +58,7 @@ class ImmichToast {
child: Row( child: Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,
children: [ children: [
(toastType == ToastType.info) _getIcon(toastType),
? Icon(
Icons.info_outline_rounded,
color: Theme.of(context).primaryColor,
)
: Container(),
(toastType == ToastType.success)
? const Icon(
Icons.check_circle_rounded,
color: Color.fromARGB(255, 78, 140, 124),
)
: Container(),
(toastType == ToastType.error)
? const Icon(
Icons.error_outline_rounded,
color: Color.fromARGB(255, 240, 162, 156),
)
: Container(),
const SizedBox( const SizedBox(
width: 12.0, width: 12.0,
), ),

View file

@ -9,25 +9,25 @@ class ImmichLoadingOverlay extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return ValueListenableBuilder<bool>( return ValueListenableBuilder<bool>(
valueListenable: ImmichLoadingOverlayController.appLoader.loaderShowingNotifier, valueListenable:
ImmichLoadingOverlayController.appLoader.loaderShowingNotifier,
builder: (context, shouldShow, child) { builder: (context, shouldShow, child) {
if (shouldShow) { return shouldShow
return const Scaffold( ? const Scaffold(
backgroundColor: Colors.black54, backgroundColor: Colors.black54,
body: Center( body: Center(
child: ImmichLoadingIndicator(), child: ImmichLoadingIndicator(),
), ),
); )
} else { : const SizedBox();
return Container();
}
}, },
); );
} }
} }
class ImmichLoadingOverlayController { class ImmichLoadingOverlayController {
static final ImmichLoadingOverlayController appLoader = ImmichLoadingOverlayController(); static final ImmichLoadingOverlayController appLoader =
ImmichLoadingOverlayController();
ValueNotifier<bool> loaderShowingNotifier = ValueNotifier(false); ValueNotifier<bool> loaderShowingNotifier = ValueNotifier(false);
ValueNotifier<String> loaderTextNotifier = ValueNotifier('error message'); ValueNotifier<String> loaderTextNotifier = ValueNotifier('error message');

View file

@ -85,7 +85,7 @@ class VersionAnnouncementOverlay extends HookConsumerWidget {
const TextSpan( const TextSpan(
text: text:
" and ensure your docker-compose and .env setup is up-to-date to prevent any misconfigurations, especially if you use WatchTower or any mechanism that handles updating your server application automatically.", " and ensure your docker-compose and .env setup is up-to-date to prevent any misconfigurations, especially if you use WatchTower or any mechanism that handles updating your server application automatically.",
) ),
], ],
), ),
), ),
@ -93,23 +93,24 @@ class VersionAnnouncementOverlay extends HookConsumerWidget {
Padding( Padding(
padding: const EdgeInsets.only(top: 16.0), padding: const EdgeInsets.only(top: 16.0),
child: ElevatedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
shape: const StadiumBorder(), shape: const StadiumBorder(),
visualDensity: VisualDensity.standard, visualDensity: VisualDensity.standard,
primary: Colors.indigo, primary: Colors.indigo,
onPrimary: Colors.grey[50], onPrimary: Colors.grey[50],
elevation: 2, elevation: 2,
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(
vertical: 10, horizontal: 25), vertical: 10, horizontal: 25),
),
onPressed: onAcknowledgeTapped,
child: const Text(
"Acknowledge",
style: TextStyle(
fontSize: 14,
), ),
onPressed: onAcknowledgeTapped, ),
child: const Text( ),
"Acknowledge", ),
style: TextStyle(
fontSize: 14,
),
)),
)
], ],
), ),
), ),

View file

@ -5,7 +5,7 @@ publish_to: "none"
version: 1.12.1+19 version: 1.12.1+19
environment: environment:
sdk: ">=2.15.1 <3.0.0" sdk: ">=2.17.0 <3.0.0"
dependencies: dependencies:
flutter: flutter: