mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
Add video thumbnail with duration and icon
This commit is contained in:
parent
d546c35e3f
commit
69ed287974
11 changed files with 118 additions and 126 deletions
|
|
@ -1,16 +1,15 @@
|
||||||
import 'package:chewie/chewie.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/thumbnail_image.dart';
|
import 'package:immich_mobile/modules/home/ui/thumbnail_image.dart';
|
||||||
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
import 'package:immich_mobile/shared/models/immich_asset.model.dart';
|
||||||
import 'package:video_player/video_player.dart';
|
|
||||||
|
|
||||||
class ImageGrid extends StatelessWidget {
|
class ImageGrid extends ConsumerWidget {
|
||||||
final List<ImmichAsset> assetGroup;
|
final List<ImmichAsset> assetGroup;
|
||||||
|
|
||||||
const ImageGrid({Key? key, required this.assetGroup}) : super(key: key);
|
const ImageGrid({Key? key, required this.assetGroup}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
return SliverGrid(
|
return SliverGrid(
|
||||||
gridDelegate:
|
gridDelegate:
|
||||||
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 5.0, mainAxisSpacing: 5),
|
const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 3, crossAxisSpacing: 5.0, mainAxisSpacing: 5),
|
||||||
|
|
@ -20,10 +19,32 @@ class ImageGrid extends StatelessWidget {
|
||||||
|
|
||||||
return GestureDetector(
|
return GestureDetector(
|
||||||
onTap: () {},
|
onTap: () {},
|
||||||
child: assetType == 'IMAGE'
|
child: Stack(
|
||||||
? ThumbnailImage(asset: assetGroup[index])
|
children: [
|
||||||
: VideoThumbnailPlayer(key: Key(assetGroup[index].id), videoAsset: assetGroup[index]),
|
ThumbnailImage(asset: assetGroup[index]),
|
||||||
);
|
assetType == 'IMAGE'
|
||||||
|
? Container()
|
||||||
|
: Positioned(
|
||||||
|
top: 5,
|
||||||
|
right: 5,
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
assetGroup[index].duration.toString().substring(0, 7),
|
||||||
|
style: const TextStyle(
|
||||||
|
color: Colors.white,
|
||||||
|
fontSize: 10,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Icon(
|
||||||
|
Icons.play_circle_outline_rounded,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
));
|
||||||
},
|
},
|
||||||
childCount: assetGroup.length,
|
childCount: assetGroup.length,
|
||||||
),
|
),
|
||||||
|
|
@ -31,55 +52,55 @@ class ImageGrid extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class VideoThumbnailPlayer extends StatefulWidget {
|
// class VideoThumbnailPlayer extends StatefulWidget {
|
||||||
ImmichAsset videoAsset;
|
// ImmichAsset videoAsset;
|
||||||
|
|
||||||
VideoThumbnailPlayer({Key? key, required this.videoAsset}) : super(key: key);
|
// VideoThumbnailPlayer({Key? key, required this.videoAsset}) : super(key: key);
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
State<VideoThumbnailPlayer> createState() => _VideoThumbnailPlayerState();
|
// State<VideoThumbnailPlayer> createState() => _VideoThumbnailPlayerState();
|
||||||
}
|
// }
|
||||||
|
|
||||||
class _VideoThumbnailPlayerState extends State<VideoThumbnailPlayer> {
|
// class _VideoThumbnailPlayerState extends State<VideoThumbnailPlayer> {
|
||||||
late VideoPlayerController videoPlayerController;
|
// late VideoPlayerController videoPlayerController;
|
||||||
ChewieController? chewieController;
|
// ChewieController? chewieController;
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
void initState() {
|
// void initState() {
|
||||||
super.initState();
|
// super.initState();
|
||||||
initializePlayer();
|
// initializePlayer();
|
||||||
}
|
// }
|
||||||
|
|
||||||
Future<void> initializePlayer() async {
|
// Future<void> initializePlayer() async {
|
||||||
videoPlayerController =
|
// videoPlayerController =
|
||||||
VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
|
// VideoPlayerController.network('https://flutter.github.io/assets-for-api-docs/assets/videos/butterfly.mp4');
|
||||||
|
|
||||||
await Future.wait([
|
// await Future.wait([
|
||||||
videoPlayerController.initialize(),
|
// videoPlayerController.initialize(),
|
||||||
]);
|
// ]);
|
||||||
_createChewieController();
|
// _createChewieController();
|
||||||
setState(() {});
|
// setState(() {});
|
||||||
}
|
// }
|
||||||
|
|
||||||
_createChewieController() {
|
// _createChewieController() {
|
||||||
chewieController = ChewieController(
|
// chewieController = ChewieController(
|
||||||
showControlsOnInitialize: false,
|
// showControlsOnInitialize: false,
|
||||||
videoPlayerController: videoPlayerController,
|
// videoPlayerController: videoPlayerController,
|
||||||
autoPlay: true,
|
// autoPlay: true,
|
||||||
looping: true,
|
// looping: true,
|
||||||
);
|
// );
|
||||||
}
|
// }
|
||||||
|
|
||||||
@override
|
// @override
|
||||||
Widget build(BuildContext context) {
|
// Widget build(BuildContext context) {
|
||||||
return chewieController != null && chewieController!.videoPlayerController.value.isInitialized
|
// return chewieController != null && chewieController!.videoPlayerController.value.isInitialized
|
||||||
? SizedBox(
|
// ? SizedBox(
|
||||||
height: 300,
|
// height: 300,
|
||||||
width: 300,
|
// width: 300,
|
||||||
child: Chewie(
|
// child: Chewie(
|
||||||
controller: chewieController!,
|
// controller: chewieController!,
|
||||||
),
|
// ),
|
||||||
)
|
// )
|
||||||
: const Text("Loading Video");
|
// : const Text("Loading Video");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,21 @@
|
||||||
import 'package:auto_route/auto_route.dart';
|
import 'package:auto_route/auto_route.dart';
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||||
import 'package:hive_flutter/hive_flutter.dart';
|
import 'package:hive_flutter/hive_flutter.dart';
|
||||||
import 'package:immich_mobile/constants/hive_box.dart';
|
import 'package:immich_mobile/constants/hive_box.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';
|
||||||
|
|
||||||
class ThumbnailImage extends StatelessWidget {
|
class ThumbnailImage extends HookWidget {
|
||||||
final ImmichAsset asset;
|
final ImmichAsset asset;
|
||||||
|
|
||||||
const ThumbnailImage({Key? key, required this.asset}) : super(key: key);
|
const ThumbnailImage({Key? key, required this.asset}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
final cacheKey = useState(1);
|
||||||
|
|
||||||
var box = Hive.box(userInfoBox);
|
var box = Hive.box(userInfoBox);
|
||||||
var thumbnailRequestUrl =
|
var thumbnailRequestUrl =
|
||||||
'${box.get(serverEndpointKey)}/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}&isThumb=true';
|
'${box.get(serverEndpointKey)}/asset/file?aid=${asset.deviceAssetId}&did=${asset.deviceId}&isThumb=true';
|
||||||
|
|
@ -31,6 +34,7 @@ class ThumbnailImage extends StatelessWidget {
|
||||||
child: Hero(
|
child: Hero(
|
||||||
tag: asset.id,
|
tag: asset.id,
|
||||||
child: CachedNetworkImage(
|
child: CachedNetworkImage(
|
||||||
|
cacheKey: "${asset.id}-${cacheKey.value}",
|
||||||
width: 300,
|
width: 300,
|
||||||
height: 300,
|
height: 300,
|
||||||
memCacheHeight: 250,
|
memCacheHeight: 250,
|
||||||
|
|
@ -44,6 +48,7 @@ class ThumbnailImage extends StatelessWidget {
|
||||||
),
|
),
|
||||||
errorWidget: (context, url, error) {
|
errorWidget: (context, url, error) {
|
||||||
debugPrint("Error Loading Thumbnail Widget $error");
|
debugPrint("Error Loading Thumbnail Widget $error");
|
||||||
|
cacheKey.value += 1;
|
||||||
return const Icon(Icons.error);
|
return const Icon(Icons.error);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ 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/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/immich_sliver_appbar.dart';
|
import 'package:immich_mobile/modules/home/ui/immich_sliver_appbar.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/models/get_all_asset_respose.model.dart';
|
||||||
import 'package:immich_mobile/modules/home/ui/image_grid.dart';
|
|
||||||
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
import 'package:immich_mobile/modules/home/providers/asset.provider.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
|
|
||||||
|
|
@ -16,9 +16,9 @@ class HomePage extends HookConsumerWidget {
|
||||||
Widget build(BuildContext context, WidgetRef ref) {
|
Widget build(BuildContext context, WidgetRef ref) {
|
||||||
final ValueNotifier<bool> _showBackToTopBtn = useState(false);
|
final ValueNotifier<bool> _showBackToTopBtn = useState(false);
|
||||||
ScrollController _scrollController = useScrollController();
|
ScrollController _scrollController = useScrollController();
|
||||||
|
|
||||||
List<ImmichAssetGroupByDate> assetGroup = ref.watch(assetProvider);
|
List<ImmichAssetGroupByDate> assetGroup = ref.watch(assetProvider);
|
||||||
List<Widget> imageGridGroup = [];
|
List<Widget> imageGridGroup = [];
|
||||||
String scrollBarText = "";
|
|
||||||
|
|
||||||
_scrollControllerCallback() {
|
_scrollControllerCallback() {
|
||||||
var endOfPage = _scrollController.position.maxScrollExtent;
|
var endOfPage = _scrollController.position.maxScrollExtent;
|
||||||
|
|
@ -40,7 +40,6 @@ class HomePage extends HookConsumerWidget {
|
||||||
_scrollController.addListener(_scrollControllerCallback);
|
_scrollController.addListener(_scrollControllerCallback);
|
||||||
|
|
||||||
return () {
|
return () {
|
||||||
debugPrint("Remove scroll listener");
|
|
||||||
_scrollController.removeListener(_scrollControllerCallback);
|
_scrollController.removeListener(_scrollControllerCallback);
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
@ -72,33 +71,13 @@ class HomePage extends HookConsumerWidget {
|
||||||
imageGridGroup.add(
|
imageGridGroup.add(
|
||||||
ImageGrid(assetGroup: assetGroup),
|
ImageGrid(assetGroup: assetGroup),
|
||||||
);
|
);
|
||||||
|
//
|
||||||
lastGroupDate = dateTitle;
|
lastGroupDate = dateTitle;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
child: DraggableScrollbar.semicircle(
|
child: DraggableScrollbar.semicircle(
|
||||||
// labelTextBuilder: (offset) {
|
|
||||||
// final int currentItem = _scrollController.hasClients
|
|
||||||
// ? (_scrollController.offset / _scrollController.position.maxScrollExtent * imageGridGroup.length)
|
|
||||||
// .floor()
|
|
||||||
// : 0;
|
|
||||||
|
|
||||||
// if (imageGridGroup[currentItem] is DailyTitleText) {
|
|
||||||
// DailyTitleText item = imageGridGroup[currentItem] as DailyTitleText;
|
|
||||||
// debugPrint(item.isoDate);
|
|
||||||
// return const Text("");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (imageGridGroup[currentItem] is MonthlyTitleText) {
|
|
||||||
// MonthlyTitleText item = imageGridGroup[currentItem] as MonthlyTitleText;
|
|
||||||
// debugPrint(item.isoDate);
|
|
||||||
// return const Text("scrollBarText");
|
|
||||||
// }
|
|
||||||
// return const Text("scrollBarText");
|
|
||||||
// },
|
|
||||||
// labelConstraints: const BoxConstraints.tightFor(width: 200.0, height: 30.0),
|
|
||||||
backgroundColor: Theme.of(context).primaryColor,
|
backgroundColor: Theme.of(context).primaryColor,
|
||||||
controller: _scrollController,
|
controller: _scrollController,
|
||||||
heightScrollThumb: 48.0,
|
heightScrollThumb: 48.0,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ class ImmichAsset {
|
||||||
final String createdAt;
|
final String createdAt;
|
||||||
final String modifiedAt;
|
final String modifiedAt;
|
||||||
final bool isFavorite;
|
final bool isFavorite;
|
||||||
final String? description;
|
final String? duration;
|
||||||
|
|
||||||
ImmichAsset({
|
ImmichAsset({
|
||||||
required this.id,
|
required this.id,
|
||||||
|
|
@ -20,7 +20,7 @@ class ImmichAsset {
|
||||||
required this.createdAt,
|
required this.createdAt,
|
||||||
required this.modifiedAt,
|
required this.modifiedAt,
|
||||||
required this.isFavorite,
|
required this.isFavorite,
|
||||||
this.description,
|
this.duration,
|
||||||
});
|
});
|
||||||
|
|
||||||
ImmichAsset copyWith({
|
ImmichAsset copyWith({
|
||||||
|
|
@ -32,7 +32,7 @@ class ImmichAsset {
|
||||||
String? createdAt,
|
String? createdAt,
|
||||||
String? modifiedAt,
|
String? modifiedAt,
|
||||||
bool? isFavorite,
|
bool? isFavorite,
|
||||||
String? description,
|
String? duration,
|
||||||
}) {
|
}) {
|
||||||
return ImmichAsset(
|
return ImmichAsset(
|
||||||
id: id ?? this.id,
|
id: id ?? this.id,
|
||||||
|
|
@ -43,7 +43,7 @@ class ImmichAsset {
|
||||||
createdAt: createdAt ?? this.createdAt,
|
createdAt: createdAt ?? this.createdAt,
|
||||||
modifiedAt: modifiedAt ?? this.modifiedAt,
|
modifiedAt: modifiedAt ?? this.modifiedAt,
|
||||||
isFavorite: isFavorite ?? this.isFavorite,
|
isFavorite: isFavorite ?? this.isFavorite,
|
||||||
description: description ?? this.description,
|
duration: duration ?? this.duration,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,7 +57,7 @@ class ImmichAsset {
|
||||||
'createdAt': createdAt,
|
'createdAt': createdAt,
|
||||||
'modifiedAt': modifiedAt,
|
'modifiedAt': modifiedAt,
|
||||||
'isFavorite': isFavorite,
|
'isFavorite': isFavorite,
|
||||||
'description': description,
|
'duration': duration,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,7 +71,7 @@ class ImmichAsset {
|
||||||
createdAt: map['createdAt'] ?? '',
|
createdAt: map['createdAt'] ?? '',
|
||||||
modifiedAt: map['modifiedAt'] ?? '',
|
modifiedAt: map['modifiedAt'] ?? '',
|
||||||
isFavorite: map['isFavorite'] ?? false,
|
isFavorite: map['isFavorite'] ?? false,
|
||||||
description: map['description'],
|
duration: map['duration'],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -81,7 +81,7 @@ class ImmichAsset {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'ImmichAsset(id: $id, deviceAssetId: $deviceAssetId, userId: $userId, deviceId: $deviceId, type: $type, createdAt: $createdAt, modifiedAt: $modifiedAt, isFavorite: $isFavorite, description: $description)';
|
return 'ImmichAsset(id: $id, deviceAssetId: $deviceAssetId, userId: $userId, deviceId: $deviceId, type: $type, createdAt: $createdAt, modifiedAt: $modifiedAt, isFavorite: $isFavorite, duration: $duration)';
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -97,7 +97,7 @@ class ImmichAsset {
|
||||||
other.createdAt == createdAt &&
|
other.createdAt == createdAt &&
|
||||||
other.modifiedAt == modifiedAt &&
|
other.modifiedAt == modifiedAt &&
|
||||||
other.isFavorite == isFavorite &&
|
other.isFavorite == isFavorite &&
|
||||||
other.description == description;
|
other.duration == duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -110,6 +110,6 @@ class ImmichAsset {
|
||||||
createdAt.hashCode ^
|
createdAt.hashCode ^
|
||||||
modifiedAt.hashCode ^
|
modifiedAt.hashCode ^
|
||||||
isFavorite.hashCode ^
|
isFavorite.hashCode ^
|
||||||
description.hashCode;
|
duration.hashCode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@ class BackupService {
|
||||||
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);
|
||||||
LatLng coordinate = await entity.latlngAsync();
|
|
||||||
var mimeType = FileHelper.getMimeType(file.path);
|
var mimeType = FileHelper.getMimeType(file.path);
|
||||||
|
|
||||||
var formData = FormData.fromMap({
|
var formData = FormData.fromMap({
|
||||||
'deviceAssetId': entity.id,
|
'deviceAssetId': entity.id,
|
||||||
'deviceId': deviceId,
|
'deviceId': deviceId,
|
||||||
|
|
@ -59,8 +59,7 @@ class BackupService {
|
||||||
'modifiedAt': entity.modifiedDateTime.toIso8601String(),
|
'modifiedAt': entity.modifiedDateTime.toIso8601String(),
|
||||||
'isFavorite': entity.isFavorite,
|
'isFavorite': entity.isFavorite,
|
||||||
'fileExtension': fileExtension,
|
'fileExtension': fileExtension,
|
||||||
'lat': coordinate.latitude,
|
'duration': entity.videoDuration,
|
||||||
'lon': coordinate.longitude,
|
|
||||||
'files': [
|
'files': [
|
||||||
await MultipartFile.fromFile(
|
await MultipartFile.fromFile(
|
||||||
file.path,
|
file.path,
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,7 @@ export class AssetController {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedAsset && savedAsset.type == AssetType.VIDEO) {
|
if (savedAsset && savedAsset.type == AssetType.VIDEO) {
|
||||||
await this.assetOptimizeService.resizeVideo(savedAsset);
|
await this.assetOptimizeService.getVideoThumbnail(savedAsset, file.originalname);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -26,9 +26,9 @@ export class AssetService {
|
||||||
asset.createdAt = assetInfo.createdAt;
|
asset.createdAt = assetInfo.createdAt;
|
||||||
asset.modifiedAt = assetInfo.modifiedAt;
|
asset.modifiedAt = assetInfo.modifiedAt;
|
||||||
asset.isFavorite = assetInfo.isFavorite;
|
asset.isFavorite = assetInfo.isFavorite;
|
||||||
asset.lat = assetInfo.lat;
|
|
||||||
asset.lon = assetInfo.lon;
|
|
||||||
asset.mimeType = mimeType;
|
asset.mimeType = mimeType;
|
||||||
|
asset.duration = assetInfo.duration;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await this.assetRepository.save(asset);
|
const res = await this.assetRepository.save(asset);
|
||||||
|
|
||||||
|
|
@ -63,7 +63,7 @@ export class AssetService {
|
||||||
lastQueryCreatedAt: query.nextPageKey || new Date().toISOString(),
|
lastQueryCreatedAt: query.nextPageKey || new Date().toISOString(),
|
||||||
})
|
})
|
||||||
.orderBy('a."createdAt"::date', 'DESC')
|
.orderBy('a."createdAt"::date', 'DESC')
|
||||||
.take(10000)
|
// .take(5000)
|
||||||
.getMany();
|
.getMany();
|
||||||
|
|
||||||
if (assets.length > 0) {
|
if (assets.length > 0) {
|
||||||
|
|
|
||||||
|
|
@ -24,8 +24,5 @@ export class CreateAssetDto {
|
||||||
fileExtension: string;
|
fileExtension: string;
|
||||||
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
lat: string;
|
duration: string;
|
||||||
|
|
||||||
@IsOptional()
|
|
||||||
lon: string;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,17 +33,11 @@ export class AssetEntity {
|
||||||
@Column({ type: 'boolean', default: false })
|
@Column({ type: 'boolean', default: false })
|
||||||
isFavorite: boolean;
|
isFavorite: boolean;
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
description: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
lat: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
|
||||||
lon: string;
|
|
||||||
|
|
||||||
@Column({ nullable: true })
|
@Column({ nullable: true })
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true })
|
||||||
|
duration: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum AssetType {
|
export enum AssetType {
|
||||||
|
|
|
||||||
|
|
@ -60,13 +60,13 @@ export class ImageOptimizeProcessor {
|
||||||
return 'ok';
|
return 'ok';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Process('resize-video')
|
@Process('get-video-thumbnail')
|
||||||
async resizeUploadedVideo(job: Job) {
|
async resizeUploadedVideo(job: Job) {
|
||||||
const { savedAsset }: { savedAsset: AssetEntity } = job.data;
|
const { savedAsset, filename }: { savedAsset: AssetEntity; filename: String } = job.data;
|
||||||
|
|
||||||
const basePath = this.configService.get('UPLOAD_LOCATION');
|
const basePath = this.configService.get('UPLOAD_LOCATION');
|
||||||
const resizePath = savedAsset.originalPath.replace('/original/', '/thumb/');
|
// const resizePath = savedAsset.originalPath.replace('/original/', '/thumb/');
|
||||||
|
console.log(filename);
|
||||||
// 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}`;
|
||||||
|
|
||||||
|
|
@ -75,18 +75,16 @@ export class ImageOptimizeProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
ffmpeg(savedAsset.originalPath)
|
ffmpeg(savedAsset.originalPath)
|
||||||
.output(resizePath)
|
.thumbnail({
|
||||||
.noAudio()
|
count: 1,
|
||||||
.videoCodec('libx264')
|
timestamps: [1],
|
||||||
.size('640x?')
|
folder: resizeDir,
|
||||||
.aspect('4:3')
|
filename: `${filename}.png`,
|
||||||
.on('error', (e) => {
|
size: '512x512',
|
||||||
Logger.log(`Error resizing File: ${e}`, 'resizeUploadedVideo');
|
|
||||||
})
|
})
|
||||||
.on('end', async () => {
|
.on('end', async (a) => {
|
||||||
await this.assetRepository.update(savedAsset, { resizePath: resizePath });
|
await this.assetRepository.update(savedAsset, { resizePath: `${resizeDir}/${filename}.png` });
|
||||||
})
|
});
|
||||||
.run();
|
|
||||||
|
|
||||||
return 'ok';
|
return 'ok';
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,7 @@ import { InjectQueue } from '@nestjs/bull';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { Queue } from 'bull';
|
import { Queue } from 'bull';
|
||||||
import { randomUUID } from 'crypto';
|
import { randomUUID } from 'crypto';
|
||||||
import { join } from 'path';
|
|
||||||
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
import { AssetEntity } from '../../api-v1/asset/entities/asset.entity';
|
||||||
import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AssetOptimizeService {
|
export class AssetOptimizeService {
|
||||||
|
|
@ -24,11 +22,12 @@ export class AssetOptimizeService {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public async resizeVideo(savedAsset: AssetEntity) {
|
public async getVideoThumbnail(savedAsset: AssetEntity, filename: String) {
|
||||||
const job = await this.optimizeQueue.add(
|
const job = await this.optimizeQueue.add(
|
||||||
'resize-video',
|
'get-video-thumbnail',
|
||||||
{
|
{
|
||||||
savedAsset,
|
savedAsset,
|
||||||
|
filename,
|
||||||
},
|
},
|
||||||
{ jobId: randomUUID() },
|
{ jobId: randomUUID() },
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue