mirror of
https://github.com/immich-app/immich.git
synced 2025-12-14 00:30:47 -08:00
Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c234c95880 | ||
|
|
7cc7fc0a0c | ||
|
|
897d49f734 | ||
|
|
051c958c8b | ||
|
|
56627caf5b | ||
|
|
4f47c8c06b | ||
|
|
de1dbcea9c | ||
|
|
d1498506a8 | ||
|
|
9bcbdd31ce | ||
|
|
38c968d47e | ||
|
|
f578ca6d47 |
2
.github/workflows/Build+push Immich.yml
vendored
2
.github/workflows/Build+push Immich.yml
vendored
@@ -39,7 +39,7 @@ jobs:
|
|||||||
context: ./server
|
context: ./server
|
||||||
file: ./server/Dockerfile
|
file: ./server/Dockerfile
|
||||||
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
#platforms: linux/amd64,linux/arm64,linux/riscv64,linux/ppc64le,linux/s390x,linux/386,linux/mips64le,linux/mips64,linux/arm/v7,linux/arm/v6
|
||||||
platforms: linux/arm/v7,linux/amd64
|
platforms: linux/arm/v7,linux/amd64,linux/arm64
|
||||||
pull: true
|
pull: true
|
||||||
push: true
|
push: true
|
||||||
tags: |
|
tags: |
|
||||||
|
|||||||
2
LICENSE
2
LICENSE
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2022 Alex
|
Copyright (c) 2022 Hau Tran
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -2,4 +2,7 @@ dev:
|
|||||||
docker-compose -f ./server/docker-compose.yml up
|
docker-compose -f ./server/docker-compose.yml up
|
||||||
|
|
||||||
dev-update:
|
dev-update:
|
||||||
docker-compose -f ./server/docker-compose.yml up --build -V
|
docker-compose -f ./server/docker-compose.yml up --build -V
|
||||||
|
|
||||||
|
dev-scale:
|
||||||
|
docker-compose -f ./server/docker-compose.yml up --build -V --scale immich_server=3 --remove-orphans
|
||||||
|
|||||||
27
README.md
27
README.md
@@ -22,25 +22,25 @@ Loading ~4000 images/videos
|
|||||||
|
|
||||||
# Note
|
# Note
|
||||||
|
|
||||||
This project is under heavy development, there will be continous functions, features and api changes.
|
|
||||||
|
|
||||||
**!! NOT READY FOR PRODUCTION! DO NOT USE TO STORE YOUR ASSETS !!**
|
**!! NOT READY FOR PRODUCTION! DO NOT USE TO STORE YOUR ASSETS !!**
|
||||||
|
|
||||||
|
This project is under heavy development, there will be continous functions, features and api changes.
|
||||||
|
|
||||||
# Features
|
# Features
|
||||||
|
|
||||||
[x] Upload assets(videos/images)
|
- Upload assets(videos/images).
|
||||||
|
- View assets.
|
||||||
[x] View assets
|
- Quick navigation with drag scroll bar.
|
||||||
|
- Auto Backup.
|
||||||
[x] Quick navigation with drag scroll bar
|
- Support HEIC/HEIF Backup.
|
||||||
|
- Extract and display EXIF info.
|
||||||
[x] Auto Backup
|
- Real-time render from multi-device upload event.
|
||||||
|
|
||||||
# Development
|
# Development
|
||||||
|
|
||||||
You can use docker compose for development, there are several services that compose Immich
|
You can use docker compose for development, there are several services that compose Immich
|
||||||
|
|
||||||
1. The server
|
1. NestJs
|
||||||
2. PostgreSQL
|
2. PostgreSQL
|
||||||
3. Redis
|
3. Redis
|
||||||
4. Nginx
|
4. Nginx
|
||||||
@@ -49,17 +49,18 @@ You can use docker compose for development, there are several services that comp
|
|||||||
|
|
||||||
Navigate to `server` directory and run
|
Navigate to `server` directory and run
|
||||||
|
|
||||||
```
|
````
|
||||||
cp .env.example .env
|
cp .env.example .env
|
||||||
```
|
|
||||||
|
|
||||||
Then populate the value in there.
|
Then populate the value in there.
|
||||||
|
|
||||||
|
Pay attention to the key `UPLOAD_LOCATION`, this directory must exist and is owned by the user that run the `docker-compose` command below.
|
||||||
|
|
||||||
To start, run
|
To start, run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker-compose -f ./server/docker-compose.yml up
|
docker-compose -f ./server/docker-compose.yml up
|
||||||
```
|
````
|
||||||
|
|
||||||
To force rebuild node modules after installing new packages
|
To force rebuild node modules after installing new packages
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,11 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
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/modules/home/providers/asset.provider.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.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/shared/providers/backup.provider.dart';
|
import 'package:immich_mobile/shared/providers/backup.provider.dart';
|
||||||
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
||||||
import 'constants/hive_box.dart';
|
import 'constants/hive_box.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
|
||||||
@@ -36,20 +38,23 @@ class _ImmichAppState extends ConsumerState<ImmichApp> with WidgetsBindingObserv
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case AppLifecycleState.resumed:
|
case AppLifecycleState.resumed:
|
||||||
debugPrint("[APP STATE] resumed");
|
debugPrint("[APP STATE] resumed");
|
||||||
ref.read(appStateProvider.notifier).state = AppStateEnum.resumed;
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.resumed;
|
||||||
ref.read(backupProvider.notifier).resumeBackup();
|
ref.watch(backupProvider.notifier).resumeBackup();
|
||||||
|
ref.watch(websocketProvider.notifier).connect();
|
||||||
|
ref.watch(assetProvider.notifier).getAllAsset();
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.inactive:
|
case AppLifecycleState.inactive:
|
||||||
debugPrint("[APP STATE] inactive");
|
debugPrint("[APP STATE] inactive");
|
||||||
ref.read(appStateProvider.notifier).state = AppStateEnum.inactive;
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.inactive;
|
||||||
|
ref.watch(websocketProvider.notifier).disconnect();
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.paused:
|
case AppLifecycleState.paused:
|
||||||
debugPrint("[APP STATE] paused");
|
debugPrint("[APP STATE] paused");
|
||||||
ref.read(appStateProvider.notifier).state = AppStateEnum.paused;
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.paused;
|
||||||
break;
|
break;
|
||||||
case AppLifecycleState.detached:
|
case AppLifecycleState.detached:
|
||||||
debugPrint("[APP STATE] detached");
|
debugPrint("[APP STATE] detached");
|
||||||
ref.read(appStateProvider.notifier).state = AppStateEnum.detached;
|
ref.watch(appStateProvider.notifier).state = AppStateEnum.detached;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class ImageViewerPageState {
|
||||||
|
final bool isBottomSheetEnable;
|
||||||
|
ImageViewerPageState({
|
||||||
|
required this.isBottomSheetEnable,
|
||||||
|
});
|
||||||
|
|
||||||
|
ImageViewerPageState copyWith({
|
||||||
|
bool? isBottomSheetEnable,
|
||||||
|
}) {
|
||||||
|
return ImageViewerPageState(
|
||||||
|
isBottomSheetEnable: isBottomSheetEnable ?? this.isBottomSheetEnable,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'isBottomSheetEnable': isBottomSheetEnable,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory ImageViewerPageState.fromMap(Map<String, dynamic> map) {
|
||||||
|
return ImageViewerPageState(
|
||||||
|
isBottomSheetEnable: map['isBottomSheetEnable'] ?? false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
factory ImageViewerPageState.fromJson(String source) => ImageViewerPageState.fromMap(json.decode(source));
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => 'ImageViewerPageState(isBottomSheetEnable: $isBottomSheetEnable)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is ImageViewerPageState && other.isBottomSheetEnable == isBottomSheetEnable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => isBottomSheetEnable.hashCode;
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/modules/asset_viewer/models/image_viewer_page_state.model.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/models/home_page_state.model.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
|
|
||||||
|
class ImageViewerPageStateNotifier extends StateNotifier<ImageViewerPageState> {
|
||||||
|
ImageViewerPageStateNotifier() : super(ImageViewerPageState(isBottomSheetEnable: false));
|
||||||
|
|
||||||
|
void toggleBottomSheet() {
|
||||||
|
bool isBottomSheetEnable = state.isBottomSheetEnable;
|
||||||
|
|
||||||
|
if (isBottomSheetEnable) {
|
||||||
|
state.copyWith(isBottomSheetEnable: false);
|
||||||
|
} else {
|
||||||
|
state.copyWith(isBottomSheetEnable: true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final homePageStateProvider = StateNotifierProvider<ImageViewerPageStateNotifier, ImageViewerPageState>(
|
||||||
|
((ref) => ImageViewerPageStateNotifier()));
|
||||||
118
mobile/lib/modules/asset_viewer/ui/exif_bottom_sheet.dart
Normal file
118
mobile/lib/modules/asset_viewer/ui/exif_bottom_sheet.dart
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset_with_exif.model.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
|
class ExifBottomSheet extends ConsumerWidget {
|
||||||
|
final ImmichAssetWithExif assetDetail;
|
||||||
|
|
||||||
|
const ExifBottomSheet({Key? key, required this.assetDetail}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 16.0, horizontal: 8),
|
||||||
|
child: ListView(
|
||||||
|
children: [
|
||||||
|
assetDetail.exifInfo?.dateTimeOriginal != null
|
||||||
|
? Text(
|
||||||
|
DateFormat('E, LLL d, y • h:mm a').format(
|
||||||
|
DateTime.parse(assetDetail.exifInfo!.dateTimeOriginal!),
|
||||||
|
),
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[400],
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 14,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 16.0),
|
||||||
|
child: Text(
|
||||||
|
"Add Description...",
|
||||||
|
style: TextStyle(
|
||||||
|
color: Colors.grey[500],
|
||||||
|
fontSize: 11,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
|
||||||
|
// Location
|
||||||
|
assetDetail.exifInfo?.latitude != null
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 32.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Divider(
|
||||||
|
thickness: 1,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"LOCATION",
|
||||||
|
style: TextStyle(fontSize: 11, color: Colors.grey[400]),
|
||||||
|
),
|
||||||
|
Text(
|
||||||
|
"${assetDetail.exifInfo!.latitude!.toStringAsFixed(4)}, ${assetDetail.exifInfo!.longitude!.toStringAsFixed(4)}",
|
||||||
|
style: TextStyle(fontSize: 11, color: Colors.grey[400]),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(),
|
||||||
|
// Detail
|
||||||
|
assetDetail.exifInfo != null
|
||||||
|
? Padding(
|
||||||
|
padding: const EdgeInsets.only(top: 32.0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Divider(
|
||||||
|
thickness: 1,
|
||||||
|
color: Colors.grey[600],
|
||||||
|
),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 8.0),
|
||||||
|
child: Text(
|
||||||
|
"DETAILS",
|
||||||
|
style: TextStyle(fontSize: 11, color: Colors.grey[400]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
contentPadding: const EdgeInsets.all(0),
|
||||||
|
dense: true,
|
||||||
|
textColor: Colors.grey[300],
|
||||||
|
iconColor: Colors.grey[300],
|
||||||
|
leading: const Icon(Icons.image),
|
||||||
|
title: Text(
|
||||||
|
"${assetDetail.exifInfo?.imageName!}${p.extension(assetDetail.originalPath)}",
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
"${assetDetail.exifInfo?.exifImageHeight!} x ${assetDetail.exifInfo?.exifImageWidth!} ${assetDetail.exifInfo?.fileSizeInByte!}B "),
|
||||||
|
),
|
||||||
|
assetDetail.exifInfo?.make != null
|
||||||
|
? ListTile(
|
||||||
|
contentPadding: const EdgeInsets.all(0),
|
||||||
|
dense: true,
|
||||||
|
textColor: Colors.grey[300],
|
||||||
|
iconColor: Colors.grey[300],
|
||||||
|
leading: const Icon(Icons.camera),
|
||||||
|
title: Text(
|
||||||
|
"${assetDetail.exifInfo?.make} ${assetDetail.exifInfo?.model}",
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
"ƒ/${assetDetail.exifInfo?.fNumber} 1/${(1 / assetDetail.exifInfo!.exposureTime!).toStringAsFixed(0)} ${assetDetail.exifInfo?.focalLength}mm ISO${assetDetail.exifInfo?.iso} "),
|
||||||
|
)
|
||||||
|
: Container()
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container()
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
57
mobile/lib/modules/asset_viewer/ui/top_control_app_bar.dart
Normal file
57
mobile/lib/modules/asset_viewer/ui/top_control_app_bar.dart
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
|
|
||||||
|
class TopControlAppBar extends StatelessWidget with PreferredSizeWidget {
|
||||||
|
const TopControlAppBar({Key? key, required this.asset, required this.onMoreInfoPressed}) : super(key: key);
|
||||||
|
|
||||||
|
final ImmichAsset asset;
|
||||||
|
final Function onMoreInfoPressed;
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
double iconSize = 18.0;
|
||||||
|
|
||||||
|
return AppBar(
|
||||||
|
foregroundColor: Colors.grey[100],
|
||||||
|
toolbarHeight: 60,
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
leading: IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
AutoRouter.of(context).pop();
|
||||||
|
},
|
||||||
|
icon: const Icon(
|
||||||
|
Icons.arrow_back_ios_new_rounded,
|
||||||
|
size: 20.0,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
iconSize: iconSize,
|
||||||
|
splashRadius: iconSize,
|
||||||
|
onPressed: () {
|
||||||
|
print("backup");
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.backup_outlined),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
iconSize: iconSize,
|
||||||
|
splashRadius: iconSize,
|
||||||
|
onPressed: () {
|
||||||
|
print("favorite");
|
||||||
|
},
|
||||||
|
icon: asset.isFavorite ? const Icon(Icons.favorite_rounded) : const Icon(Icons.favorite_border_rounded),
|
||||||
|
),
|
||||||
|
IconButton(
|
||||||
|
iconSize: iconSize,
|
||||||
|
splashRadius: iconSize,
|
||||||
|
onPressed: () {
|
||||||
|
onMoreInfoPressed();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.more_horiz_rounded))
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Size get preferredSize => const Size.fromHeight(kToolbarHeight);
|
||||||
|
}
|
||||||
109
mobile/lib/modules/asset_viewer/views/image_viewer_page.dart
Normal file
109
mobile/lib/modules/asset_viewer/views/image_viewer_page.dart
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/constants/hive_box.dart';
|
||||||
|
import 'package:immich_mobile/modules/asset_viewer/ui/exif_bottom_sheet.dart';
|
||||||
|
import 'package:immich_mobile/modules/asset_viewer/ui/top_control_app_bar.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/services/asset.service.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset_with_exif.model.dart';
|
||||||
|
|
||||||
|
// ignore: must_be_immutable
|
||||||
|
class ImageViewerPage extends HookConsumerWidget {
|
||||||
|
final String imageUrl;
|
||||||
|
final String heroTag;
|
||||||
|
final String thumbnailUrl;
|
||||||
|
final ImmichAsset asset;
|
||||||
|
final AssetService _assetService = AssetService();
|
||||||
|
ImmichAssetWithExif? assetDetail;
|
||||||
|
|
||||||
|
ImageViewerPage(
|
||||||
|
{Key? key, required this.imageUrl, required this.heroTag, required this.thumbnailUrl, required this.asset})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
var box = Hive.box(userInfoBox);
|
||||||
|
|
||||||
|
getAssetExif() async {
|
||||||
|
assetDetail = await _assetService.getAssetById(asset.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() {
|
||||||
|
getAssetExif();
|
||||||
|
return null;
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
appBar: TopControlAppBar(
|
||||||
|
asset: asset,
|
||||||
|
onMoreInfoPressed: () {
|
||||||
|
showModalBottomSheet(
|
||||||
|
backgroundColor: Colors.black,
|
||||||
|
barrierColor: Colors.transparent,
|
||||||
|
isScrollControlled: false,
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return ExifBottomSheet(assetDetail: assetDetail!);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
body: Center(
|
||||||
|
child: Hero(
|
||||||
|
tag: heroTag,
|
||||||
|
child: CachedNetworkImage(
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
imageUrl: imageUrl,
|
||||||
|
httpHeaders: {"Authorization": "Bearer ${box.get(accessTokenKey)}"},
|
||||||
|
fadeInDuration: const Duration(milliseconds: 250),
|
||||||
|
errorWidget: (context, url, error) => ConstrainedBox(
|
||||||
|
constraints: const BoxConstraints(maxWidth: 300),
|
||||||
|
child: Wrap(
|
||||||
|
spacing: 32,
|
||||||
|
runSpacing: 32,
|
||||||
|
alignment: WrapAlignment.center,
|
||||||
|
children: [
|
||||||
|
const Text(
|
||||||
|
"Failed To Render Image - Possibly Corrupted Data",
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(fontSize: 16, color: Colors.white),
|
||||||
|
),
|
||||||
|
SingleChildScrollView(
|
||||||
|
child: Text(
|
||||||
|
error.toString(),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: TextStyle(fontSize: 12, color: Colors.grey[400]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// imageBuilder: (context, imageProvider) {
|
||||||
|
// return PhotoView(imageProvider: imageProvider);
|
||||||
|
// },
|
||||||
|
placeholder: (context, url) {
|
||||||
|
return CachedNetworkImage(
|
||||||
|
cacheKey: thumbnailUrl,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
imageUrl: thumbnailUrl,
|
||||||
|
httpHeaders: {"Authorization": "Bearer ${box.get(accessTokenKey)}"},
|
||||||
|
placeholderFadeInDuration: const Duration(milliseconds: 0),
|
||||||
|
progressIndicatorBuilder: (context, url, downloadProgress) => Transform.scale(
|
||||||
|
scale: 0.2,
|
||||||
|
child: CircularProgressIndicator(value: downloadProgress.progress),
|
||||||
|
),
|
||||||
|
errorWidget: (context, url, error) => Icon(
|
||||||
|
Icons.error,
|
||||||
|
color: Colors.grey[300],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class DeleteAssetResponse {
|
||||||
|
final String id;
|
||||||
|
final String status;
|
||||||
|
|
||||||
|
DeleteAssetResponse({
|
||||||
|
required this.id,
|
||||||
|
required this.status,
|
||||||
|
});
|
||||||
|
|
||||||
|
DeleteAssetResponse copyWith({
|
||||||
|
String? id,
|
||||||
|
String? status,
|
||||||
|
}) {
|
||||||
|
return DeleteAssetResponse(
|
||||||
|
id: id ?? this.id,
|
||||||
|
status: status ?? this.status,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'status': status,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory DeleteAssetResponse.fromMap(Map<String, dynamic> map) {
|
||||||
|
return DeleteAssetResponse(
|
||||||
|
id: map['id'] ?? '',
|
||||||
|
status: map['status'] ?? '',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
factory DeleteAssetResponse.fromJson(String source) => DeleteAssetResponse.fromMap(json.decode(source));
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => 'DeleteAssetResponse(id: $id, status: $status)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is DeleteAssetResponse && other.id == id && other.status == status;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => id.hashCode ^ status.hashCode;
|
||||||
|
}
|
||||||
@@ -1,99 +1,74 @@
|
|||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/modules/home/models/get_all_asset_respose.model.dart';
|
import 'package:immich_mobile/modules/home/models/delete_asset_response.model.dart';
|
||||||
import 'package:immich_mobile/modules/home/services/asset.service.dart';
|
import 'package:immich_mobile/modules/home/services/asset.service.dart';
|
||||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:immich_mobile/shared/services/device_info.service.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
|
import 'package:intl/intl.dart';
|
||||||
|
import 'package:photo_manager/photo_manager.dart';
|
||||||
|
|
||||||
class AssetNotifier extends StateNotifier<List<ImmichAssetGroupByDate>> {
|
class AssetNotifier extends StateNotifier<List<ImmichAsset>> {
|
||||||
final AssetService _assetService = AssetService();
|
final AssetService _assetService = AssetService();
|
||||||
|
final DeviceInfoService _deviceInfoService = DeviceInfoService();
|
||||||
|
final Ref ref;
|
||||||
|
|
||||||
AssetNotifier() : super([]);
|
AssetNotifier(this.ref) : super([]);
|
||||||
|
|
||||||
late String? nextPageKey = "";
|
getAllAsset() async {
|
||||||
bool isFetching = false;
|
List<ImmichAsset>? allAssets = await _assetService.getAllAsset();
|
||||||
|
|
||||||
// Get All assets
|
if (allAssets != null) {
|
||||||
getImmichAssets() async {
|
state = allAssets;
|
||||||
GetAllAssetResponse? res = await _assetService.getAllAsset();
|
|
||||||
nextPageKey = res?.nextPageKey;
|
|
||||||
|
|
||||||
if (res != null) {
|
|
||||||
for (var assets in res.data) {
|
|
||||||
state = [...state, assets];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get Asset From The Past
|
|
||||||
getOlderAsset() async {
|
|
||||||
if (nextPageKey != null && !isFetching) {
|
|
||||||
isFetching = true;
|
|
||||||
GetAllAssetResponse? res = await _assetService.getOlderAsset(nextPageKey);
|
|
||||||
|
|
||||||
if (res != null) {
|
|
||||||
nextPageKey = res.nextPageKey;
|
|
||||||
|
|
||||||
List<ImmichAssetGroupByDate> previousState = state;
|
|
||||||
List<ImmichAssetGroupByDate> currentState = [];
|
|
||||||
|
|
||||||
for (var assets in res.data) {
|
|
||||||
currentState = [...currentState, assets];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (previousState.last.date == currentState.first.date) {
|
|
||||||
previousState.last.assets = [...previousState.last.assets, ...currentState.first.assets];
|
|
||||||
state = [...previousState, ...currentState.sublist(1)];
|
|
||||||
} else {
|
|
||||||
state = [...previousState, ...currentState];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
isFetching = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get newer asset from the current time
|
|
||||||
getNewAsset() async {
|
|
||||||
if (state.isNotEmpty) {
|
|
||||||
var latestGroup = state.first;
|
|
||||||
|
|
||||||
// Sort the last asset group and put the lastest asset in front.
|
|
||||||
latestGroup.assets.sortByCompare<DateTime>((e) => DateTime.parse(e.createdAt), (a, b) => b.compareTo(a));
|
|
||||||
var latestAsset = latestGroup.assets.first;
|
|
||||||
var formatDateTemplate = 'y-MM-dd';
|
|
||||||
var latestAssetDateText = DateFormat(formatDateTemplate).format(DateTime.parse(latestAsset.createdAt));
|
|
||||||
|
|
||||||
List<ImmichAsset> newAssets = await _assetService.getNewAsset(latestAsset.createdAt);
|
|
||||||
|
|
||||||
if (newAssets.isEmpty) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grouping by data
|
|
||||||
var groupByDateList = groupBy<ImmichAsset, String>(
|
|
||||||
newAssets, (asset) => DateFormat(formatDateTemplate).format(DateTime.parse(asset.createdAt)));
|
|
||||||
|
|
||||||
groupByDateList.forEach((groupDateInFormattedText, assets) {
|
|
||||||
if (groupDateInFormattedText != latestAssetDateText) {
|
|
||||||
ImmichAssetGroupByDate newGroup = ImmichAssetGroupByDate(assets: assets, date: groupDateInFormattedText);
|
|
||||||
state = [newGroup, ...state];
|
|
||||||
} else {
|
|
||||||
latestGroup.assets.insertAll(0, assets);
|
|
||||||
|
|
||||||
state = [latestGroup, ...state.sublist(1)];
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
clearAllAsset() {
|
clearAllAsset() {
|
||||||
state = [];
|
state = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onNewAssetUploaded(ImmichAsset newAsset) {
|
||||||
|
state = [...state, newAsset];
|
||||||
|
}
|
||||||
|
|
||||||
|
deleteAssets(Set<ImmichAsset> deleteAssets) async {
|
||||||
|
var deviceInfo = await _deviceInfoService.getDeviceInfo();
|
||||||
|
var deviceId = deviceInfo["deviceId"];
|
||||||
|
List<String> deleteIdList = [];
|
||||||
|
// Delete asset from device
|
||||||
|
for (var asset in deleteAssets) {
|
||||||
|
// Delete asset on device if present
|
||||||
|
if (asset.deviceId == deviceId) {
|
||||||
|
AssetEntity? localAsset = await AssetEntity.fromId(asset.deviceAssetId);
|
||||||
|
|
||||||
|
if (localAsset != null) {
|
||||||
|
deleteIdList.add(localAsset.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final List<String> result = await PhotoManager.editor.deleteWithIds(deleteIdList);
|
||||||
|
|
||||||
|
// Delete asset on server
|
||||||
|
List<DeleteAssetResponse>? deleteAssetResult = await _assetService.deleteAssets(deleteAssets);
|
||||||
|
if (deleteAssetResult == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var asset in deleteAssetResult) {
|
||||||
|
if (asset.status == 'success') {
|
||||||
|
state = state.where((immichAsset) => immichAsset.id != asset.id).toList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final currentLocalPageProvider = StateProvider<int>((ref) => 0);
|
final assetProvider = StateNotifierProvider<AssetNotifier, List<ImmichAsset>>((ref) {
|
||||||
|
return AssetNotifier(ref);
|
||||||
final assetProvider = StateNotifierProvider<AssetNotifier, List<ImmichAssetGroupByDate>>((ref) {
|
});
|
||||||
return AssetNotifier();
|
|
||||||
|
final assetGroupByDateTimeProvider = StateProvider((ref) {
|
||||||
|
var assets = ref.watch(assetProvider);
|
||||||
|
|
||||||
|
assets.sortByCompare<DateTime>((e) => DateTime.parse(e.createdAt), (a, b) => b.compareTo(a));
|
||||||
|
return assets.groupListsBy((element) => DateFormat('y-MM-dd').format(DateTime.parse(element.createdAt)));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,29 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:immich_mobile/modules/home/models/get_all_asset_respose.model.dart';
|
import 'package:immich_mobile/modules/home/models/delete_asset_response.model.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/models/get_all_asset_response.model.dart';
|
||||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset_with_exif.model.dart';
|
||||||
import 'package:immich_mobile/shared/services/network.service.dart';
|
import 'package:immich_mobile/shared/services/network.service.dart';
|
||||||
|
|
||||||
class AssetService {
|
class AssetService {
|
||||||
final NetworkService _networkService = NetworkService();
|
final NetworkService _networkService = NetworkService();
|
||||||
|
|
||||||
Future<GetAllAssetResponse?> getAllAsset() async {
|
Future<List<ImmichAsset>?> getAllAsset() async {
|
||||||
|
var res = await _networkService.getRequest(url: "asset/");
|
||||||
|
try {
|
||||||
|
List<dynamic> decodedData = jsonDecode(res.toString());
|
||||||
|
|
||||||
|
List<ImmichAsset> result = List.from(decodedData.map((a) => ImmichAsset.fromMap(a)));
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Error getAllAsset ${e.toString()}");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<GetAllAssetResponse?> getAllAssetWithPagination() async {
|
||||||
var res = await _networkService.getRequest(url: "asset/all");
|
var res = await _networkService.getRequest(url: "asset/all");
|
||||||
try {
|
try {
|
||||||
Map<String, dynamic> decodedData = jsonDecode(res.toString());
|
Map<String, dynamic> decodedData = jsonDecode(res.toString());
|
||||||
@@ -58,4 +73,41 @@ class AssetService {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<ImmichAssetWithExif?> getAssetById(String assetId) async {
|
||||||
|
try {
|
||||||
|
var res = await _networkService.getRequest(
|
||||||
|
url: "asset/assetById/$assetId",
|
||||||
|
);
|
||||||
|
|
||||||
|
Map<String, dynamic> decodedData = jsonDecode(res.toString());
|
||||||
|
|
||||||
|
ImmichAssetWithExif result = ImmichAssetWithExif.fromMap(decodedData);
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Error getAllAsset ${e.toString()}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<DeleteAssetResponse>?> deleteAssets(Set<ImmichAsset> deleteAssets) async {
|
||||||
|
try {
|
||||||
|
var payload = [];
|
||||||
|
|
||||||
|
for (var asset in deleteAssets) {
|
||||||
|
payload.add(asset.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
var res = await _networkService.deleteRequest(url: "asset/", data: {"ids": payload});
|
||||||
|
|
||||||
|
List<dynamic> decodedData = jsonDecode(res.toString());
|
||||||
|
|
||||||
|
List<DeleteAssetResponse> result = List.from(decodedData.map((a) => DeleteAssetResponse.fromMap(a)));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("Error getAllAsset ${e.toString()}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
75
mobile/lib/modules/home/ui/control_bottom_app_bar.dart
Normal file
75
mobile/lib/modules/home/ui/control_bottom_app_bar.dart
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/ui/delete_diaglog.dart';
|
||||||
|
|
||||||
|
class ControlBottomAppBar extends StatelessWidget {
|
||||||
|
const ControlBottomAppBar({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Positioned(
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
child: Container(
|
||||||
|
width: MediaQuery.of(context).size.width,
|
||||||
|
height: MediaQuery.of(context).size.height * 0.15,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: const BorderRadius.only(topLeft: Radius.circular(15), topRight: Radius.circular(15)),
|
||||||
|
color: Colors.grey[300]?.withOpacity(0.98),
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(vertical: 10, horizontal: 20),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
ControlBoxButton(
|
||||||
|
iconData: Icons.delete_forever_rounded,
|
||||||
|
label: "Delete",
|
||||||
|
onPressed: () {
|
||||||
|
showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (BuildContext context) {
|
||||||
|
return const DeleteDialog();
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ControlBoxButton extends StatelessWidget {
|
||||||
|
const ControlBoxButton({Key? key, required this.label, required this.iconData, required this.onPressed})
|
||||||
|
: super(key: key);
|
||||||
|
|
||||||
|
final String label;
|
||||||
|
final IconData iconData;
|
||||||
|
final Function onPressed;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return SizedBox(
|
||||||
|
width: 60,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
IconButton(
|
||||||
|
onPressed: () {
|
||||||
|
onPressed();
|
||||||
|
},
|
||||||
|
icon: Icon(iconData, size: 30),
|
||||||
|
),
|
||||||
|
Text(label)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,6 +24,31 @@ class DailyTitleText extends ConsumerWidget {
|
|||||||
var selectedDateGroup = ref.watch(homePageStateProvider).selectedDateGroup;
|
var selectedDateGroup = ref.watch(homePageStateProvider).selectedDateGroup;
|
||||||
var selectedItems = ref.watch(homePageStateProvider).selectedItems;
|
var selectedItems = ref.watch(homePageStateProvider).selectedItems;
|
||||||
|
|
||||||
|
void _handleTitleIconClick() {
|
||||||
|
if (isMultiSelectEnable &&
|
||||||
|
selectedDateGroup.contains(dateText) &&
|
||||||
|
selectedDateGroup.length == 1 &&
|
||||||
|
selectedItems.length <= assetGroup.length) {
|
||||||
|
// Multi select is active - click again on the icon while it is the only active group -> disable multi select
|
||||||
|
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
||||||
|
} else if (isMultiSelectEnable &&
|
||||||
|
selectedDateGroup.contains(dateText) &&
|
||||||
|
selectedItems.length != assetGroup.length) {
|
||||||
|
// Multi select is active - click again on the icon while it is not the only active group -> remove that group from selected group/items
|
||||||
|
ref.watch(homePageStateProvider.notifier).removeSelectedDateGroup(dateText);
|
||||||
|
ref.watch(homePageStateProvider.notifier).removeMultipleSelectedItem(assetGroup);
|
||||||
|
} else if (isMultiSelectEnable && selectedDateGroup.contains(dateText) && selectedDateGroup.length > 1) {
|
||||||
|
ref.watch(homePageStateProvider.notifier).removeSelectedDateGroup(dateText);
|
||||||
|
ref.watch(homePageStateProvider.notifier).removeMultipleSelectedItem(assetGroup);
|
||||||
|
} else if (isMultiSelectEnable && !selectedDateGroup.contains(dateText)) {
|
||||||
|
ref.watch(homePageStateProvider.notifier).addSelectedDateGroup(dateText);
|
||||||
|
ref.watch(homePageStateProvider.notifier).addMultipleSelectedItems(assetGroup);
|
||||||
|
} else {
|
||||||
|
ref.watch(homePageStateProvider.notifier).enableMultiSelect(assetGroup.toSet());
|
||||||
|
ref.watch(homePageStateProvider.notifier).addSelectedDateGroup(dateText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return SliverToBoxAdapter(
|
return SliverToBoxAdapter(
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.only(top: 29.0, bottom: 29.0, left: 12.0, right: 12.0),
|
padding: const EdgeInsets.only(top: 29.0, bottom: 29.0, left: 12.0, right: 12.0),
|
||||||
@@ -39,33 +64,16 @@ class DailyTitleText extends ConsumerWidget {
|
|||||||
),
|
),
|
||||||
const Spacer(),
|
const Spacer(),
|
||||||
GestureDetector(
|
GestureDetector(
|
||||||
onTap: () {
|
onTap: _handleTitleIconClick,
|
||||||
if (isMultiSelectEnable &&
|
|
||||||
selectedDateGroup.contains(dateText) &&
|
|
||||||
selectedDateGroup.length == 1 &&
|
|
||||||
selectedItems.length == assetGroup.length) {
|
|
||||||
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
|
||||||
} else if (isMultiSelectEnable &&
|
|
||||||
selectedDateGroup.contains(dateText) &&
|
|
||||||
selectedItems.length != assetGroup.length) {
|
|
||||||
ref.watch(homePageStateProvider.notifier).removeSelectedDateGroup(dateText);
|
|
||||||
ref.watch(homePageStateProvider.notifier).removeMultipleSelectedItem(assetGroup);
|
|
||||||
} else if (isMultiSelectEnable &&
|
|
||||||
selectedDateGroup.contains(dateText) &&
|
|
||||||
selectedDateGroup.length > 1) {
|
|
||||||
ref.watch(homePageStateProvider.notifier).removeSelectedDateGroup(dateText);
|
|
||||||
ref.watch(homePageStateProvider.notifier).removeMultipleSelectedItem(assetGroup);
|
|
||||||
} else if (isMultiSelectEnable && !selectedDateGroup.contains(dateText)) {
|
|
||||||
ref.watch(homePageStateProvider.notifier).addSelectedDateGroup(dateText);
|
|
||||||
ref.watch(homePageStateProvider.notifier).addMultipleSelectedItems(assetGroup);
|
|
||||||
} else {
|
|
||||||
ref.watch(homePageStateProvider.notifier).enableMultiSelect(assetGroup.toSet());
|
|
||||||
ref.watch(homePageStateProvider.notifier).addSelectedDateGroup(dateText);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: isMultiSelectEnable && selectedDateGroup.contains(dateText)
|
child: isMultiSelectEnable && selectedDateGroup.contains(dateText)
|
||||||
? const Icon(Icons.check_circle_rounded)
|
? Icon(
|
||||||
: const Icon(Icons.check_circle_outline_rounded),
|
Icons.check_circle_rounded,
|
||||||
|
color: Theme.of(context).primaryColor,
|
||||||
|
)
|
||||||
|
: const Icon(
|
||||||
|
Icons.check_circle_outline_rounded,
|
||||||
|
color: Colors.grey,
|
||||||
|
),
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
|||||||
43
mobile/lib/modules/home/ui/delete_diaglog.dart
Normal file
43
mobile/lib/modules/home/ui/delete_diaglog.dart
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
||||||
|
|
||||||
|
class DeleteDialog extends ConsumerWidget {
|
||||||
|
const DeleteDialog({Key? key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
final homePageState = ref.watch(homePageStateProvider);
|
||||||
|
|
||||||
|
return AlertDialog(
|
||||||
|
backgroundColor: Colors.grey[200],
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
|
||||||
|
title: const Text("Delete Permanently"),
|
||||||
|
content: const Text("These items will be permanently deleted from Immich and from your device"),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: const Text(
|
||||||
|
"Cancel",
|
||||||
|
style: TextStyle(color: Colors.blueGrey),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
ref.watch(assetProvider.notifier).deleteAssets(homePageState.selectedItems);
|
||||||
|
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
||||||
|
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
},
|
||||||
|
child: Text(
|
||||||
|
"Delete",
|
||||||
|
style: TextStyle(color: Colors.red[400]),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
47
mobile/lib/modules/home/ui/disable_multi_select_button.dart
Normal file
47
mobile/lib/modules/home/ui/disable_multi_select_button.dart
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
||||||
|
|
||||||
|
class DisableMultiSelectButton extends ConsumerWidget {
|
||||||
|
const DisableMultiSelectButton({
|
||||||
|
Key? key,
|
||||||
|
required this.onPressed,
|
||||||
|
required this.selectedItemCount,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
final Function onPressed;
|
||||||
|
final int selectedItemCount;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
|
return Positioned(
|
||||||
|
top: 0,
|
||||||
|
left: 0,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 16.0, top: 46),
|
||||||
|
child: Material(
|
||||||
|
elevation: 20,
|
||||||
|
borderRadius: BorderRadius.circular(35),
|
||||||
|
child: Container(
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(35),
|
||||||
|
color: Colors.grey[100],
|
||||||
|
),
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 4.0),
|
||||||
|
child: TextButton.icon(
|
||||||
|
onPressed: () {
|
||||||
|
onPressed();
|
||||||
|
},
|
||||||
|
icon: const Icon(Icons.close_rounded),
|
||||||
|
label: Text(
|
||||||
|
selectedItemCount.toString(),
|
||||||
|
style: const TextStyle(fontWeight: FontWeight.w600, fontSize: 18),
|
||||||
|
)),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
|
import 'package:badges/badges.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:google_fonts/google_fonts.dart';
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
||||||
|
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
import 'package:immich_mobile/shared/models/backup_state.model.dart';
|
import 'package:immich_mobile/shared/models/backup_state.model.dart';
|
||||||
@@ -20,79 +22,89 @@ class ImmichSliverAppBar extends ConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final BackUpState _backupState = ref.watch(backupProvider);
|
final BackUpState _backupState = ref.watch(backupProvider);
|
||||||
|
bool _isEnableAutoBackup = ref.watch(authenticationProvider).deviceInfo.isAutoBackup;
|
||||||
return SliverPadding(
|
return SliverAppBar(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 5, vertical: 5),
|
centerTitle: true,
|
||||||
sliver: SliverAppBar(
|
floating: true,
|
||||||
centerTitle: true,
|
pinned: false,
|
||||||
floating: true,
|
snap: false,
|
||||||
pinned: false,
|
backgroundColor: Colors.grey[200],
|
||||||
snap: false,
|
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5))),
|
||||||
backgroundColor: Colors.grey[200],
|
leading: Builder(
|
||||||
shape: const RoundedRectangleBorder(borderRadius: BorderRadius.all(Radius.circular(5))),
|
builder: (BuildContext context) {
|
||||||
leading: Builder(
|
return IconButton(
|
||||||
builder: (BuildContext context) {
|
icon: const Icon(Icons.account_circle_rounded),
|
||||||
return IconButton(
|
onPressed: () {
|
||||||
icon: const Icon(Icons.account_circle_rounded),
|
Scaffold.of(context).openDrawer();
|
||||||
onPressed: () {
|
},
|
||||||
Scaffold.of(context).openDrawer();
|
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
|
||||||
},
|
);
|
||||||
tooltip: MaterialLocalizations.of(context).openAppDrawerTooltip,
|
},
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
title: Text(
|
|
||||||
'IMMICH',
|
|
||||||
style: GoogleFonts.snowburstOne(
|
|
||||||
textStyle: TextStyle(
|
|
||||||
fontWeight: FontWeight.bold,
|
|
||||||
fontSize: 18,
|
|
||||||
color: Theme.of(context).primaryColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
Stack(
|
|
||||||
alignment: AlignmentDirectional.center,
|
|
||||||
children: [
|
|
||||||
_backupState.backupProgress == BackUpProgressEnum.inProgress
|
|
||||||
? Positioned(
|
|
||||||
top: 10,
|
|
||||||
right: 12,
|
|
||||||
child: SizedBox(
|
|
||||||
height: 8,
|
|
||||||
width: 8,
|
|
||||||
child: CircularProgressIndicator(
|
|
||||||
strokeWidth: 1,
|
|
||||||
valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).primaryColor),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Container(),
|
|
||||||
IconButton(
|
|
||||||
icon: const Icon(Icons.backup_rounded),
|
|
||||||
tooltip: 'Backup Controller',
|
|
||||||
onPressed: () async {
|
|
||||||
var onPop = await AutoRouter.of(context).push(const BackupControllerRoute());
|
|
||||||
|
|
||||||
if (onPop == true) {
|
|
||||||
onPopBack!();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
_backupState.backupProgress == BackUpProgressEnum.inProgress
|
|
||||||
? Positioned(
|
|
||||||
bottom: 5,
|
|
||||||
child: Text(
|
|
||||||
_backupState.backingUpAssetCount.toString(),
|
|
||||||
style: const TextStyle(fontSize: 9, fontWeight: FontWeight.bold),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: Container()
|
|
||||||
],
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
|
title: Text(
|
||||||
|
'IMMICH',
|
||||||
|
style: GoogleFonts.snowburstOne(
|
||||||
|
textStyle: TextStyle(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
fontSize: 18,
|
||||||
|
color: Theme.of(context).primaryColor,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
Stack(
|
||||||
|
alignment: AlignmentDirectional.center,
|
||||||
|
children: [
|
||||||
|
_backupState.backupProgress == BackUpProgressEnum.inProgress
|
||||||
|
? Positioned(
|
||||||
|
top: 10,
|
||||||
|
right: 12,
|
||||||
|
child: SizedBox(
|
||||||
|
height: 8,
|
||||||
|
width: 8,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 1,
|
||||||
|
valueColor: AlwaysStoppedAnimation<Color>(Theme.of(context).primaryColor),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container(),
|
||||||
|
IconButton(
|
||||||
|
splashRadius: 25,
|
||||||
|
iconSize: 30,
|
||||||
|
icon: _isEnableAutoBackup
|
||||||
|
? const Icon(Icons.backup_rounded)
|
||||||
|
: Badge(
|
||||||
|
padding: const EdgeInsets.all(4),
|
||||||
|
elevation: 1,
|
||||||
|
position: BadgePosition.bottomEnd(bottom: -4, end: -4),
|
||||||
|
badgeColor: Colors.white,
|
||||||
|
badgeContent: const Icon(
|
||||||
|
Icons.cloud_off_rounded,
|
||||||
|
size: 8,
|
||||||
|
),
|
||||||
|
child: const Icon(Icons.backup_rounded)),
|
||||||
|
tooltip: 'Backup Controller',
|
||||||
|
onPressed: () async {
|
||||||
|
var onPop = await AutoRouter.of(context).push(const BackupControllerRoute());
|
||||||
|
|
||||||
|
if (onPop == true) {
|
||||||
|
onPopBack!();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
),
|
||||||
|
_backupState.backupProgress == BackUpProgressEnum.inProgress
|
||||||
|
? Positioned(
|
||||||
|
bottom: 5,
|
||||||
|
child: Text(
|
||||||
|
_backupState.backingUpAssetCount.toString(),
|
||||||
|
style: const TextStyle(fontSize: 9, fontWeight: FontWeight.bold),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Container()
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|||||||
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
||||||
import 'package:immich_mobile/modules/login/models/authentication_state.model.dart';
|
import 'package:immich_mobile/modules/login/models/authentication_state.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/backup.provider.dart';
|
||||||
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
||||||
|
|
||||||
class ProfileDrawer extends ConsumerWidget {
|
class ProfileDrawer extends ConsumerWidget {
|
||||||
const ProfileDrawer({Key? key}) : super(key: key);
|
const ProfileDrawer({Key? key}) : super(key: key);
|
||||||
@@ -57,8 +59,10 @@ class ProfileDrawer extends ConsumerWidget {
|
|||||||
bool res = await ref.read(authenticationProvider.notifier).logout();
|
bool res = await ref.read(authenticationProvider.notifier).logout();
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
|
ref.watch(backupProvider.notifier).cancelBackup();
|
||||||
|
ref.watch(assetProvider.notifier).clearAllAsset();
|
||||||
|
ref.watch(websocketProvider.notifier).disconnect();
|
||||||
AutoRouter.of(context).popUntilRoot();
|
AutoRouter.of(context).popUntilRoot();
|
||||||
ref.read(assetProvider.notifier).clearAllAsset();
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ 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/hive_box.dart';
|
import 'package:immich_mobile/constants/hive_box.dart';
|
||||||
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
||||||
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
||||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
import 'package:immich_mobile/routing/router.dart';
|
import 'package:immich_mobile/routing/router.dart';
|
||||||
|
|
||||||
@@ -25,6 +26,7 @@ class ThumbnailImage extends HookConsumerWidget {
|
|||||||
|
|
||||||
var selectedAsset = ref.watch(homePageStateProvider).selectedItems;
|
var selectedAsset = ref.watch(homePageStateProvider).selectedItems;
|
||||||
var isMultiSelectEnable = ref.watch(homePageStateProvider).isMultiSelectEnable;
|
var isMultiSelectEnable = ref.watch(homePageStateProvider).isMultiSelectEnable;
|
||||||
|
var deviceId = ref.watch(authenticationProvider).deviceId;
|
||||||
|
|
||||||
Widget _buildSelectionIcon(ImmichAsset asset) {
|
Widget _buildSelectionIcon(ImmichAsset asset) {
|
||||||
if (selectedAsset.contains(asset)) {
|
if (selectedAsset.contains(asset)) {
|
||||||
@@ -42,6 +44,7 @@ class ThumbnailImage extends HookConsumerWidget {
|
|||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
debugPrint("View ${asset.id}");
|
||||||
if (isMultiSelectEnable && selectedAsset.contains(asset) && selectedAsset.length == 1) {
|
if (isMultiSelectEnable && selectedAsset.contains(asset) && selectedAsset.length == 1) {
|
||||||
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
ref.watch(homePageStateProvider.notifier).disableMultiSelect();
|
||||||
} else if (isMultiSelectEnable && selectedAsset.contains(asset) && selectedAsset.length > 1) {
|
} else if (isMultiSelectEnable && selectedAsset.contains(asset) && selectedAsset.length > 1) {
|
||||||
@@ -56,6 +59,7 @@ class ThumbnailImage extends HookConsumerWidget {
|
|||||||
'${box.get(serverEndpointKey)}/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}&isThumb=false',
|
'${box.get(serverEndpointKey)}/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}&isThumb=false',
|
||||||
heroTag: asset.id,
|
heroTag: asset.id,
|
||||||
thumbnailUrl: thumbnailRequestUrl,
|
thumbnailUrl: thumbnailRequestUrl,
|
||||||
|
asset: asset,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
@@ -98,9 +102,10 @@ class ThumbnailImage extends HookConsumerWidget {
|
|||||||
child: CircularProgressIndicator(value: downloadProgress.progress),
|
child: CircularProgressIndicator(value: downloadProgress.progress),
|
||||||
),
|
),
|
||||||
errorWidget: (context, url, error) {
|
errorWidget: (context, url, error) {
|
||||||
debugPrint("Error Loading Thumbnail Widget $error");
|
return Icon(
|
||||||
cacheKey.value += 1;
|
Icons.image_not_supported_outlined,
|
||||||
return const Icon(Icons.error);
|
color: Theme.of(context).primaryColor,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@@ -115,6 +120,15 @@ class ThumbnailImage extends HookConsumerWidget {
|
|||||||
)
|
)
|
||||||
: Container(),
|
: Container(),
|
||||||
),
|
),
|
||||||
|
Positioned(
|
||||||
|
right: 10,
|
||||||
|
bottom: 5,
|
||||||
|
child: Icon(
|
||||||
|
(deviceId != asset.deviceId) ? Icons.cloud_done_outlined : Icons.photo_library_rounded,
|
||||||
|
color: Colors.white,
|
||||||
|
size: 18,
|
||||||
|
),
|
||||||
|
)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,14 +1,18 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/providers/home_page_state.provider.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/ui/control_bottom_app_bar.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/daily_title_text.dart';
|
import 'package:immich_mobile/modules/home/ui/daily_title_text.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/ui/disable_multi_select_button.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/draggable_scrollbar.dart';
|
import 'package:immich_mobile/modules/home/ui/draggable_scrollbar.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/image_grid.dart';
|
import 'package:immich_mobile/modules/home/ui/image_grid.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/immich_sliver_appbar.dart';
|
import 'package:immich_mobile/modules/home/ui/immich_sliver_appbar.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/monthly_title_text.dart';
|
import 'package:immich_mobile/modules/home/ui/monthly_title_text.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/profile_drawer.dart';
|
import 'package:immich_mobile/modules/home/ui/profile_drawer.dart';
|
||||||
import 'package:immich_mobile/modules/home/models/get_all_asset_respose.model.dart';
|
|
||||||
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
||||||
|
import 'package:immich_mobile/shared/providers/websocket.provider.dart';
|
||||||
|
import 'package:sliver_tools/sliver_tools.dart';
|
||||||
|
|
||||||
class HomePage extends HookConsumerWidget {
|
class HomePage extends HookConsumerWidget {
|
||||||
const HomePage({Key? key}) : super(key: key);
|
const HomePage({Key? key}) : super(key: key);
|
||||||
@@ -16,94 +20,98 @@ class HomePage extends HookConsumerWidget {
|
|||||||
@override
|
@override
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
ScrollController _scrollController = useScrollController();
|
ScrollController _scrollController = useScrollController();
|
||||||
List<ImmichAssetGroupByDate> _assetGroup = ref.watch(assetProvider);
|
var assetGroupByDateTime = ref.watch(assetGroupByDateTimeProvider);
|
||||||
List<Widget> _imageGridGroup = [];
|
List<Widget> _imageGridGroup = [];
|
||||||
|
var isMultiSelectEnable = ref.watch(homePageStateProvider).isMultiSelectEnable;
|
||||||
_scrollControllerCallback() {
|
var homePageState = ref.watch(homePageStateProvider);
|
||||||
var endOfPage = _scrollController.position.maxScrollExtent;
|
|
||||||
|
|
||||||
if (_scrollController.offset >= endOfPage - (endOfPage * 0.1) && !_scrollController.position.outOfRange) {
|
|
||||||
ref.read(assetProvider.notifier).getOlderAsset();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() {
|
useEffect(() {
|
||||||
ref.read(assetProvider.notifier).getImmichAssets();
|
ref.read(websocketProvider.notifier).connect();
|
||||||
|
ref.read(assetProvider.notifier).getAllAsset();
|
||||||
_scrollController.addListener(_scrollControllerCallback);
|
return null;
|
||||||
|
|
||||||
return () {
|
|
||||||
_scrollController.removeListener(_scrollControllerCallback);
|
|
||||||
};
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
onPopBackFromBackupPage() {
|
onPopBackFromBackupPage() {
|
||||||
ref.read(assetProvider.notifier).getNewAsset();
|
// ref.read(assetProvider.notifier).getAllAsset();
|
||||||
// Remove and force getting new widget again if there is not many widget on screen.
|
|
||||||
// Otherwise do nothing.
|
|
||||||
|
|
||||||
if (_imageGridGroup.isNotEmpty && _imageGridGroup.length < 20) {
|
|
||||||
ref.read(assetProvider.notifier).getOlderAsset();
|
|
||||||
} else if (_imageGridGroup.isEmpty) {
|
|
||||||
ref.read(assetProvider.notifier).getImmichAssets();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildBody() {
|
Widget _buildBody() {
|
||||||
if (_assetGroup.isNotEmpty) {
|
if (assetGroupByDateTime.isNotEmpty) {
|
||||||
String lastGroupDate = _assetGroup[0].date;
|
int? lastMonth;
|
||||||
|
|
||||||
for (var group in _assetGroup) {
|
assetGroupByDateTime.forEach((dateGroup, immichAssetList) {
|
||||||
var dateTitle = group.date;
|
DateTime parseDateGroup = DateTime.parse(dateGroup);
|
||||||
var assetGroup = group.assets;
|
int currentMonth = parseDateGroup.month;
|
||||||
|
|
||||||
int? currentMonth = DateTime.tryParse(dateTitle)?.month;
|
if (lastMonth != null) {
|
||||||
int? previousMonth = DateTime.tryParse(lastGroupDate)?.month;
|
if (currentMonth - lastMonth! != 0) {
|
||||||
|
|
||||||
// Add Monthly Title Group if started at the beginning of the month
|
|
||||||
|
|
||||||
if (currentMonth != null && previousMonth != null) {
|
|
||||||
if ((currentMonth - previousMonth) != 0) {
|
|
||||||
_imageGridGroup.add(
|
_imageGridGroup.add(
|
||||||
MonthlyTitleText(isoDate: dateTitle),
|
MonthlyTitleText(
|
||||||
|
isoDate: dateGroup,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add Daily Title Group
|
|
||||||
_imageGridGroup.add(
|
_imageGridGroup.add(
|
||||||
DailyTitleText(isoDate: dateTitle, assetGroup: assetGroup),
|
DailyTitleText(
|
||||||
|
isoDate: dateGroup,
|
||||||
|
assetGroup: immichAssetList,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Add Image Group
|
|
||||||
_imageGridGroup.add(
|
_imageGridGroup.add(
|
||||||
ImageGrid(assetGroup: assetGroup),
|
ImageGrid(assetGroup: immichAssetList),
|
||||||
);
|
);
|
||||||
//
|
|
||||||
lastGroupDate = dateTitle;
|
lastMonth = currentMonth;
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: DraggableScrollbar.semicircle(
|
bottom: !isMultiSelectEnable,
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
top: !isMultiSelectEnable,
|
||||||
controller: _scrollController,
|
child: Stack(
|
||||||
heightScrollThumb: 48.0,
|
children: [
|
||||||
child: CustomScrollView(
|
DraggableScrollbar.semicircle(
|
||||||
controller: _scrollController,
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
slivers: [
|
controller: _scrollController,
|
||||||
ImmichSliverAppBar(
|
heightScrollThumb: 48.0,
|
||||||
imageGridGroup: _imageGridGroup,
|
child: CustomScrollView(
|
||||||
onPopBack: onPopBackFromBackupPage,
|
controller: _scrollController,
|
||||||
|
slivers: [
|
||||||
|
SliverAnimatedSwitcher(
|
||||||
|
child: isMultiSelectEnable
|
||||||
|
? const SliverToBoxAdapter(
|
||||||
|
child: SizedBox(
|
||||||
|
height: 70,
|
||||||
|
child: null,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: ImmichSliverAppBar(
|
||||||
|
imageGridGroup: _imageGridGroup,
|
||||||
|
onPopBack: onPopBackFromBackupPage,
|
||||||
|
),
|
||||||
|
duration: const Duration(milliseconds: 350),
|
||||||
|
),
|
||||||
|
..._imageGridGroup
|
||||||
|
],
|
||||||
),
|
),
|
||||||
..._imageGridGroup,
|
),
|
||||||
],
|
isMultiSelectEnable
|
||||||
),
|
? DisableMultiSelectButton(
|
||||||
|
onPressed: ref.watch(homePageStateProvider.notifier).disableMultiSelect,
|
||||||
|
selectedItemCount: homePageState.selectedItems.length,
|
||||||
|
)
|
||||||
|
: Container(),
|
||||||
|
isMultiSelectEnable ? const ControlBottomAppBar() : Container(),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
|
// key: _scaffoldKey,
|
||||||
drawer: const ProfileDrawer(),
|
drawer: const ProfileDrawer(),
|
||||||
body: _buildBody(),
|
body: _buildBody(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -20,31 +20,33 @@ class LoginForm extends HookConsumerWidget {
|
|||||||
return Center(
|
return Center(
|
||||||
child: ConstrainedBox(
|
child: ConstrainedBox(
|
||||||
constraints: const BoxConstraints(maxWidth: 300),
|
constraints: const BoxConstraints(maxWidth: 300),
|
||||||
child: Wrap(
|
child: SingleChildScrollView(
|
||||||
spacing: 32,
|
child: Wrap(
|
||||||
runSpacing: 32,
|
spacing: 32,
|
||||||
alignment: WrapAlignment.center,
|
runSpacing: 32,
|
||||||
children: [
|
alignment: WrapAlignment.center,
|
||||||
const Image(
|
children: [
|
||||||
image: AssetImage('assets/immich-logo-no-outline.png'),
|
const Image(
|
||||||
width: 128,
|
image: AssetImage('assets/immich-logo-no-outline.png'),
|
||||||
filterQuality: FilterQuality.high,
|
width: 128,
|
||||||
),
|
filterQuality: FilterQuality.high,
|
||||||
Text(
|
),
|
||||||
'IMMICH',
|
Text(
|
||||||
style: GoogleFonts.snowburstOne(
|
'IMMICH',
|
||||||
textStyle:
|
style: GoogleFonts.snowburstOne(
|
||||||
TextStyle(fontWeight: FontWeight.bold, fontSize: 48, color: Theme.of(context).primaryColor)),
|
textStyle:
|
||||||
),
|
TextStyle(fontWeight: FontWeight.bold, fontSize: 48, color: Theme.of(context).primaryColor)),
|
||||||
EmailInput(controller: usernameController),
|
),
|
||||||
PasswordInput(controller: passwordController),
|
EmailInput(controller: usernameController),
|
||||||
ServerEndpointInput(controller: serverEndpointController),
|
PasswordInput(controller: passwordController),
|
||||||
LoginButton(
|
ServerEndpointInput(controller: serverEndpointController),
|
||||||
emailController: usernameController,
|
LoginButton(
|
||||||
passwordController: passwordController,
|
emailController: usernameController,
|
||||||
serverEndpointController: serverEndpointController,
|
passwordController: passwordController,
|
||||||
),
|
serverEndpointController: serverEndpointController,
|
||||||
],
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@@ -126,7 +128,7 @@ class LoginButton extends ConsumerWidget {
|
|||||||
} else {
|
} else {
|
||||||
ImmichToast.show(
|
ImmichToast.show(
|
||||||
context: context,
|
context: context,
|
||||||
msg: "Error logging you in, check server url, emald and password!",
|
msg: "Error logging you in, check server url, email and password!",
|
||||||
toastType: ToastType.error);
|
toastType: ToastType.error);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
|
||||||
import 'package:immich_mobile/modules/login/ui/login_form.dart';
|
import 'package:immich_mobile/modules/login/ui/login_form.dart';
|
||||||
|
|
||||||
class LoginPage extends HookConsumerWidget {
|
class LoginPage extends HookConsumerWidget {
|
||||||
|
|||||||
@@ -3,8 +3,9 @@ import 'package:flutter/widgets.dart';
|
|||||||
import 'package:immich_mobile/modules/login/views/login_page.dart';
|
import 'package:immich_mobile/modules/login/views/login_page.dart';
|
||||||
import 'package:immich_mobile/modules/home/views/home_page.dart';
|
import 'package:immich_mobile/modules/home/views/home_page.dart';
|
||||||
import 'package:immich_mobile/routing/auth_guard.dart';
|
import 'package:immich_mobile/routing/auth_guard.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
import 'package:immich_mobile/shared/views/backup_controller_page.dart';
|
import 'package:immich_mobile/shared/views/backup_controller_page.dart';
|
||||||
import 'package:immich_mobile/shared/views/image_viewer_page.dart';
|
import 'package:immich_mobile/modules/asset_viewer/views/image_viewer_page.dart';
|
||||||
import 'package:immich_mobile/shared/views/video_viewer_page.dart';
|
import 'package:immich_mobile/shared/views/video_viewer_page.dart';
|
||||||
|
|
||||||
part 'router.gr.dart';
|
part 'router.gr.dart';
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ class _$AppRouter extends RootStackRouter {
|
|||||||
key: args.key,
|
key: args.key,
|
||||||
imageUrl: args.imageUrl,
|
imageUrl: args.imageUrl,
|
||||||
heroTag: args.heroTag,
|
heroTag: args.heroTag,
|
||||||
thumbnailUrl: args.thumbnailUrl));
|
thumbnailUrl: args.thumbnailUrl,
|
||||||
|
asset: args.asset));
|
||||||
},
|
},
|
||||||
VideoViewerRoute.name: (routeData) {
|
VideoViewerRoute.name: (routeData) {
|
||||||
final args = routeData.argsAs<VideoViewerRouteArgs>();
|
final args = routeData.argsAs<VideoViewerRouteArgs>();
|
||||||
@@ -96,14 +97,16 @@ class ImageViewerRoute extends PageRouteInfo<ImageViewerRouteArgs> {
|
|||||||
{Key? key,
|
{Key? key,
|
||||||
required String imageUrl,
|
required String imageUrl,
|
||||||
required String heroTag,
|
required String heroTag,
|
||||||
required String thumbnailUrl})
|
required String thumbnailUrl,
|
||||||
|
required ImmichAsset asset})
|
||||||
: super(ImageViewerRoute.name,
|
: super(ImageViewerRoute.name,
|
||||||
path: '/image-viewer-page',
|
path: '/image-viewer-page',
|
||||||
args: ImageViewerRouteArgs(
|
args: ImageViewerRouteArgs(
|
||||||
key: key,
|
key: key,
|
||||||
imageUrl: imageUrl,
|
imageUrl: imageUrl,
|
||||||
heroTag: heroTag,
|
heroTag: heroTag,
|
||||||
thumbnailUrl: thumbnailUrl));
|
thumbnailUrl: thumbnailUrl,
|
||||||
|
asset: asset));
|
||||||
|
|
||||||
static const String name = 'ImageViewerRoute';
|
static const String name = 'ImageViewerRoute';
|
||||||
}
|
}
|
||||||
@@ -113,7 +116,8 @@ class ImageViewerRouteArgs {
|
|||||||
{this.key,
|
{this.key,
|
||||||
required this.imageUrl,
|
required this.imageUrl,
|
||||||
required this.heroTag,
|
required this.heroTag,
|
||||||
required this.thumbnailUrl});
|
required this.thumbnailUrl,
|
||||||
|
required this.asset});
|
||||||
|
|
||||||
final Key? key;
|
final Key? key;
|
||||||
|
|
||||||
@@ -123,9 +127,11 @@ class ImageViewerRouteArgs {
|
|||||||
|
|
||||||
final String thumbnailUrl;
|
final String thumbnailUrl;
|
||||||
|
|
||||||
|
final ImmichAsset asset;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ImageViewerRouteArgs{key: $key, imageUrl: $imageUrl, heroTag: $heroTag, thumbnailUrl: $thumbnailUrl}';
|
return 'ImageViewerRouteArgs{key: $key, imageUrl: $imageUrl, heroTag: $heroTag, thumbnailUrl: $thumbnailUrl, asset: $asset}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
187
mobile/lib/shared/models/exif.model.dart
Normal file
187
mobile/lib/shared/models/exif.model.dart
Normal file
@@ -0,0 +1,187 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
class ImmichExif {
|
||||||
|
final int? id;
|
||||||
|
final String? assetId;
|
||||||
|
final String? make;
|
||||||
|
final String? model;
|
||||||
|
final String? imageName;
|
||||||
|
final int? exifImageWidth;
|
||||||
|
final int? exifImageHeight;
|
||||||
|
final int? fileSizeInByte;
|
||||||
|
final String? orientation;
|
||||||
|
final String? dateTimeOriginal;
|
||||||
|
final String? modifyDate;
|
||||||
|
final String? lensModel;
|
||||||
|
final double? fNumber;
|
||||||
|
final double? focalLength;
|
||||||
|
final int? iso;
|
||||||
|
final double? exposureTime;
|
||||||
|
final double? latitude;
|
||||||
|
final double? longitude;
|
||||||
|
|
||||||
|
ImmichExif({
|
||||||
|
this.id,
|
||||||
|
this.assetId,
|
||||||
|
this.make,
|
||||||
|
this.model,
|
||||||
|
this.imageName,
|
||||||
|
this.exifImageWidth,
|
||||||
|
this.exifImageHeight,
|
||||||
|
this.fileSizeInByte,
|
||||||
|
this.orientation,
|
||||||
|
this.dateTimeOriginal,
|
||||||
|
this.modifyDate,
|
||||||
|
this.lensModel,
|
||||||
|
this.fNumber,
|
||||||
|
this.focalLength,
|
||||||
|
this.iso,
|
||||||
|
this.exposureTime,
|
||||||
|
this.latitude,
|
||||||
|
this.longitude,
|
||||||
|
});
|
||||||
|
|
||||||
|
ImmichExif copyWith({
|
||||||
|
int? id,
|
||||||
|
String? assetId,
|
||||||
|
String? make,
|
||||||
|
String? model,
|
||||||
|
String? imageName,
|
||||||
|
int? exifImageWidth,
|
||||||
|
int? exifImageHeight,
|
||||||
|
int? fileSizeInByte,
|
||||||
|
String? orientation,
|
||||||
|
String? dateTimeOriginal,
|
||||||
|
String? modifyDate,
|
||||||
|
String? lensModel,
|
||||||
|
double? fNumber,
|
||||||
|
double? focalLength,
|
||||||
|
int? iso,
|
||||||
|
double? exposureTime,
|
||||||
|
double? latitude,
|
||||||
|
double? longitude,
|
||||||
|
}) {
|
||||||
|
return ImmichExif(
|
||||||
|
id: id ?? this.id,
|
||||||
|
assetId: assetId ?? this.assetId,
|
||||||
|
make: make ?? this.make,
|
||||||
|
model: model ?? this.model,
|
||||||
|
imageName: imageName ?? this.imageName,
|
||||||
|
exifImageWidth: exifImageWidth ?? this.exifImageWidth,
|
||||||
|
exifImageHeight: exifImageHeight ?? this.exifImageHeight,
|
||||||
|
fileSizeInByte: fileSizeInByte ?? this.fileSizeInByte,
|
||||||
|
orientation: orientation ?? this.orientation,
|
||||||
|
dateTimeOriginal: dateTimeOriginal ?? this.dateTimeOriginal,
|
||||||
|
modifyDate: modifyDate ?? this.modifyDate,
|
||||||
|
lensModel: lensModel ?? this.lensModel,
|
||||||
|
fNumber: fNumber ?? this.fNumber,
|
||||||
|
focalLength: focalLength ?? this.focalLength,
|
||||||
|
iso: iso ?? this.iso,
|
||||||
|
exposureTime: exposureTime ?? this.exposureTime,
|
||||||
|
latitude: latitude ?? this.latitude,
|
||||||
|
longitude: longitude ?? this.longitude,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'assetId': assetId,
|
||||||
|
'make': make,
|
||||||
|
'model': model,
|
||||||
|
'imageName': imageName,
|
||||||
|
'exifImageWidth': exifImageWidth,
|
||||||
|
'exifImageHeight': exifImageHeight,
|
||||||
|
'fileSizeInByte': fileSizeInByte,
|
||||||
|
'orientation': orientation,
|
||||||
|
'dateTimeOriginal': dateTimeOriginal,
|
||||||
|
'modifyDate': modifyDate,
|
||||||
|
'lensModel': lensModel,
|
||||||
|
'fNumber': fNumber,
|
||||||
|
'focalLength': focalLength,
|
||||||
|
'iso': iso,
|
||||||
|
'exposureTime': exposureTime,
|
||||||
|
'latitude': latitude,
|
||||||
|
'longitude': longitude,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory ImmichExif.fromMap(Map<String, dynamic> map) {
|
||||||
|
return ImmichExif(
|
||||||
|
id: map['id']?.toInt(),
|
||||||
|
assetId: map['assetId'],
|
||||||
|
make: map['make'],
|
||||||
|
model: map['model'],
|
||||||
|
imageName: map['imageName'],
|
||||||
|
exifImageWidth: map['exifImageWidth']?.toInt(),
|
||||||
|
exifImageHeight: map['exifImageHeight']?.toInt(),
|
||||||
|
fileSizeInByte: map['fileSizeInByte']?.toInt(),
|
||||||
|
orientation: map['orientation'],
|
||||||
|
dateTimeOriginal: map['dateTimeOriginal'],
|
||||||
|
modifyDate: map['modifyDate'],
|
||||||
|
lensModel: map['lensModel'],
|
||||||
|
fNumber: map['fNumber']?.toDouble(),
|
||||||
|
focalLength: map['focalLength']?.toDouble(),
|
||||||
|
iso: map['iso']?.toInt(),
|
||||||
|
exposureTime: map['exposureTime']?.toDouble(),
|
||||||
|
latitude: map['latitude']?.toDouble(),
|
||||||
|
longitude: map['longitude']?.toDouble(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
factory ImmichExif.fromJson(String source) => ImmichExif.fromMap(json.decode(source));
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ImmichExif(id: $id, assetId: $assetId, make: $make, model: $model, imageName: $imageName, exifImageWidth: $exifImageWidth, exifImageHeight: $exifImageHeight, fileSizeInByte: $fileSizeInByte, orientation: $orientation, dateTimeOriginal: $dateTimeOriginal, modifyDate: $modifyDate, lensModel: $lensModel, fNumber: $fNumber, focalLength: $focalLength, iso: $iso, exposureTime: $exposureTime, latitude: $latitude, longitude: $longitude)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is ImmichExif &&
|
||||||
|
other.id == id &&
|
||||||
|
other.assetId == assetId &&
|
||||||
|
other.make == make &&
|
||||||
|
other.model == model &&
|
||||||
|
other.imageName == imageName &&
|
||||||
|
other.exifImageWidth == exifImageWidth &&
|
||||||
|
other.exifImageHeight == exifImageHeight &&
|
||||||
|
other.fileSizeInByte == fileSizeInByte &&
|
||||||
|
other.orientation == orientation &&
|
||||||
|
other.dateTimeOriginal == dateTimeOriginal &&
|
||||||
|
other.modifyDate == modifyDate &&
|
||||||
|
other.lensModel == lensModel &&
|
||||||
|
other.fNumber == fNumber &&
|
||||||
|
other.focalLength == focalLength &&
|
||||||
|
other.iso == iso &&
|
||||||
|
other.exposureTime == exposureTime &&
|
||||||
|
other.latitude == latitude &&
|
||||||
|
other.longitude == longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^
|
||||||
|
assetId.hashCode ^
|
||||||
|
make.hashCode ^
|
||||||
|
model.hashCode ^
|
||||||
|
imageName.hashCode ^
|
||||||
|
exifImageWidth.hashCode ^
|
||||||
|
exifImageHeight.hashCode ^
|
||||||
|
fileSizeInByte.hashCode ^
|
||||||
|
orientation.hashCode ^
|
||||||
|
dateTimeOriginal.hashCode ^
|
||||||
|
modifyDate.hashCode ^
|
||||||
|
lensModel.hashCode ^
|
||||||
|
fNumber.hashCode ^
|
||||||
|
focalLength.hashCode ^
|
||||||
|
iso.hashCode ^
|
||||||
|
exposureTime.hashCode ^
|
||||||
|
latitude.hashCode ^
|
||||||
|
longitude.hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
133
mobile/lib/shared/models/immich_asset_with_exif.model.dart
Normal file
133
mobile/lib/shared/models/immich_asset_with_exif.model.dart
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:immich_mobile/shared/models/exif.model.dart';
|
||||||
|
|
||||||
|
class ImmichAssetWithExif {
|
||||||
|
final String id;
|
||||||
|
final String deviceAssetId;
|
||||||
|
final String userId;
|
||||||
|
final String deviceId;
|
||||||
|
final String type;
|
||||||
|
final String createdAt;
|
||||||
|
final String modifiedAt;
|
||||||
|
final String originalPath;
|
||||||
|
final bool isFavorite;
|
||||||
|
final String? duration;
|
||||||
|
final ImmichExif? exifInfo;
|
||||||
|
|
||||||
|
ImmichAssetWithExif({
|
||||||
|
required this.id,
|
||||||
|
required this.deviceAssetId,
|
||||||
|
required this.userId,
|
||||||
|
required this.deviceId,
|
||||||
|
required this.type,
|
||||||
|
required this.createdAt,
|
||||||
|
required this.modifiedAt,
|
||||||
|
required this.originalPath,
|
||||||
|
required this.isFavorite,
|
||||||
|
this.duration,
|
||||||
|
this.exifInfo,
|
||||||
|
});
|
||||||
|
|
||||||
|
ImmichAssetWithExif copyWith({
|
||||||
|
String? id,
|
||||||
|
String? deviceAssetId,
|
||||||
|
String? userId,
|
||||||
|
String? deviceId,
|
||||||
|
String? type,
|
||||||
|
String? createdAt,
|
||||||
|
String? modifiedAt,
|
||||||
|
String? originalPath,
|
||||||
|
bool? isFavorite,
|
||||||
|
String? duration,
|
||||||
|
ImmichExif? exifInfo,
|
||||||
|
}) {
|
||||||
|
return ImmichAssetWithExif(
|
||||||
|
id: id ?? this.id,
|
||||||
|
deviceAssetId: deviceAssetId ?? this.deviceAssetId,
|
||||||
|
userId: userId ?? this.userId,
|
||||||
|
deviceId: deviceId ?? this.deviceId,
|
||||||
|
type: type ?? this.type,
|
||||||
|
createdAt: createdAt ?? this.createdAt,
|
||||||
|
modifiedAt: modifiedAt ?? this.modifiedAt,
|
||||||
|
originalPath: originalPath ?? this.originalPath,
|
||||||
|
isFavorite: isFavorite ?? this.isFavorite,
|
||||||
|
duration: duration ?? this.duration,
|
||||||
|
exifInfo: exifInfo ?? this.exifInfo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toMap() {
|
||||||
|
return {
|
||||||
|
'id': id,
|
||||||
|
'deviceAssetId': deviceAssetId,
|
||||||
|
'userId': userId,
|
||||||
|
'deviceId': deviceId,
|
||||||
|
'type': type,
|
||||||
|
'createdAt': createdAt,
|
||||||
|
'modifiedAt': modifiedAt,
|
||||||
|
'originalPath': originalPath,
|
||||||
|
'isFavorite': isFavorite,
|
||||||
|
'duration': duration,
|
||||||
|
'exifInfo': exifInfo?.toMap(),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
factory ImmichAssetWithExif.fromMap(Map<String, dynamic> map) {
|
||||||
|
return ImmichAssetWithExif(
|
||||||
|
id: map['id'] ?? '',
|
||||||
|
deviceAssetId: map['deviceAssetId'] ?? '',
|
||||||
|
userId: map['userId'] ?? '',
|
||||||
|
deviceId: map['deviceId'] ?? '',
|
||||||
|
type: map['type'] ?? '',
|
||||||
|
createdAt: map['createdAt'] ?? '',
|
||||||
|
modifiedAt: map['modifiedAt'] ?? '',
|
||||||
|
originalPath: map['originalPath'] ?? '',
|
||||||
|
isFavorite: map['isFavorite'] ?? false,
|
||||||
|
duration: map['duration'],
|
||||||
|
exifInfo: map['exifInfo'] != null ? ImmichExif.fromMap(map['exifInfo']) : null,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String toJson() => json.encode(toMap());
|
||||||
|
|
||||||
|
factory ImmichAssetWithExif.fromJson(String source) => ImmichAssetWithExif.fromMap(json.decode(source));
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() {
|
||||||
|
return 'ImmichAssetWithExif(id: $id, deviceAssetId: $deviceAssetId, userId: $userId, deviceId: $deviceId, type: $type, createdAt: $createdAt, modifiedAt: $modifiedAt, originalPath: $originalPath, isFavorite: $isFavorite, duration: $duration, exifInfo: $exifInfo)';
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is ImmichAssetWithExif &&
|
||||||
|
other.id == id &&
|
||||||
|
other.deviceAssetId == deviceAssetId &&
|
||||||
|
other.userId == userId &&
|
||||||
|
other.deviceId == deviceId &&
|
||||||
|
other.type == type &&
|
||||||
|
other.createdAt == createdAt &&
|
||||||
|
other.modifiedAt == modifiedAt &&
|
||||||
|
other.originalPath == originalPath &&
|
||||||
|
other.isFavorite == isFavorite &&
|
||||||
|
other.duration == duration &&
|
||||||
|
other.exifInfo == exifInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode {
|
||||||
|
return id.hashCode ^
|
||||||
|
deviceAssetId.hashCode ^
|
||||||
|
userId.hashCode ^
|
||||||
|
deviceId.hashCode ^
|
||||||
|
type.hashCode ^
|
||||||
|
createdAt.hashCode ^
|
||||||
|
modifiedAt.hashCode ^
|
||||||
|
originalPath.hashCode ^
|
||||||
|
isFavorite.hashCode ^
|
||||||
|
duration.hashCode ^
|
||||||
|
exifInfo.hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
@@ -11,7 +13,7 @@ import 'package:immich_mobile/shared/services/backup.service.dart';
|
|||||||
import 'package:photo_manager/photo_manager.dart';
|
import 'package:photo_manager/photo_manager.dart';
|
||||||
|
|
||||||
class BackupNotifier extends StateNotifier<BackUpState> {
|
class BackupNotifier extends StateNotifier<BackUpState> {
|
||||||
BackupNotifier(this.ref)
|
BackupNotifier({this.ref})
|
||||||
: super(
|
: super(
|
||||||
BackUpState(
|
BackUpState(
|
||||||
backupProgress: BackUpProgressEnum.idle,
|
backupProgress: BackUpProgressEnum.idle,
|
||||||
@@ -32,22 +34,25 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
final Ref ref;
|
Ref? ref;
|
||||||
final BackupService _backupService = BackupService();
|
final BackupService _backupService = BackupService();
|
||||||
final ServerInfoService _serverInfoService = ServerInfoService();
|
final ServerInfoService _serverInfoService = ServerInfoService();
|
||||||
|
final StreamController _onAssetBackupStreamCtrl = StreamController.broadcast();
|
||||||
|
|
||||||
void getBackupInfo() async {
|
void getBackupInfo() async {
|
||||||
_updateServerInfo();
|
_updateServerInfo();
|
||||||
|
|
||||||
List<AssetPathEntity> list = await PhotoManager.getAssetPathList(onlyAll: true, type: RequestType.common);
|
List<AssetPathEntity> list = await PhotoManager.getAssetPathList(onlyAll: true, type: RequestType.common);
|
||||||
|
List<String> didBackupAsset = await _backupService.getDeviceBackupAsset();
|
||||||
|
|
||||||
if (list.isEmpty) {
|
if (list.isEmpty) {
|
||||||
debugPrint("No Asset On Device");
|
debugPrint("No Asset On Device");
|
||||||
|
state = state.copyWith(
|
||||||
|
backupProgress: BackUpProgressEnum.idle, totalAssetCount: 0, assetOnDatabase: didBackupAsset.length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalAsset = list[0].assetCount;
|
int totalAsset = list[0].assetCount;
|
||||||
List<String> didBackupAsset = await _backupService.getDeviceBackupAsset();
|
|
||||||
|
|
||||||
state = state.copyWith(totalAssetCount: totalAsset, assetOnDatabase: didBackupAsset.length);
|
state = state.copyWith(totalAssetCount: totalAsset, assetOnDatabase: didBackupAsset.length);
|
||||||
}
|
}
|
||||||
@@ -65,19 +70,21 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||||||
List<AssetPathEntity> list =
|
List<AssetPathEntity> list =
|
||||||
await PhotoManager.getAssetPathList(hasAll: true, onlyAll: true, type: RequestType.common);
|
await PhotoManager.getAssetPathList(hasAll: true, onlyAll: true, type: RequestType.common);
|
||||||
|
|
||||||
|
// Get device assets info from database
|
||||||
|
// Compare and find different assets that has not been backing up
|
||||||
|
// Backup those assets
|
||||||
|
List<String> backupAsset = await _backupService.getDeviceBackupAsset();
|
||||||
|
|
||||||
if (list.isEmpty) {
|
if (list.isEmpty) {
|
||||||
debugPrint("No Asset On Device - Abort Backup Process");
|
debugPrint("No Asset On Device - Abort Backup Process");
|
||||||
|
state = state.copyWith(
|
||||||
|
backupProgress: BackUpProgressEnum.idle, totalAssetCount: 0, assetOnDatabase: backupAsset.length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int totalAsset = list[0].assetCount;
|
int totalAsset = list[0].assetCount;
|
||||||
List<AssetEntity> currentAssets = await list[0].getAssetListRange(start: 0, end: totalAsset);
|
List<AssetEntity> currentAssets = await list[0].getAssetListRange(start: 0, end: totalAsset);
|
||||||
|
|
||||||
// Get device assets info from database
|
|
||||||
// Compare and find different assets that has not been backing up
|
|
||||||
// Backup those assets
|
|
||||||
List<String> backupAsset = await _backupService.getDeviceBackupAsset();
|
|
||||||
|
|
||||||
state = state.copyWith(totalAssetCount: totalAsset, assetOnDatabase: backupAsset.length);
|
state = state.copyWith(totalAssetCount: totalAsset, assetOnDatabase: backupAsset.length);
|
||||||
// Remove item that has already been backed up
|
// Remove item that has already been backed up
|
||||||
for (var backupAssetId in backupAsset) {
|
for (var backupAssetId in backupAsset) {
|
||||||
@@ -103,7 +110,7 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||||||
state = state.copyWith(backupProgress: BackUpProgressEnum.idle, progressInPercentage: 0.0);
|
state = state.copyWith(backupProgress: BackUpProgressEnum.idle, progressInPercentage: 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void _onAssetUploaded() {
|
void _onAssetUploaded(String deviceAssetId, String deviceId) {
|
||||||
state =
|
state =
|
||||||
state.copyWith(backingUpAssetCount: state.backingUpAssetCount - 1, assetOnDatabase: state.assetOnDatabase + 1);
|
state.copyWith(backingUpAssetCount: state.backingUpAssetCount - 1, assetOnDatabase: state.assetOnDatabase + 1);
|
||||||
|
|
||||||
@@ -136,36 +143,36 @@ class BackupNotifier extends StateNotifier<BackUpState> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void resumeBackup() {
|
void resumeBackup() {
|
||||||
debugPrint("[resumeBackup]");
|
var authState = ref?.read(authenticationProvider);
|
||||||
var authState = ref.read(authenticationProvider);
|
|
||||||
|
|
||||||
// Check if user is login
|
// Check if user is login
|
||||||
var accessKey = Hive.box(userInfoBox).get(accessTokenKey);
|
var accessKey = Hive.box(userInfoBox).get(accessTokenKey);
|
||||||
|
|
||||||
// User has been logged out return
|
// User has been logged out return
|
||||||
if (accessKey == null || !authState.isAuthenticated) {
|
if (authState != null) {
|
||||||
debugPrint("[resumeBackup] not authenticated - abort");
|
if (accessKey == null || !authState.isAuthenticated) {
|
||||||
return;
|
debugPrint("[resumeBackup] not authenticated - abort");
|
||||||
}
|
|
||||||
|
|
||||||
// Check if this device is enable backup by the user
|
|
||||||
if ((authState.deviceInfo.deviceId == authState.deviceId) && authState.deviceInfo.isAutoBackup) {
|
|
||||||
// check if backup is alreayd in process - then return
|
|
||||||
if (state.backupProgress == BackUpProgressEnum.inProgress) {
|
|
||||||
debugPrint("[resumeBackup] Backup is already in progress - abort");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run backup
|
// Check if this device is enable backup by the user
|
||||||
debugPrint("[resumeBackup] Start back up");
|
if ((authState.deviceInfo.deviceId == authState.deviceId) && authState.deviceInfo.isAutoBackup) {
|
||||||
startBackupProcess();
|
// check if backup is alreayd in process - then return
|
||||||
}
|
if (state.backupProgress == BackUpProgressEnum.inProgress) {
|
||||||
|
debugPrint("[resumeBackup] Backup is already in progress - abort");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
debugPrint("[resumeBackup] User disables auto backup");
|
// Run backup
|
||||||
return;
|
debugPrint("[resumeBackup] Start back up");
|
||||||
|
startBackupProcess();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final backupProvider = StateNotifierProvider<BackupNotifier, BackUpState>((ref) {
|
final backupProvider = StateNotifierProvider<BackupNotifier, BackUpState>((ref) {
|
||||||
return BackupNotifier(ref);
|
return BackupNotifier(ref: ref);
|
||||||
});
|
});
|
||||||
|
|||||||
113
mobile/lib/shared/providers/websocket.provider.dart
Normal file
113
mobile/lib/shared/providers/websocket.provider.dart
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:hive/hive.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
||||||
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
|
import 'package:socket_io_client/socket_io_client.dart';
|
||||||
|
|
||||||
|
import 'package:immich_mobile/constants/hive_box.dart';
|
||||||
|
import 'package:immich_mobile/modules/login/providers/authentication.provider.dart';
|
||||||
|
|
||||||
|
class WebscoketState {
|
||||||
|
final Socket? socket;
|
||||||
|
final bool isConnected;
|
||||||
|
|
||||||
|
WebscoketState({
|
||||||
|
this.socket,
|
||||||
|
required this.isConnected,
|
||||||
|
});
|
||||||
|
|
||||||
|
WebscoketState copyWith({
|
||||||
|
Socket? socket,
|
||||||
|
bool? isConnected,
|
||||||
|
}) {
|
||||||
|
return WebscoketState(
|
||||||
|
socket: socket ?? this.socket,
|
||||||
|
isConnected: isConnected ?? this.isConnected,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
String toString() => 'WebscoketState(socket: $socket, isConnected: $isConnected)';
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool operator ==(Object other) {
|
||||||
|
if (identical(this, other)) return true;
|
||||||
|
|
||||||
|
return other is WebscoketState && other.socket == socket && other.isConnected == isConnected;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
int get hashCode => socket.hashCode ^ isConnected.hashCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
class WebsocketNotifier extends StateNotifier<WebscoketState> {
|
||||||
|
WebsocketNotifier(this.ref) : super(WebscoketState(socket: null, isConnected: false)) {
|
||||||
|
debugPrint("Init websocket instance");
|
||||||
|
}
|
||||||
|
|
||||||
|
final Ref ref;
|
||||||
|
|
||||||
|
connect() {
|
||||||
|
var authenticationState = ref.watch(authenticationProvider);
|
||||||
|
|
||||||
|
if (authenticationState.isAuthenticated) {
|
||||||
|
var accessToken = Hive.box(userInfoBox).get(accessTokenKey);
|
||||||
|
var endpoint = Hive.box(userInfoBox).get(serverEndpointKey);
|
||||||
|
try {
|
||||||
|
debugPrint("[WEBSOCKET] Attempting to connect to ws");
|
||||||
|
// Configure socket transports must be sepecified
|
||||||
|
Socket socket = io(
|
||||||
|
endpoint,
|
||||||
|
OptionBuilder()
|
||||||
|
.setTransports(['websocket'])
|
||||||
|
.enableReconnection()
|
||||||
|
.enableForceNew()
|
||||||
|
.enableForceNewConnection()
|
||||||
|
.enableAutoConnect()
|
||||||
|
.setExtraHeaders({"Authorization": "Bearer $accessToken"})
|
||||||
|
.build(),
|
||||||
|
);
|
||||||
|
|
||||||
|
socket.onConnect((_) {
|
||||||
|
debugPrint("[WEBSOCKET] Established Websocket Connection");
|
||||||
|
state = WebscoketState(isConnected: true, socket: socket);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.onDisconnect((_) {
|
||||||
|
debugPrint("[WEBSOCKET] Disconnect to Websocket Connection");
|
||||||
|
state = WebscoketState(isConnected: false, socket: null);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('error', (errorMessage) {
|
||||||
|
debugPrint("Webcoket Error - $errorMessage");
|
||||||
|
state = WebscoketState(isConnected: false, socket: null);
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('on_upload_success', (data) {
|
||||||
|
var jsonString = jsonDecode(data.toString());
|
||||||
|
ImmichAsset newAsset = ImmichAsset.fromMap(jsonString);
|
||||||
|
ref.watch(assetProvider.notifier).onNewAssetUploaded(newAsset);
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("[WEBSOCKET] Catch Websocket Error - ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnect() {
|
||||||
|
debugPrint("[WEBSOCKET] Attempting to disconnect");
|
||||||
|
var socket = state.socket?.disconnect();
|
||||||
|
if (socket != null) {
|
||||||
|
if (socket.disconnected) {
|
||||||
|
state = WebscoketState(isConnected: false, socket: null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final websocketProvider = StateNotifierProvider<WebsocketNotifier, WebscoketState>((ref) {
|
||||||
|
return WebsocketNotifier(ref);
|
||||||
|
});
|
||||||
@@ -26,7 +26,7 @@ class BackupService {
|
|||||||
return result.cast<String>();
|
return result.cast<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
backupAsset(List<AssetEntity> assetList, CancelToken cancelToken, Function singleAssetDoneCb,
|
backupAsset(List<AssetEntity> assetList, CancelToken cancelToken, Function(String, String) singleAssetDoneCb,
|
||||||
Function(int, int) uploadProgress) async {
|
Function(int, int) uploadProgress) async {
|
||||||
var dio = Dio();
|
var dio = Dio();
|
||||||
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
dio.interceptors.add(AuthenticatedRequestInterceptor());
|
||||||
@@ -37,20 +37,12 @@ class BackupService {
|
|||||||
for (var entity in assetList) {
|
for (var entity in assetList) {
|
||||||
try {
|
try {
|
||||||
if (entity.type == AssetType.video) {
|
if (entity.type == AssetType.video) {
|
||||||
file = await entity.file;
|
file = await entity.originFile;
|
||||||
} else {
|
} else {
|
||||||
file = await entity.file.timeout(const Duration(seconds: 5));
|
file = await entity.originFile.timeout(const Duration(seconds: 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
// reading exif
|
|
||||||
// var exifData = await readExifFromFile(file);
|
|
||||||
|
|
||||||
// for (String key in exifData.keys) {
|
|
||||||
// debugPrint("- $key (${exifData[key]?.tagType}): ${exifData[key]}");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// debugPrint("------------------");
|
|
||||||
String originalFileName = await entity.titleAsync;
|
String originalFileName = await entity.titleAsync;
|
||||||
String fileNameWithoutPath = originalFileName.toString().split(".")[0];
|
String fileNameWithoutPath = originalFileName.toString().split(".")[0];
|
||||||
var fileExtension = p.extension(file.path);
|
var fileExtension = p.extension(file.path);
|
||||||
@@ -85,7 +77,7 @@ class BackupService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (res.statusCode == 201) {
|
if (res.statusCode == 201) {
|
||||||
singleAssetDoneCb();
|
singleAssetDoneCb(entity.id, deviceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} on DioError catch (e) {
|
} on DioError catch (e) {
|
||||||
|
|||||||
@@ -7,6 +7,24 @@ 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';
|
||||||
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (res.statusCode == 200) {
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
} on DioError catch (e) {
|
||||||
|
debugPrint("DioError: ${e.response}");
|
||||||
|
} catch (e) {
|
||||||
|
debugPrint("ERROR getRequest: ${e.toString()}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Future<dynamic> getRequest({required String url}) async {
|
Future<dynamic> getRequest({required String url}) async {
|
||||||
try {
|
try {
|
||||||
var dio = Dio();
|
var dio = Dio();
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ class BackupControllerPage extends HookConsumerWidget {
|
|||||||
if (_backupState.backupProgress != BackUpProgressEnum.inProgress) {
|
if (_backupState.backupProgress != BackUpProgressEnum.inProgress) {
|
||||||
ref.read(backupProvider.notifier).getBackupInfo();
|
ref.read(backupProvider.notifier).getBackupInfo();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
Widget _buildStorageInformation() {
|
Widget _buildStorageInformation() {
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
import 'package:auto_route/auto_route.dart';
|
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:hive/hive.dart';
|
|
||||||
import 'package:immich_mobile/constants/hive_box.dart';
|
|
||||||
|
|
||||||
class ImageViewerPage extends StatelessWidget {
|
|
||||||
final String imageUrl;
|
|
||||||
final String heroTag;
|
|
||||||
final String thumbnailUrl;
|
|
||||||
|
|
||||||
const ImageViewerPage({Key? key, required this.imageUrl, required this.heroTag, required this.thumbnailUrl})
|
|
||||||
: super(key: key);
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
var box = Hive.box(userInfoBox);
|
|
||||||
|
|
||||||
return Scaffold(
|
|
||||||
backgroundColor: Colors.black,
|
|
||||||
appBar: AppBar(
|
|
||||||
toolbarHeight: 60,
|
|
||||||
backgroundColor: Colors.black,
|
|
||||||
leading: IconButton(
|
|
||||||
onPressed: () {
|
|
||||||
AutoRouter.of(context).pop();
|
|
||||||
},
|
|
||||||
icon: const Icon(Icons.arrow_back_ios)),
|
|
||||||
),
|
|
||||||
body: Dismissible(
|
|
||||||
direction: DismissDirection.vertical,
|
|
||||||
onDismissed: (_) {
|
|
||||||
AutoRouter.of(context).pop();
|
|
||||||
},
|
|
||||||
key: Key(heroTag),
|
|
||||||
child: Center(
|
|
||||||
child: Hero(
|
|
||||||
tag: heroTag,
|
|
||||||
child: CachedNetworkImage(
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
imageUrl: imageUrl,
|
|
||||||
httpHeaders: {"Authorization": "Bearer ${box.get(accessTokenKey)}"},
|
|
||||||
fadeInDuration: const Duration(milliseconds: 250),
|
|
||||||
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
||||||
placeholder: (context, url) {
|
|
||||||
return CachedNetworkImage(
|
|
||||||
fit: BoxFit.cover,
|
|
||||||
imageUrl: thumbnailUrl,
|
|
||||||
httpHeaders: {"Authorization": "Bearer ${box.get(accessTokenKey)}"},
|
|
||||||
placeholderFadeInDuration: const Duration(milliseconds: 0),
|
|
||||||
progressIndicatorBuilder: (context, url, downloadProgress) => Transform.scale(
|
|
||||||
scale: 0.2,
|
|
||||||
child: CircularProgressIndicator(value: downloadProgress.progress),
|
|
||||||
),
|
|
||||||
errorWidget: (context, url, error) => const Icon(Icons.error),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
class FileHelper {
|
class FileHelper {
|
||||||
static getMimeType(String filePath) {
|
static getMimeType(String filePath) {
|
||||||
debugPrint(filePath);
|
|
||||||
var fileExtension = p.extension(filePath).split(".")[1];
|
var fileExtension = p.extension(filePath).split(".")[1];
|
||||||
|
|
||||||
switch (fileExtension.toLowerCase()) {
|
switch (fileExtension.toLowerCase()) {
|
||||||
@@ -28,6 +26,12 @@ class FileHelper {
|
|||||||
case 'avi':
|
case 'avi':
|
||||||
return {"type": "video", "subType": "x-msvideo"};
|
return {"type": "video", "subType": "x-msvideo"};
|
||||||
|
|
||||||
|
case 'heic':
|
||||||
|
return {"type": "image", "subType": "heic"};
|
||||||
|
|
||||||
|
case 'heif':
|
||||||
|
return {"type": "image", "subType": "heif"};
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return {"type": "unsupport", "subType": "unsupport"};
|
return {"type": "unsupport", "subType": "unsupport"};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ build:
|
|||||||
flutter packages pub run build_runner build
|
flutter packages pub run build_runner build
|
||||||
|
|
||||||
watch:
|
watch:
|
||||||
flutter packages pub run build_runner watch
|
flutter packages pub run build_runner watch --delete-conflicting-outputs
|
||||||
|
|
||||||
create_app_icon:
|
create_app_icon:
|
||||||
flutter pub run flutter_launcher_icons:main
|
flutter pub run flutter_launcher_icons:main
|
||||||
@@ -50,6 +50,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.2.1"
|
version: "3.2.1"
|
||||||
|
badges:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: badges
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.2"
|
||||||
boolean_selector:
|
boolean_selector:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -639,6 +646,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.10"
|
version: "1.3.10"
|
||||||
|
photo_view:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: photo_view
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.13.0"
|
||||||
platform:
|
platform:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@@ -721,6 +735,27 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.99"
|
version: "0.0.99"
|
||||||
|
sliver_tools:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: sliver_tools
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "0.2.5"
|
||||||
|
socket_io_client:
|
||||||
|
dependency: "direct main"
|
||||||
|
description:
|
||||||
|
name: socket_io_client
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0-beta.4-nullsafety.0"
|
||||||
|
socket_io_common:
|
||||||
|
dependency: transitive
|
||||||
|
description:
|
||||||
|
name: socket_io_common
|
||||||
|
url: "https://pub.dartlang.org"
|
||||||
|
source: hosted
|
||||||
|
version: "2.0.0"
|
||||||
source_gen:
|
source_gen:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|||||||
@@ -30,6 +30,10 @@ dependencies:
|
|||||||
fluttertoast: ^8.0.8
|
fluttertoast: ^8.0.8
|
||||||
video_player: ^2.2.18
|
video_player: ^2.2.18
|
||||||
chewie: ^1.2.2
|
chewie: ^1.2.2
|
||||||
|
sliver_tools: ^0.2.5
|
||||||
|
badges: ^2.0.2
|
||||||
|
photo_view: ^0.13.0
|
||||||
|
socket_io_client: ^2.0.0-beta.4-nullsafety.0
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
flutter_test:
|
flutter_test:
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ DB_PASSWORD=postgres
|
|||||||
DB_DATABASE_NAME=
|
DB_DATABASE_NAME=
|
||||||
|
|
||||||
# Upload File Config
|
# Upload File Config
|
||||||
UPLOAD_LOCATION=./upload
|
UPLOAD_LOCATION=absolute_location_on_your_machine_where_you_want_to_store_the_backup
|
||||||
|
|
||||||
# JWT SECRET
|
# JWT SECRET
|
||||||
JWT_SECRET=
|
JWT_SECRET=
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
##################################
|
##################################
|
||||||
# DEVELOPMENT
|
# DEVELOPMENT
|
||||||
##################################
|
##################################
|
||||||
FROM node:16-bullseye-slim AS development
|
FROM node:16-alpine3.14 AS development
|
||||||
|
|
||||||
ARG DEBIAN_FRONTEND=noninteractive
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
|
||||||
@@ -9,8 +9,7 @@ WORKDIR /usr/src/app
|
|||||||
|
|
||||||
COPY package.json package-lock.json ./
|
COPY package.json package-lock.json ./
|
||||||
|
|
||||||
RUN apt-get update
|
RUN apk add --update-cache build-base python3 libheif vips-dev vips ffmpeg
|
||||||
RUN apt-get install gcc g++ make cmake python3 python3-pip ffmpeg -y
|
|
||||||
|
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
@@ -18,44 +17,25 @@ COPY . .
|
|||||||
|
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
|
|
||||||
# Clean up commands
|
#################################
|
||||||
RUN apt-get autoremove -y && apt-get clean && \
|
|
||||||
rm -rf /usr/local/src/*
|
|
||||||
|
|
||||||
RUN apt-get clean && \
|
|
||||||
rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##################################
|
|
||||||
# PRODUCTION
|
# PRODUCTION
|
||||||
##################################
|
#################################
|
||||||
# FROM node:16-bullseye-slim as production
|
FROM node:16-alpine3.14 AS production
|
||||||
# ARG DEBIAN_FRONTEND=noninteractive
|
|
||||||
# ARG NODE_ENV=production
|
|
||||||
# ENV NODE_ENV=${NODE_ENV}
|
|
||||||
|
|
||||||
# WORKDIR /usr/src/app
|
ARG DEBIAN_FRONTEND=noninteractive
|
||||||
|
ARG NODE_ENV=production
|
||||||
|
ENV NODE_ENV=${NODE_ENV}
|
||||||
|
|
||||||
# COPY package.json yarn.lock ./
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
# RUN apt-get update
|
COPY package.json package-lock.json ./
|
||||||
# RUN apt-get install gcc g++ make cmake python3 python3-pip ffmpeg -y
|
|
||||||
|
|
||||||
# RUN npm i -g yarn --force
|
RUN apk add --update-cache build-base python3 libheif vips-dev vips ffmpeg
|
||||||
|
|
||||||
# RUN yarn install --only=production
|
RUN npm install --only=production
|
||||||
|
|
||||||
# COPY . .
|
COPY . .
|
||||||
|
|
||||||
# COPY --from=development /usr/src/app/dist ./dist
|
COPY --from=development /usr/src/app/dist ./dist
|
||||||
|
|
||||||
# # Clean up commands
|
CMD ["node", "dist/main"]
|
||||||
# RUN apt-get autoremove -y && apt-get clean && \
|
|
||||||
# rm -rf /usr/local/src/*
|
|
||||||
|
|
||||||
# RUN apt-get clean && \
|
|
||||||
# rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
|
|
||||||
# CMD ["node", "dist/main"]
|
|
||||||
@@ -2,21 +2,18 @@ version: '3.8'
|
|||||||
|
|
||||||
|
|
||||||
services:
|
services:
|
||||||
server:
|
immich_server:
|
||||||
container_name: immich_server
|
|
||||||
image: immich-server-dev:1.0.0
|
image: immich-server-dev:1.0.0
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
target: development
|
target: development
|
||||||
dockerfile: ./Dockerfile
|
dockerfile: ./Dockerfile
|
||||||
command: npm run start:dev
|
command: npm run start:dev
|
||||||
ports:
|
expose:
|
||||||
- "3000:3000"
|
- "3000"
|
||||||
# expose:
|
|
||||||
# - 3000
|
|
||||||
volumes:
|
volumes:
|
||||||
- .:/usr/src/app
|
- .:/usr/src/app
|
||||||
- userdata:/usr/src/app/upload
|
- ${UPLOAD_LOCATION}:/usr/src/app/upload
|
||||||
- /usr/src/app/node_modules
|
- /usr/src/app/node_modules
|
||||||
env_file:
|
env_file:
|
||||||
- .env
|
- .env
|
||||||
@@ -62,10 +59,9 @@ services:
|
|||||||
networks:
|
networks:
|
||||||
- immich_network
|
- immich_network
|
||||||
depends_on:
|
depends_on:
|
||||||
- server
|
- immich_server
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
immich_network:
|
immich_network:
|
||||||
volumes:
|
volumes:
|
||||||
pgdata:
|
pgdata:
|
||||||
userdata:
|
|
||||||
1247
server/package-lock.json
generated
1247
server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -30,17 +30,16 @@
|
|||||||
"@nestjs/passport": "^8.1.0",
|
"@nestjs/passport": "^8.1.0",
|
||||||
"@nestjs/platform-express": "^8.0.0",
|
"@nestjs/platform-express": "^8.0.0",
|
||||||
"@nestjs/platform-fastify": "^8.2.6",
|
"@nestjs/platform-fastify": "^8.2.6",
|
||||||
|
"@nestjs/platform-socket.io": "^8.2.6",
|
||||||
"@nestjs/typeorm": "^8.0.3",
|
"@nestjs/typeorm": "^8.0.3",
|
||||||
"@tensorflow-models/coco-ssd": "^2.2.2",
|
"@nestjs/websockets": "^8.2.6",
|
||||||
"@tensorflow/tfjs": "^3.13.0",
|
"@socket.io/redis-adapter": "^7.1.0",
|
||||||
"@tensorflow/tfjs-converter": "^3.13.0",
|
|
||||||
"@tensorflow/tfjs-core": "^3.13.0",
|
|
||||||
"@tensorflow/tfjs-node": "^3.13.0",
|
|
||||||
"bcrypt": "^5.0.1",
|
"bcrypt": "^5.0.1",
|
||||||
"bull": "^4.4.0",
|
"bull": "^4.4.0",
|
||||||
"class-transformer": "^0.5.1",
|
"class-transformer": "^0.5.1",
|
||||||
"class-validator": "^0.13.2",
|
"class-validator": "^0.13.2",
|
||||||
"dotenv": "^14.2.0",
|
"dotenv": "^14.2.0",
|
||||||
|
"exifr": "^7.1.3",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
"joi": "^17.5.0",
|
"joi": "^17.5.0",
|
||||||
"lodash": "^4.17.21",
|
"lodash": "^4.17.21",
|
||||||
@@ -50,7 +49,7 @@
|
|||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rimraf": "^3.0.2",
|
"rimraf": "^3.0.2",
|
||||||
"rxjs": "^7.2.0",
|
"rxjs": "^7.2.0",
|
||||||
"sharp": "^0.29.3",
|
"sharp": "0.28",
|
||||||
"systeminformation": "^5.11.0",
|
"systeminformation": "^5.11.0",
|
||||||
"typeorm": "^0.2.41"
|
"typeorm": "^0.2.41"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,15 @@
|
|||||||
|
|
||||||
|
map $http_upgrade $connection_upgrade {
|
||||||
|
default upgrade;
|
||||||
|
'' close;
|
||||||
|
}
|
||||||
|
|
||||||
|
# events {
|
||||||
|
# worker_connections 1000;
|
||||||
|
# }
|
||||||
|
|
||||||
server {
|
server {
|
||||||
|
|
||||||
client_max_body_size 50000M;
|
client_max_body_size 50000M;
|
||||||
|
|
||||||
listen 80;
|
listen 80;
|
||||||
@@ -10,11 +21,15 @@ server {
|
|||||||
proxy_buffers 64 4k;
|
proxy_buffers 64 4k;
|
||||||
proxy_force_ranges on;
|
proxy_force_ranges on;
|
||||||
|
|
||||||
|
proxy_http_version 1.1;
|
||||||
proxy_set_header Host $host;
|
proxy_set_header Host $host;
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
proxy_set_header X-Real-IP $remote_addr;
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
proxy_set_header X-Forwarded-Proto $scheme;
|
||||||
|
proxy_set_header Upgrade $http_upgrade;
|
||||||
|
proxy_set_header Connection "upgrade";
|
||||||
|
proxy_set_header Host $host;
|
||||||
|
|
||||||
proxy_pass http://immich_server:3000;
|
proxy_pass http://immich_server:3000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,33 +12,30 @@ import {
|
|||||||
Query,
|
Query,
|
||||||
Response,
|
Response,
|
||||||
Headers,
|
Headers,
|
||||||
BadRequestException,
|
Delete,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
|
import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard';
|
||||||
import { AssetService } from './asset.service';
|
import { AssetService } from './asset.service';
|
||||||
import { FileInterceptor, FilesInterceptor } from '@nestjs/platform-express';
|
import { FilesInterceptor } from '@nestjs/platform-express';
|
||||||
import { multerOption } from '../../config/multer-option.config';
|
import { multerOption } from '../../config/multer-option.config';
|
||||||
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
|
import { AuthUserDto, GetAuthUser } from '../../decorators/auth-user.decorator';
|
||||||
import { CreateAssetDto } from './dto/create-asset.dto';
|
import { CreateAssetDto } from './dto/create-asset.dto';
|
||||||
import { createReadStream } from 'fs';
|
|
||||||
import { ServeFileDto } from './dto/serve-file.dto';
|
import { ServeFileDto } from './dto/serve-file.dto';
|
||||||
import { AssetOptimizeService } from '../../modules/image-optimize/image-optimize.service';
|
import { AssetOptimizeService } from '../../modules/image-optimize/image-optimize.service';
|
||||||
import { AssetType } from './entities/asset.entity';
|
import { AssetEntity, AssetType } from './entities/asset.entity';
|
||||||
import { GetAllAssetQueryDto } from './dto/get-all-asset-query.dto';
|
import { GetAllAssetQueryDto } from './dto/get-all-asset-query.dto';
|
||||||
import { Response as Res } from 'express';
|
import { Response as Res } from 'express';
|
||||||
import { promisify } from 'util';
|
|
||||||
import { stat } from 'fs';
|
|
||||||
import { pipeline } from 'stream';
|
|
||||||
import { GetNewAssetQueryDto } from './dto/get-new-asset-query.dto';
|
import { GetNewAssetQueryDto } from './dto/get-new-asset-query.dto';
|
||||||
|
import { BackgroundTaskService } from '../../modules/background-task/background-task.service';
|
||||||
const fileInfo = promisify(stat);
|
import { DeleteAssetDto } from './dto/delete-asset.dto';
|
||||||
|
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Controller('asset')
|
@Controller('asset')
|
||||||
export class AssetController {
|
export class AssetController {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly assetService: AssetService,
|
private assetService: AssetService,
|
||||||
private readonly assetOptimizeService: AssetOptimizeService,
|
private assetOptimizeService: AssetOptimizeService,
|
||||||
|
private backgroundTaskService: BackgroundTaskService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Post('upload')
|
@Post('upload')
|
||||||
@@ -53,6 +50,7 @@ export class AssetController {
|
|||||||
|
|
||||||
if (savedAsset && savedAsset.type == AssetType.IMAGE) {
|
if (savedAsset && savedAsset.type == AssetType.IMAGE) {
|
||||||
await this.assetOptimizeService.resizeImage(savedAsset);
|
await this.assetOptimizeService.resizeImage(savedAsset);
|
||||||
|
await this.backgroundTaskService.extractExif(savedAsset, file.originalname, file.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedAsset && savedAsset.type == AssetType.VIDEO) {
|
if (savedAsset && savedAsset.type == AssetType.VIDEO) {
|
||||||
@@ -70,75 +68,7 @@ export class AssetController {
|
|||||||
@Response({ passthrough: true }) res: Res,
|
@Response({ passthrough: true }) res: Res,
|
||||||
@Query(ValidationPipe) query: ServeFileDto,
|
@Query(ValidationPipe) query: ServeFileDto,
|
||||||
): Promise<StreamableFile> {
|
): Promise<StreamableFile> {
|
||||||
let file = null;
|
return this.assetService.serveFile(authUser, query, res, headers);
|
||||||
const asset = await this.assetService.findOne(authUser, query.did, query.aid);
|
|
||||||
|
|
||||||
// Handle Sending Images
|
|
||||||
if (asset.type == AssetType.IMAGE || query.isThumb == 'true') {
|
|
||||||
res.set({
|
|
||||||
'Content-Type': asset.mimeType,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (query.isThumb === 'false' || !query.isThumb) {
|
|
||||||
file = createReadStream(asset.originalPath);
|
|
||||||
} else {
|
|
||||||
file = createReadStream(asset.resizePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new StreamableFile(file);
|
|
||||||
} else if (asset.type == AssetType.VIDEO) {
|
|
||||||
// Handle Handling Video
|
|
||||||
const { size } = await fileInfo(asset.originalPath);
|
|
||||||
const range = headers.range;
|
|
||||||
|
|
||||||
if (range) {
|
|
||||||
/** Extracting Start and End value from Range Header */
|
|
||||||
let [start, end] = range.replace(/bytes=/, '').split('-');
|
|
||||||
start = parseInt(start, 10);
|
|
||||||
end = end ? parseInt(end, 10) : size - 1;
|
|
||||||
|
|
||||||
if (!isNaN(start) && isNaN(end)) {
|
|
||||||
start = start;
|
|
||||||
end = size - 1;
|
|
||||||
}
|
|
||||||
if (isNaN(start) && !isNaN(end)) {
|
|
||||||
start = size - end;
|
|
||||||
end = size - 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle unavailable range request
|
|
||||||
if (start >= size || end >= size) {
|
|
||||||
console.error('Bad Request');
|
|
||||||
// Return the 416 Range Not Satisfiable.
|
|
||||||
res.status(416).set({
|
|
||||||
'Content-Range': `bytes */${size}`,
|
|
||||||
});
|
|
||||||
|
|
||||||
throw new BadRequestException('Bad Request Range');
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Sending Partial Content With HTTP Code 206 */
|
|
||||||
|
|
||||||
res.status(206).set({
|
|
||||||
'Content-Range': `bytes ${start}-${end}/${size}`,
|
|
||||||
'Accept-Ranges': 'bytes',
|
|
||||||
'Content-Length': end - start + 1,
|
|
||||||
'Content-Type': asset.mimeType,
|
|
||||||
});
|
|
||||||
|
|
||||||
const videoStream = createReadStream(asset.originalPath, { start: start, end: end });
|
|
||||||
|
|
||||||
return new StreamableFile(videoStream);
|
|
||||||
} else {
|
|
||||||
res.set({
|
|
||||||
'Content-Type': asset.mimeType,
|
|
||||||
});
|
|
||||||
|
|
||||||
return new StreamableFile(createReadStream(asset.originalPath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log('SHOULD NOT BE HERE');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('/new')
|
@Get('/new')
|
||||||
@@ -151,8 +81,38 @@ export class AssetController {
|
|||||||
return await this.assetService.getAllAssets(authUser, query);
|
return await this.assetService.getAllAssets(authUser, query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/')
|
||||||
|
async getAllAssetsNoPagination(@GetAuthUser() authUser: AuthUserDto) {
|
||||||
|
return await this.assetService.getAllAssetsNoPagination(authUser);
|
||||||
|
}
|
||||||
|
|
||||||
@Get('/:deviceId')
|
@Get('/:deviceId')
|
||||||
async getUserAssetsByDeviceId(@GetAuthUser() authUser: AuthUserDto, @Param('deviceId') deviceId: string) {
|
async getUserAssetsByDeviceId(@GetAuthUser() authUser: AuthUserDto, @Param('deviceId') deviceId: string) {
|
||||||
return await this.assetService.getUserAssetsByDeviceId(authUser, deviceId);
|
return await this.assetService.getUserAssetsByDeviceId(authUser, deviceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('/assetById/:assetId')
|
||||||
|
async getAssetById(@GetAuthUser() authUser: AuthUserDto, @Param('assetId') assetId) {
|
||||||
|
return this.assetService.getAssetById(authUser, assetId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Delete('/')
|
||||||
|
async deleteAssetById(@GetAuthUser() authUser: AuthUserDto, @Body(ValidationPipe) assetIds: DeleteAssetDto) {
|
||||||
|
const deleteAssetList: AssetEntity[] = [];
|
||||||
|
|
||||||
|
assetIds.ids.forEach(async (id) => {
|
||||||
|
const assets = await this.assetService.getAssetById(authUser, id);
|
||||||
|
deleteAssetList.push(assets);
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await this.assetService.deleteAssetById(authUser, assetIds);
|
||||||
|
|
||||||
|
result.forEach((res) => {
|
||||||
|
deleteAssetList.filter((a) => a.id == res.id && res.status == 'success');
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.backgroundTaskService.deleteFileOnDisk(deleteAssetList);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import { AssetEntity } from './entities/asset.entity';
|
|||||||
import { ImageOptimizeModule } from '../../modules/image-optimize/image-optimize.module';
|
import { ImageOptimizeModule } from '../../modules/image-optimize/image-optimize.module';
|
||||||
import { AssetOptimizeService } from '../../modules/image-optimize/image-optimize.service';
|
import { AssetOptimizeService } from '../../modules/image-optimize/image-optimize.service';
|
||||||
import { BullModule } from '@nestjs/bull';
|
import { BullModule } from '@nestjs/bull';
|
||||||
|
import { BackgroundTaskModule } from '../../modules/background-task/background-task.module';
|
||||||
|
import { BackgroundTaskService } from '../../modules/background-task/background-task.service';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -18,7 +20,7 @@ import { BullModule } from '@nestjs/bull';
|
|||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
BullModule.registerQueue({
|
BullModule.registerQueue({
|
||||||
name: 'machine-learning',
|
name: 'background-task',
|
||||||
defaultJobOptions: {
|
defaultJobOptions: {
|
||||||
attempts: 3,
|
attempts: 3,
|
||||||
removeOnComplete: true,
|
removeOnComplete: true,
|
||||||
@@ -27,9 +29,10 @@ import { BullModule } from '@nestjs/bull';
|
|||||||
}),
|
}),
|
||||||
TypeOrmModule.forFeature([AssetEntity]),
|
TypeOrmModule.forFeature([AssetEntity]),
|
||||||
ImageOptimizeModule,
|
ImageOptimizeModule,
|
||||||
|
BackgroundTaskModule,
|
||||||
],
|
],
|
||||||
controllers: [AssetController],
|
controllers: [AssetController],
|
||||||
providers: [AssetService, AssetOptimizeService],
|
providers: [AssetService, AssetOptimizeService, BackgroundTaskService],
|
||||||
exports: [],
|
exports: [],
|
||||||
})
|
})
|
||||||
export class AssetModule {}
|
export class AssetModule {}
|
||||||
|
|||||||
@@ -1,14 +1,20 @@
|
|||||||
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
import { BadRequestException, Injectable, Logger, StreamableFile } from '@nestjs/common';
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
import { MoreThan, Repository } from 'typeorm';
|
import { MoreThan, Repository } from 'typeorm';
|
||||||
import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
||||||
import { CreateAssetDto } from './dto/create-asset.dto';
|
import { CreateAssetDto } from './dto/create-asset.dto';
|
||||||
import { UpdateAssetDto } from './dto/update-asset.dto';
|
import { UpdateAssetDto } from './dto/update-asset.dto';
|
||||||
import { AssetEntity, AssetType } from './entities/asset.entity';
|
import { AssetEntity, AssetType } from './entities/asset.entity';
|
||||||
import _ from 'lodash';
|
import _, { result } from 'lodash';
|
||||||
import { GetAllAssetQueryDto } from './dto/get-all-asset-query.dto';
|
import { GetAllAssetQueryDto } from './dto/get-all-asset-query.dto';
|
||||||
import { GetAllAssetReponseDto } from './dto/get-all-asset-response.dto';
|
import { GetAllAssetReponseDto } from './dto/get-all-asset-response.dto';
|
||||||
import { Greater } from '@tensorflow/tfjs-core';
|
import { createReadStream, stat } from 'fs';
|
||||||
|
import { ServeFileDto } from './dto/serve-file.dto';
|
||||||
|
import { Response as Res } from 'express';
|
||||||
|
import { promisify } from 'util';
|
||||||
|
import { DeleteAssetDto } from './dto/delete-asset.dto';
|
||||||
|
|
||||||
|
const fileInfo = promisify(stat);
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AssetService {
|
export class AssetService {
|
||||||
@@ -53,6 +59,20 @@ export class AssetService {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getAllAssetsNoPagination(authUser: AuthUserDto) {
|
||||||
|
try {
|
||||||
|
const assets = await this.assetRepository
|
||||||
|
.createQueryBuilder('a')
|
||||||
|
.where('a."userId" = :userId', { userId: authUser.id })
|
||||||
|
.orderBy('a."createdAt"::date', 'DESC')
|
||||||
|
.getMany();
|
||||||
|
|
||||||
|
return assets;
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error(e, 'getAllAssets');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async getAllAssets(authUser: AuthUserDto, query: GetAllAssetQueryDto): Promise<GetAllAssetReponseDto> {
|
public async getAllAssets(authUser: AuthUserDto, query: GetAllAssetQueryDto): Promise<GetAllAssetReponseDto> {
|
||||||
try {
|
try {
|
||||||
const assets = await this.assetRepository
|
const assets = await this.assetRepository
|
||||||
@@ -113,4 +133,114 @@ export class AssetService {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getAssetById(authUser: AuthUserDto, assetId: string) {
|
||||||
|
return await this.assetRepository.findOne({
|
||||||
|
where: {
|
||||||
|
userId: authUser.id,
|
||||||
|
id: assetId,
|
||||||
|
},
|
||||||
|
relations: ['exifInfo'],
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public async serveFile(authUser: AuthUserDto, query: ServeFileDto, res: Res, headers: any) {
|
||||||
|
let file = null;
|
||||||
|
const asset = await this.findOne(authUser, query.did, query.aid);
|
||||||
|
|
||||||
|
// Handle Sending Images
|
||||||
|
if (asset.type == AssetType.IMAGE || query.isThumb == 'true') {
|
||||||
|
res.set({
|
||||||
|
'Content-Type': asset.mimeType,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (query.isThumb === 'false' || !query.isThumb) {
|
||||||
|
file = createReadStream(asset.originalPath);
|
||||||
|
} else {
|
||||||
|
file = createReadStream(asset.resizePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
file.on('error', (error) => {
|
||||||
|
Logger.log(`Cannot create read stream ${error}`);
|
||||||
|
return new BadRequestException('Cannot Create Read Stream');
|
||||||
|
});
|
||||||
|
return new StreamableFile(file);
|
||||||
|
} else if (asset.type == AssetType.VIDEO) {
|
||||||
|
// Handle Handling Video
|
||||||
|
const { size } = await fileInfo(asset.originalPath);
|
||||||
|
const range = headers.range;
|
||||||
|
|
||||||
|
if (range) {
|
||||||
|
/** Extracting Start and End value from Range Header */
|
||||||
|
let [start, end] = range.replace(/bytes=/, '').split('-');
|
||||||
|
start = parseInt(start, 10);
|
||||||
|
end = end ? parseInt(end, 10) : size - 1;
|
||||||
|
|
||||||
|
if (!isNaN(start) && isNaN(end)) {
|
||||||
|
start = start;
|
||||||
|
end = size - 1;
|
||||||
|
}
|
||||||
|
if (isNaN(start) && !isNaN(end)) {
|
||||||
|
start = size - end;
|
||||||
|
end = size - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle unavailable range request
|
||||||
|
if (start >= size || end >= size) {
|
||||||
|
console.error('Bad Request');
|
||||||
|
// Return the 416 Range Not Satisfiable.
|
||||||
|
res.status(416).set({
|
||||||
|
'Content-Range': `bytes */${size}`,
|
||||||
|
});
|
||||||
|
|
||||||
|
throw new BadRequestException('Bad Request Range');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sending Partial Content With HTTP Code 206 */
|
||||||
|
|
||||||
|
res.status(206).set({
|
||||||
|
'Content-Range': `bytes ${start}-${end}/${size}`,
|
||||||
|
'Accept-Ranges': 'bytes',
|
||||||
|
'Content-Length': end - start + 1,
|
||||||
|
'Content-Type': asset.mimeType,
|
||||||
|
});
|
||||||
|
|
||||||
|
const videoStream = createReadStream(asset.originalPath, { start: start, end: end });
|
||||||
|
|
||||||
|
return new StreamableFile(videoStream);
|
||||||
|
} else {
|
||||||
|
res.set({
|
||||||
|
'Content-Type': asset.mimeType,
|
||||||
|
});
|
||||||
|
|
||||||
|
return new StreamableFile(createReadStream(asset.originalPath));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public async deleteAssetById(authUser: AuthUserDto, assetIds: DeleteAssetDto) {
|
||||||
|
let result = [];
|
||||||
|
|
||||||
|
const target = assetIds.ids;
|
||||||
|
for (let assetId of target) {
|
||||||
|
const res = await this.assetRepository.delete({
|
||||||
|
id: assetId,
|
||||||
|
userId: authUser.id,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (res.affected) {
|
||||||
|
result.push({
|
||||||
|
id: assetId,
|
||||||
|
status: 'success',
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
result.push({
|
||||||
|
id: assetId,
|
||||||
|
status: 'failed',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
48
server/src/api-v1/asset/dto/create-exif.dto.ts
Normal file
48
server/src/api-v1/asset/dto/create-exif.dto.ts
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
import { IsNotEmpty, IsOptional } from 'class-validator';
|
||||||
|
|
||||||
|
export class CreateExifDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
assetId: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
make: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
model: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
imageName: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
exifImageWidth: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
exifImageHeight: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
fileSizeInByte: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
orientation: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
dateTimeOriginal: Date;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
modifiedDate: Date;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
lensModel: string;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
fNumber: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
focalLenght: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
iso: number;
|
||||||
|
|
||||||
|
@IsOptional()
|
||||||
|
exposureTime: number;
|
||||||
|
}
|
||||||
6
server/src/api-v1/asset/dto/delete-asset.dto.ts
Normal file
6
server/src/api-v1/asset/dto/delete-asset.dto.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { IsNotEmpty } from 'class-validator';
|
||||||
|
|
||||||
|
export class DeleteAssetDto {
|
||||||
|
@IsNotEmpty()
|
||||||
|
ids: string[];
|
||||||
|
}
|
||||||
4
server/src/api-v1/asset/dto/update-exif.dto.ts
Normal file
4
server/src/api-v1/asset/dto/update-exif.dto.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { PartialType } from '@nestjs/mapped-types';
|
||||||
|
import { CreateExifDto } from './create-exif.dto';
|
||||||
|
|
||||||
|
export class UpdateExifDto extends PartialType(CreateExifDto) {}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Column, Entity, PrimaryColumn, PrimaryGeneratedColumn, Unique } from 'typeorm';
|
import { Column, Entity, JoinColumn, OneToOne, PrimaryColumn, PrimaryGeneratedColumn, Unique } from 'typeorm';
|
||||||
|
import { ExifEntity } from './exif.entity';
|
||||||
|
|
||||||
@Entity('assets')
|
@Entity('assets')
|
||||||
@Unique(['deviceAssetId', 'userId', 'deviceId'])
|
@Unique(['deviceAssetId', 'userId', 'deviceId'])
|
||||||
@@ -38,6 +39,9 @@ export class AssetEntity {
|
|||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
duration: string;
|
duration: string;
|
||||||
|
|
||||||
|
@OneToOne(() => ExifEntity, (exifEntity) => exifEntity.asset)
|
||||||
|
exifInfo: ExifEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AssetType {
|
export enum AssetType {
|
||||||
|
|||||||
67
server/src/api-v1/asset/entities/exif.entity.ts
Normal file
67
server/src/api-v1/asset/entities/exif.entity.ts
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
import { Index, JoinColumn, OneToOne } from 'typeorm';
|
||||||
|
import { Column } from 'typeorm/decorator/columns/Column';
|
||||||
|
import { PrimaryGeneratedColumn } from 'typeorm/decorator/columns/PrimaryGeneratedColumn';
|
||||||
|
import { Entity } from 'typeorm/decorator/entity/Entity';
|
||||||
|
import { AssetEntity } from './asset.entity';
|
||||||
|
|
||||||
|
@Entity('exif')
|
||||||
|
export class ExifEntity {
|
||||||
|
@PrimaryGeneratedColumn()
|
||||||
|
id: string;
|
||||||
|
|
||||||
|
@Index({ unique: true })
|
||||||
|
@Column({ type: 'uuid' })
|
||||||
|
assetId: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
make: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
model: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
imageName: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
exifImageWidth: number;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
exifImageHeight: number;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
fileSizeInByte: number;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
orientation: string;
|
||||||
|
|
||||||
|
@Column({ type: 'timestamptz', nullable: true })
|
||||||
|
dateTimeOriginal: Date;
|
||||||
|
|
||||||
|
@Column({ type: 'timestamptz', nullable: true })
|
||||||
|
modifyDate: Date;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
lensModel: string;
|
||||||
|
|
||||||
|
@Column({ type: 'float8', nullable: true })
|
||||||
|
fNumber: number;
|
||||||
|
|
||||||
|
@Column({ type: 'float8', nullable: true })
|
||||||
|
focalLength: number;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
iso: number;
|
||||||
|
|
||||||
|
@Column({ type: 'float', nullable: true })
|
||||||
|
exposureTime: number;
|
||||||
|
|
||||||
|
@Column({ type: 'float', nullable: true })
|
||||||
|
latitude: number;
|
||||||
|
|
||||||
|
@Column({ type: 'float', nullable: true })
|
||||||
|
longitude: number;
|
||||||
|
|
||||||
|
@OneToOne(() => AssetEntity, { onDelete: 'CASCADE', nullable: true })
|
||||||
|
@JoinColumn({ name: 'assetId', referencedColumnName: 'id' })
|
||||||
|
asset: ExifEntity;
|
||||||
|
}
|
||||||
47
server/src/api-v1/communication/communication.gateway.ts
Normal file
47
server/src/api-v1/communication/communication.gateway.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { OnGatewayConnection, OnGatewayDisconnect, WebSocketGateway, WebSocketServer } from '@nestjs/websockets';
|
||||||
|
import { CommunicationService } from './communication.service';
|
||||||
|
import { Socket, Server } from 'socket.io';
|
||||||
|
import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service';
|
||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { UserEntity } from '../user/entities/user.entity';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
|
||||||
|
@WebSocketGateway()
|
||||||
|
export class CommunicationGateway implements OnGatewayConnection, OnGatewayDisconnect {
|
||||||
|
constructor(
|
||||||
|
private immichJwtService: ImmichJwtService,
|
||||||
|
|
||||||
|
@InjectRepository(UserEntity)
|
||||||
|
private userRepository: Repository<UserEntity>,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@WebSocketServer() server: Server;
|
||||||
|
|
||||||
|
handleDisconnect(client: Socket) {
|
||||||
|
client.leave(client.nsp.name);
|
||||||
|
|
||||||
|
Logger.log(`Client ${client.id} disconnected`);
|
||||||
|
}
|
||||||
|
|
||||||
|
async handleConnection(client: Socket, ...args: any[]) {
|
||||||
|
Logger.log(`New websocket connection: ${client.id}`, 'NewWebSocketConnection');
|
||||||
|
const accessToken = client.handshake.headers.authorization.split(' ')[1];
|
||||||
|
const res = await this.immichJwtService.validateToken(accessToken);
|
||||||
|
|
||||||
|
if (!res.status) {
|
||||||
|
client.emit('error', 'unauthorized');
|
||||||
|
client.disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = await this.userRepository.findOne({ where: { id: res.userId } });
|
||||||
|
if (!user) {
|
||||||
|
client.emit('error', 'unauthorized');
|
||||||
|
client.disconnect();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
client.join(user.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
16
server/src/api-v1/communication/communication.module.ts
Normal file
16
server/src/api-v1/communication/communication.module.ts
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { CommunicationService } from './communication.service';
|
||||||
|
import { CommunicationGateway } from './communication.gateway';
|
||||||
|
import { ImmichJwtModule } from '../../modules/immich-jwt/immich-jwt.module';
|
||||||
|
import { ImmichJwtService } from '../../modules/immich-jwt/immich-jwt.service';
|
||||||
|
import { JwtModule } from '@nestjs/jwt';
|
||||||
|
import { jwtConfig } from '../../config/jwt.config';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { UserEntity } from '../user/entities/user.entity';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [TypeOrmModule.forFeature([UserEntity]), ImmichJwtModule, JwtModule.register(jwtConfig)],
|
||||||
|
providers: [CommunicationGateway, CommunicationService, ImmichJwtService],
|
||||||
|
exports: [CommunicationGateway],
|
||||||
|
})
|
||||||
|
export class CommunicationModule {}
|
||||||
4
server/src/api-v1/communication/communication.service.ts
Normal file
4
server/src/api-v1/communication/communication.service.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CommunicationService {}
|
||||||
@@ -16,16 +16,7 @@ export class UserService {
|
|||||||
return 'This action adds a new user';
|
return 'This action adds a new user';
|
||||||
}
|
}
|
||||||
|
|
||||||
async findAll() {
|
async findAll() {}
|
||||||
try {
|
|
||||||
return 'welcome';
|
|
||||||
// return await this.userRepository.find();
|
|
||||||
// return await this.userRepository.query('select * from users');
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
// return 'helloworld';
|
|
||||||
}
|
|
||||||
|
|
||||||
findOne(id: number) {
|
findOne(id: number) {
|
||||||
return `This action returns a #${id} user`;
|
return `This action returns a #${id} user`;
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ import { immichAppConfig } from './config/app.config';
|
|||||||
import { BullModule } from '@nestjs/bull';
|
import { BullModule } from '@nestjs/bull';
|
||||||
import { ImageOptimizeModule } from './modules/image-optimize/image-optimize.module';
|
import { ImageOptimizeModule } from './modules/image-optimize/image-optimize.module';
|
||||||
import { ServerInfoModule } from './api-v1/server-info/server-info.module';
|
import { ServerInfoModule } from './api-v1/server-info/server-info.module';
|
||||||
|
import { BackgroundTaskModule } from './modules/background-task/background-task.module';
|
||||||
|
import { CommunicationModule } from './api-v1/communication/communication.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -29,7 +31,6 @@ import { ServerInfoModule } from './api-v1/server-info/server-info.module';
|
|||||||
redis: {
|
redis: {
|
||||||
host: 'immich_redis',
|
host: 'immich_redis',
|
||||||
port: 6379,
|
port: 6379,
|
||||||
// password: configService.get('REDIS_PASSWORD'),
|
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
@@ -38,6 +39,10 @@ import { ServerInfoModule } from './api-v1/server-info/server-info.module';
|
|||||||
ImageOptimizeModule,
|
ImageOptimizeModule,
|
||||||
|
|
||||||
ServerInfoModule,
|
ServerInfoModule,
|
||||||
|
|
||||||
|
BackgroundTaskModule,
|
||||||
|
|
||||||
|
CommunicationModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
|||||||
@@ -4,14 +4,15 @@ import { existsSync, mkdirSync } from 'fs';
|
|||||||
import { diskStorage } from 'multer';
|
import { diskStorage } from 'multer';
|
||||||
import { extname } from 'path';
|
import { extname } from 'path';
|
||||||
import { Request } from 'express';
|
import { Request } from 'express';
|
||||||
|
import { APP_UPLOAD_LOCATION } from '../constants/upload_location.constant';
|
||||||
|
|
||||||
export const multerConfig = {
|
export const multerConfig = {
|
||||||
dest: process.env.UPLOAD_LOCATION,
|
dest: APP_UPLOAD_LOCATION,
|
||||||
};
|
};
|
||||||
|
|
||||||
export const multerOption: MulterOptions = {
|
export const multerOption: MulterOptions = {
|
||||||
fileFilter: (req: Request, file: any, cb: any) => {
|
fileFilter: (req: Request, file: any, cb: any) => {
|
||||||
if (file.mimetype.match(/\/(jpg|jpeg|png|gif|mp4|x-msvideo|quicktime)$/)) {
|
if (file.mimetype.match(/\/(jpg|jpeg|png|gif|mp4|x-msvideo|quicktime|heic|heif)$/)) {
|
||||||
cb(null, true);
|
cb(null, true);
|
||||||
} else {
|
} else {
|
||||||
cb(new HttpException(`Unsupported file type ${extname(file.originalname)}`, HttpStatus.BAD_REQUEST), false);
|
cb(new HttpException(`Unsupported file type ${extname(file.originalname)}`, HttpStatus.BAD_REQUEST), false);
|
||||||
|
|||||||
1
server/src/constants/upload_location.constant.ts
Normal file
1
server/src/constants/upload_location.constant.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
export const APP_UPLOAD_LOCATION = './upload';
|
||||||
@@ -1,11 +1,15 @@
|
|||||||
import { NestFactory } from '@nestjs/core';
|
import { NestFactory } from '@nestjs/core';
|
||||||
import { NestExpressApplication } from '@nestjs/platform-express';
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import { RedisIoAdapter } from './middlewares/redis-io.adapter.middleware';
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
const app = await NestFactory.create<NestExpressApplication>(AppModule);
|
||||||
|
|
||||||
app.set('trust proxy');
|
app.set('trust proxy');
|
||||||
|
|
||||||
|
app.useWebSocketAdapter(new RedisIoAdapter(app));
|
||||||
|
|
||||||
await app.listen(3000);
|
await app.listen(3000);
|
||||||
}
|
}
|
||||||
bootstrap();
|
bootstrap();
|
||||||
|
|||||||
15
server/src/middlewares/redis-io.adapter.middleware.ts
Normal file
15
server/src/middlewares/redis-io.adapter.middleware.ts
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
import { IoAdapter } from '@nestjs/platform-socket.io';
|
||||||
|
import { RedisClient, createClient } from 'redis';
|
||||||
|
import { ServerOptions } from 'socket.io';
|
||||||
|
import { createAdapter } from '@socket.io/redis-adapter';
|
||||||
|
|
||||||
|
const pubClient = createClient({ url: 'redis://immich_redis:6379' });
|
||||||
|
const subClient = pubClient.duplicate();
|
||||||
|
|
||||||
|
export class RedisIoAdapter extends IoAdapter {
|
||||||
|
createIOServer(port: number, options?: ServerOptions): any {
|
||||||
|
const server = super.createIOServer(port, options);
|
||||||
|
server.adapter(createAdapter(pubClient, subClient));
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
server/src/modules/background-task/background-task.module.ts
Normal file
24
server/src/modules/background-task/background-task.module.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { BullModule } from '@nestjs/bull';
|
||||||
|
import { Module } from '@nestjs/common';
|
||||||
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
||||||
|
import { ExifEntity } from '../../api-v1/asset/entities/exif.entity';
|
||||||
|
import { BackgroundTaskProcessor } from './background-task.processor';
|
||||||
|
import { BackgroundTaskService } from './background-task.service';
|
||||||
|
|
||||||
|
@Module({
|
||||||
|
imports: [
|
||||||
|
BullModule.registerQueue({
|
||||||
|
name: 'background-task',
|
||||||
|
defaultJobOptions: {
|
||||||
|
attempts: 3,
|
||||||
|
removeOnComplete: true,
|
||||||
|
removeOnFail: false,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
TypeOrmModule.forFeature([AssetEntity, ExifEntity]),
|
||||||
|
],
|
||||||
|
providers: [BackgroundTaskService, BackgroundTaskProcessor],
|
||||||
|
exports: [BackgroundTaskService],
|
||||||
|
})
|
||||||
|
export class BackgroundTaskModule {}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import { InjectQueue, Process, Processor } from '@nestjs/bull';
|
||||||
|
import { InjectRepository } from '@nestjs/typeorm';
|
||||||
|
import { Job, Queue } from 'bull';
|
||||||
|
import { Repository } from 'typeorm';
|
||||||
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import exifr from 'exifr';
|
||||||
|
import { readFile } from 'fs/promises';
|
||||||
|
import fs from 'fs';
|
||||||
|
import { Logger } from '@nestjs/common';
|
||||||
|
import { ExifEntity } from '../../api-v1/asset/entities/exif.entity';
|
||||||
|
|
||||||
|
@Processor('background-task')
|
||||||
|
export class BackgroundTaskProcessor {
|
||||||
|
constructor(
|
||||||
|
@InjectRepository(AssetEntity)
|
||||||
|
private assetRepository: Repository<AssetEntity>,
|
||||||
|
|
||||||
|
@InjectRepository(ExifEntity)
|
||||||
|
private exifRepository: Repository<ExifEntity>,
|
||||||
|
|
||||||
|
private configService: ConfigService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@Process('extract-exif')
|
||||||
|
async extractExif(job: Job) {
|
||||||
|
const { savedAsset, fileName, fileSize }: { savedAsset: AssetEntity; fileName: string; fileSize: number } =
|
||||||
|
job.data;
|
||||||
|
|
||||||
|
const fileBuffer = await readFile(savedAsset.originalPath);
|
||||||
|
|
||||||
|
const exifData = await exifr.parse(fileBuffer);
|
||||||
|
|
||||||
|
const newExif = new ExifEntity();
|
||||||
|
newExif.assetId = savedAsset.id;
|
||||||
|
newExif.make = exifData['Make'] || null;
|
||||||
|
newExif.model = exifData['Model'] || null;
|
||||||
|
newExif.imageName = fileName || null;
|
||||||
|
newExif.exifImageHeight = exifData['ExifImageHeight'] || null;
|
||||||
|
newExif.exifImageWidth = exifData['ExifImageWidth'] || null;
|
||||||
|
newExif.fileSizeInByte = fileSize || null;
|
||||||
|
newExif.orientation = exifData['Orientation'] || null;
|
||||||
|
newExif.dateTimeOriginal = exifData['DateTimeOriginal'] || null;
|
||||||
|
newExif.modifyDate = exifData['ModifyDate'] || null;
|
||||||
|
newExif.lensModel = exifData['LensModel'] || null;
|
||||||
|
newExif.fNumber = exifData['FNumber'] || null;
|
||||||
|
newExif.focalLength = exifData['FocalLength'] || null;
|
||||||
|
newExif.iso = exifData['ISO'] || null;
|
||||||
|
newExif.exposureTime = exifData['ExposureTime'] || null;
|
||||||
|
newExif.latitude = exifData['latitude'] || null;
|
||||||
|
newExif.longitude = exifData['longitude'] || null;
|
||||||
|
|
||||||
|
await this.exifRepository.save(newExif);
|
||||||
|
|
||||||
|
try {
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error(`Error extracting EXIF ${e.toString()}`, 'extractExif');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Process('delete-file-on-disk')
|
||||||
|
async deleteFileOnDisk(job) {
|
||||||
|
const { assets }: { assets: AssetEntity[] } = job.data;
|
||||||
|
|
||||||
|
assets.forEach(async (asset) => {
|
||||||
|
fs.unlink(asset.originalPath, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('error deleting ', asset.originalPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
fs.unlink(asset.resizePath, (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log('error deleting ', asset.originalPath);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
import { InjectQueue } from '@nestjs/bull/dist/decorators';
|
||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { Queue } from 'bull';
|
||||||
|
import { randomUUID } from 'node:crypto';
|
||||||
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BackgroundTaskService {
|
||||||
|
constructor(
|
||||||
|
@InjectQueue('background-task')
|
||||||
|
private backgroundTaskQueue: Queue,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
async extractExif(savedAsset: AssetEntity, fileName: string, fileSize: number) {
|
||||||
|
await this.backgroundTaskQueue.add(
|
||||||
|
'extract-exif',
|
||||||
|
{
|
||||||
|
savedAsset,
|
||||||
|
fileName,
|
||||||
|
fileSize,
|
||||||
|
},
|
||||||
|
{ jobId: randomUUID() },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteFileOnDisk(assets: AssetEntity[]) {
|
||||||
|
await this.backgroundTaskQueue.add(
|
||||||
|
'delete-file-on-disk',
|
||||||
|
{
|
||||||
|
assets,
|
||||||
|
},
|
||||||
|
{ jobId: randomUUID() },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,12 +5,16 @@ import { join } from 'path';
|
|||||||
import { AssetModule } from '../../api-v1/asset/asset.module';
|
import { AssetModule } from '../../api-v1/asset/asset.module';
|
||||||
import { AssetService } from '../../api-v1/asset/asset.service';
|
import { AssetService } from '../../api-v1/asset/asset.service';
|
||||||
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
||||||
|
import { CommunicationGateway } from '../../api-v1/communication/communication.gateway';
|
||||||
|
import { CommunicationModule } from '../../api-v1/communication/communication.module';
|
||||||
|
import { UserEntity } from '../../api-v1/user/entities/user.entity';
|
||||||
|
import { ImmichJwtModule } from '../immich-jwt/immich-jwt.module';
|
||||||
import { ImageOptimizeProcessor } from './image-optimize.processor';
|
import { ImageOptimizeProcessor } from './image-optimize.processor';
|
||||||
import { AssetOptimizeService } from './image-optimize.service';
|
import { AssetOptimizeService } from './image-optimize.service';
|
||||||
import { MachineLearningProcessor } from './machine-learning.processor';
|
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
CommunicationModule,
|
||||||
BullModule.registerQueue({
|
BullModule.registerQueue({
|
||||||
name: 'optimize',
|
name: 'optimize',
|
||||||
defaultJobOptions: {
|
defaultJobOptions: {
|
||||||
@@ -19,18 +23,10 @@ import { MachineLearningProcessor } from './machine-learning.processor';
|
|||||||
removeOnFail: false,
|
removeOnFail: false,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
BullModule.registerQueue({
|
|
||||||
name: 'machine-learning',
|
|
||||||
defaultJobOptions: {
|
|
||||||
attempts: 3,
|
|
||||||
removeOnComplete: true,
|
|
||||||
removeOnFail: false,
|
|
||||||
},
|
|
||||||
}),
|
|
||||||
|
|
||||||
TypeOrmModule.forFeature([AssetEntity]),
|
TypeOrmModule.forFeature([AssetEntity]),
|
||||||
],
|
],
|
||||||
providers: [AssetOptimizeService, ImageOptimizeProcessor, MachineLearningProcessor],
|
providers: [AssetOptimizeService, ImageOptimizeProcessor],
|
||||||
exports: [AssetOptimizeService],
|
exports: [AssetOptimizeService],
|
||||||
})
|
})
|
||||||
export class ImageOptimizeModule {}
|
export class ImageOptimizeModule {}
|
||||||
|
|||||||
@@ -4,24 +4,27 @@ import { Job, Queue } from 'bull';
|
|||||||
import { Repository } from 'typeorm';
|
import { Repository } from 'typeorm';
|
||||||
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
||||||
import sharp from 'sharp';
|
import sharp from 'sharp';
|
||||||
import fs, { existsSync, mkdirSync } from 'fs';
|
import { existsSync, mkdirSync, readFile } from 'fs';
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
import { Logger } from '@nestjs/common';
|
import { APP_UPLOAD_LOCATION } from '../../constants/upload_location.constant';
|
||||||
|
import { WebSocketServer } from '@nestjs/websockets';
|
||||||
|
import { Socket, Server as SocketIoServer } from 'socket.io';
|
||||||
|
import { CommunicationGateway } from '../../api-v1/communication/communication.gateway';
|
||||||
|
|
||||||
@Processor('optimize')
|
@Processor('optimize')
|
||||||
export class ImageOptimizeProcessor {
|
export class ImageOptimizeProcessor {
|
||||||
constructor(
|
constructor(
|
||||||
@InjectRepository(AssetEntity) private assetRepository: Repository<AssetEntity>,
|
private wsCommunicateionGateway: CommunicationGateway,
|
||||||
@InjectQueue('machine-learning') private machineLearningQueue: Queue,
|
@InjectRepository(AssetEntity)
|
||||||
private configService: ConfigService,
|
private assetRepository: Repository<AssetEntity>,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Process('resize-image')
|
@Process('resize-image')
|
||||||
async resizeUploadedImage(job: Job) {
|
async resizeUploadedImage(job: Job) {
|
||||||
const { savedAsset }: { savedAsset: AssetEntity } = job.data;
|
const { savedAsset }: { savedAsset: AssetEntity } = job.data;
|
||||||
|
|
||||||
const basePath = this.configService.get('UPLOAD_LOCATION');
|
const basePath = APP_UPLOAD_LOCATION;
|
||||||
const resizePath = savedAsset.originalPath.replace('/original/', '/thumb/');
|
const resizePath = savedAsset.originalPath.replace('/original/', '/thumb/');
|
||||||
|
|
||||||
// Create folder for thumb image if not exist
|
// Create folder for thumb image if not exist
|
||||||
@@ -32,30 +35,52 @@ export class ImageOptimizeProcessor {
|
|||||||
mkdirSync(resizeDir, { recursive: true });
|
mkdirSync(resizeDir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(savedAsset.originalPath, (err, data) => {
|
readFile(savedAsset.originalPath, async (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error Reading File');
|
console.error('Error Reading File');
|
||||||
}
|
}
|
||||||
|
|
||||||
sharp(data)
|
if (savedAsset.mimeType == 'image/heic' || savedAsset.mimeType == 'image/heif') {
|
||||||
.resize(512, 512, { fit: 'outside' })
|
let desitnation = '';
|
||||||
.toFile(resizePath, async (err, info) => {
|
if (savedAsset.mimeType == 'image/heic') {
|
||||||
if (err) {
|
desitnation = resizePath.replace('.HEIC', '.jpeg');
|
||||||
console.error('Error resizing file ', err);
|
} else {
|
||||||
return;
|
desitnation = resizePath.replace('.HEIF', '.jpeg');
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.assetRepository.update(savedAsset, { resizePath: resizePath });
|
sharp(data)
|
||||||
|
.toFormat('jpeg')
|
||||||
|
.resize(512, 512, { fit: 'outside' })
|
||||||
|
.toFile(desitnation, async (err, info) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Error resizing file ', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Send file to object detection after resizing
|
const res = await this.assetRepository.update(savedAsset, { resizePath: desitnation });
|
||||||
// const detectionJob = await this.machineLearningQueue.add(
|
if (res.affected) {
|
||||||
// 'object-detection',
|
this.wsCommunicateionGateway.server
|
||||||
// {
|
.to(savedAsset.userId)
|
||||||
// resizePath,
|
.emit('on_upload_success', JSON.stringify(savedAsset));
|
||||||
// },
|
}
|
||||||
// { jobId: randomUUID() },
|
});
|
||||||
// );
|
} else {
|
||||||
});
|
sharp(data)
|
||||||
|
.resize(512, 512, { fit: 'outside' })
|
||||||
|
.toFile(resizePath, async (err, info) => {
|
||||||
|
if (err) {
|
||||||
|
console.error('Error resizing file ', err);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = await this.assetRepository.update(savedAsset, { resizePath: resizePath });
|
||||||
|
if (res.affected) {
|
||||||
|
this.wsCommunicateionGateway.server
|
||||||
|
.to(savedAsset.userId)
|
||||||
|
.emit('on_upload_success', JSON.stringify(savedAsset));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return 'ok';
|
return 'ok';
|
||||||
@@ -65,7 +90,7 @@ export class ImageOptimizeProcessor {
|
|||||||
async resizeUploadedVideo(job: Job) {
|
async resizeUploadedVideo(job: Job) {
|
||||||
const { savedAsset, filename }: { savedAsset: AssetEntity; filename: String } = job.data;
|
const { savedAsset, filename }: { savedAsset: AssetEntity; filename: String } = job.data;
|
||||||
|
|
||||||
const basePath = this.configService.get('UPLOAD_LOCATION');
|
const basePath = APP_UPLOAD_LOCATION;
|
||||||
// const resizePath = savedAsset.originalPath.replace('/original/', '/thumb/');
|
// const resizePath = savedAsset.originalPath.replace('/original/', '/thumb/');
|
||||||
// Create folder for thumb image if not exist
|
// Create folder for thumb image if not exist
|
||||||
const resizeDir = `${basePath}/${savedAsset.userId}/thumb/${savedAsset.deviceId}`;
|
const resizeDir = `${basePath}/${savedAsset.userId}/thumb/${savedAsset.deviceId}`;
|
||||||
@@ -82,7 +107,12 @@ export class ImageOptimizeProcessor {
|
|||||||
filename: `${filename}.png`,
|
filename: `${filename}.png`,
|
||||||
})
|
})
|
||||||
.on('end', async (a) => {
|
.on('end', async (a) => {
|
||||||
await this.assetRepository.update(savedAsset, { resizePath: `${resizeDir}/${filename}.png` });
|
const res = await this.assetRepository.update(savedAsset, { resizePath: `${resizeDir}/${filename}.png` });
|
||||||
|
if (res.affected) {
|
||||||
|
this.wsCommunicateionGateway.server
|
||||||
|
.to(savedAsset.userId)
|
||||||
|
.emit('on_upload_success', JSON.stringify(savedAsset));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return 'ok';
|
return 'ok';
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class AssetOptimizeService {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getVideoThumbnail(savedAsset: AssetEntity, filename: String) {
|
public async getVideoThumbnail(savedAsset: AssetEntity, filename: string) {
|
||||||
const job = await this.optimizeQueue.add(
|
const job = await this.optimizeQueue.add(
|
||||||
'get-video-thumbnail',
|
'get-video-thumbnail',
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
import { Process, Processor } from '@nestjs/bull';
|
|
||||||
import { InjectRepository } from '@nestjs/typeorm';
|
|
||||||
import { Job } from 'bull';
|
|
||||||
import { Repository } from 'typeorm';
|
|
||||||
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
|
||||||
import fs from 'fs';
|
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
import * as tfnode from '@tensorflow/tfjs-node';
|
|
||||||
import * as cocoSsd from '@tensorflow-models/coco-ssd';
|
|
||||||
|
|
||||||
@Processor('machine-learning')
|
|
||||||
export class MachineLearningProcessor {
|
|
||||||
constructor(
|
|
||||||
@InjectRepository(AssetEntity) private assetRepository: Repository<AssetEntity>,
|
|
||||||
private configService: ConfigService,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
@Process('object-detection')
|
|
||||||
async handleOptimization(job: Job) {
|
|
||||||
try {
|
|
||||||
const { resizePath }: { resizePath: string } = job.data;
|
|
||||||
|
|
||||||
const image = fs.readFileSync(resizePath);
|
|
||||||
const decodedImage = tfnode.node.decodeImage(image, 3) as tfnode.Tensor3D;
|
|
||||||
const model = await cocoSsd.load();
|
|
||||||
const predictions = await model.detect(decodedImage);
|
|
||||||
console.log('\n\nstart predictions ------------------ ');
|
|
||||||
for (var result of predictions) {
|
|
||||||
console.log(`Found ${result.class} with score ${result.score}`);
|
|
||||||
}
|
|
||||||
console.log('end predictions ------------------\n\n');
|
|
||||||
|
|
||||||
return 'ok';
|
|
||||||
} catch (e) {
|
|
||||||
console.log('Error object detection ', e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable, Logger } from '@nestjs/common';
|
||||||
import { JwtService } from '@nestjs/jwt';
|
import { JwtService } from '@nestjs/jwt';
|
||||||
import { JwtPayloadDto } from '../../api-v1/auth/dto/jwt-payload.dto';
|
import { JwtPayloadDto } from '../../api-v1/auth/dto/jwt-payload.dto';
|
||||||
|
import { jwtSecret } from '../../constants/jwt.constant';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ImmichJwtService {
|
export class ImmichJwtService {
|
||||||
@@ -11,4 +12,20 @@ export class ImmichJwtService {
|
|||||||
...payload,
|
...payload,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async validateToken(accessToken: string) {
|
||||||
|
try {
|
||||||
|
const payload = await this.jwtService.verify(accessToken, { secret: jwtSecret });
|
||||||
|
return {
|
||||||
|
userId: payload['userId'],
|
||||||
|
status: true,
|
||||||
|
};
|
||||||
|
} catch (e) {
|
||||||
|
Logger.error('Error validating token from websocket request', 'ValidateWebsocketToken');
|
||||||
|
return {
|
||||||
|
userId: null,
|
||||||
|
status: false,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user