diff --git a/cli/package.json b/cli/package.json index e74425eb41..3c65605330 100644 --- a/cli/package.json +++ b/cli/package.json @@ -20,7 +20,7 @@ "@types/lodash-es": "^4.17.12", "@types/micromatch": "^4.0.9", "@types/mock-fs": "^4.13.1", - "@types/node": "^24.10.1", + "@types/node": "^24.10.3", "@vitest/coverage-v8": "^3.0.0", "byte-size": "^9.0.0", "cli-progress": "^3.12.0", diff --git a/e2e/package.json b/e2e/package.json index 70669a8546..07d02f0cbc 100644 --- a/e2e/package.json +++ b/e2e/package.json @@ -26,7 +26,7 @@ "@playwright/test": "^1.44.1", "@socket.io/component-emitter": "^3.1.2", "@types/luxon": "^3.4.2", - "@types/node": "^24.10.1", + "@types/node": "^24.10.3", "@types/oidc-provider": "^9.0.0", "@types/pg": "^8.15.1", "@types/pngjs": "^6.0.4", diff --git a/mobile/lib/presentation/widgets/action_buttons/like_activity_action_button.widget.dart b/mobile/lib/presentation/widgets/action_buttons/like_activity_action_button.widget.dart index a61f72ea01..8c326974a7 100644 --- a/mobile/lib/presentation/widgets/action_buttons/like_activity_action_button.widget.dart +++ b/mobile/lib/presentation/widgets/action_buttons/like_activity_action_button.widget.dart @@ -47,7 +47,7 @@ class LikeActivityActionButton extends ConsumerWidget { return BaseActionButton( maxWidth: 60, - iconData: liked != null ? Icons.favorite : Icons.favorite_border, + iconData: liked != null ? Icons.thumb_up : Icons.thumb_up_off_alt, label: "like".t(context: context), onPressed: () => onTap(liked), iconOnly: iconOnly, @@ -57,7 +57,7 @@ class LikeActivityActionButton extends ConsumerWidget { // default to empty heart during loading loading: () => BaseActionButton( - iconData: Icons.favorite_border, + iconData: Icons.thumb_up_off_alt, label: "like".t(context: context), iconOnly: iconOnly, menuItem: menuItem, diff --git a/mobile/lib/presentation/widgets/asset_viewer/activities_bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/asset_viewer/activities_bottom_sheet.widget.dart index 63669495b9..3b46b69958 100644 --- a/mobile/lib/presentation/widgets/asset_viewer/activities_bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/asset_viewer/activities_bottom_sheet.widget.dart @@ -79,7 +79,7 @@ class ActivitiesBottomSheet extends HookConsumerWidget { expand: false, shouldCloseOnMinExtent: false, resizeOnScroll: false, - backgroundColor: context.isDarkTheme ? Colors.black : Colors.white, + backgroundColor: context.isDarkTheme ? context.colorScheme.surface : Colors.white, ); } } diff --git a/mobile/lib/presentation/widgets/asset_viewer/asset_viewer.page.dart b/mobile/lib/presentation/widgets/asset_viewer/asset_viewer.page.dart index 70eb6699aa..d992d243ee 100644 --- a/mobile/lib/presentation/widgets/asset_viewer/asset_viewer.page.dart +++ b/mobile/lib/presentation/widgets/asset_viewer/asset_viewer.page.dart @@ -97,7 +97,7 @@ class AssetViewer extends ConsumerStatefulWidget { } const double _kBottomSheetMinimumExtent = 0.4; -const double _kBottomSheetSnapExtent = 0.7; +const double _kBottomSheetSnapExtent = 0.67; class _AssetViewerState extends ConsumerState { static final _dummyListener = ImageStreamListener((image, _) => image.dispose()); @@ -399,10 +399,14 @@ class _AssetViewerState extends ConsumerState { final isDraggingDown = currentExtent < previousExtent; previousExtent = currentExtent; // Closes the bottom sheet if the user is dragging down - if (isDraggingDown && delta.extent < 0.55) { + if (isDraggingDown && delta.extent < 0.67) { if (dragInProgress) { blockGestures = true; } + // Jump to a lower position before starting close animation to prevent glitch + if (bottomSheetController.isAttached) { + bottomSheetController.jumpTo(0.67); + } sheetCloseController?.close(); } @@ -480,7 +484,7 @@ class _AssetViewerState extends ConsumerState { previousExtent = _kBottomSheetMinimumExtent; sheetCloseController = showBottomSheet( context: ctx, - sheetAnimationStyle: const AnimationStyle(duration: Durations.short4, reverseDuration: Durations.short2), + sheetAnimationStyle: const AnimationStyle(duration: Durations.medium2, reverseDuration: Durations.medium2), constraints: const BoxConstraints(maxWidth: double.infinity), shape: const RoundedRectangleBorder(borderRadius: BorderRadius.vertical(top: Radius.circular(20.0))), backgroundColor: ctx.colorScheme.surfaceContainerLowest, @@ -688,16 +692,20 @@ class _AssetViewerState extends ConsumerState { backgroundDecoration: BoxDecoration(color: backgroundColor), enablePanAlways: true, ), + if (!showingBottomSheet) + const Positioned( + bottom: 0, + left: 0, + right: 0, + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [AssetStackRow(), ViewerBottomBar()], + ), + ), ], ), - bottomNavigationBar: showingBottomSheet - ? const SizedBox.shrink() - : const Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.stretch, - children: [AssetStackRow(), ViewerBottomBar()], - ), ), ); } diff --git a/mobile/lib/presentation/widgets/asset_viewer/bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/asset_viewer/bottom_sheet.widget.dart index f0ba970b98..ed3873b510 100644 --- a/mobile/lib/presentation/widgets/asset_viewer/bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/asset_viewer/bottom_sheet.widget.dart @@ -52,7 +52,7 @@ class AssetDetailBottomSheet extends ConsumerWidget { expand: false, shouldCloseOnMinExtent: false, resizeOnScroll: false, - backgroundColor: context.isDarkTheme ? Colors.black : Colors.white, + backgroundColor: context.isDarkTheme ? context.colorScheme.surface : Colors.white, ); } } @@ -299,7 +299,7 @@ class _AssetDetailBottomSheet extends ConsumerWidget { // Appears in (Albums) Padding(padding: const EdgeInsets.only(top: 16.0), child: _buildAppearsInList(ref, context)), // padding at the bottom to avoid cut-off - const SizedBox(height: 100), + const SizedBox(height: 30), ], ); } diff --git a/mobile/lib/presentation/widgets/bottom_sheet/archive_bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/bottom_sheet/archive_bottom_sheet.widget.dart index f40e189e18..9481ec12f5 100644 --- a/mobile/lib/presentation/widgets/bottom_sheet/archive_bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/bottom_sheet/archive_bottom_sheet.widget.dart @@ -14,7 +14,6 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/stack_action_b import 'package:immich_mobile/presentation/widgets/action_buttons/trash_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/unarchive_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/unstack_action_button.widget.dart'; -import 'package:immich_mobile/presentation/widgets/action_buttons/upload_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart'; import 'package:immich_mobile/providers/server_info.provider.dart'; import 'package:immich_mobile/providers/timeline/multiselect.provider.dart'; @@ -47,10 +46,7 @@ class ArchiveBottomSheet extends ConsumerWidget { if (multiselect.selectedAssets.length > 1) const StackActionButton(source: ActionSource.timeline), if (multiselect.hasStacked) const UnStackActionButton(source: ActionSource.timeline), ], - if (multiselect.hasLocal) ...[ - const DeleteLocalActionButton(source: ActionSource.timeline), - const UploadActionButton(source: ActionSource.timeline), - ], + if (multiselect.hasMerged) const DeleteLocalActionButton(source: ActionSource.timeline), ], ); } diff --git a/mobile/lib/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart index 2f2847543f..0d0e0259fd 100644 --- a/mobile/lib/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart @@ -81,7 +81,7 @@ class _BaseDraggableScrollableSheetState extends ConsumerState child: CustomScrollView( controller: scrollController, slivers: [ - const SliverPersistentHeader(delegate: _DragHandleDelegate(), pinned: true), + const SliverToBoxAdapter(child: _DragHandle()), if (widget.actions.isNotEmpty) SliverToBoxAdapter( child: Column( @@ -108,31 +108,13 @@ class _BaseDraggableScrollableSheetState extends ConsumerState } } -class _DragHandleDelegate extends SliverPersistentHeaderDelegate { - const _DragHandleDelegate(); - - @override - Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) { - return const _DragHandle(); - } - - @override - bool shouldRebuild(_DragHandleDelegate oldDelegate) => false; - - @override - double get minExtent => 50.0; - - @override - double get maxExtent => 50.0; -} - class _DragHandle extends StatelessWidget { const _DragHandle(); @override Widget build(BuildContext context) { return SizedBox( - height: 50, + height: 38, child: Center( child: SizedBox( width: 32, diff --git a/mobile/lib/presentation/widgets/bottom_sheet/favorite_bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/bottom_sheet/favorite_bottom_sheet.widget.dart index b2502127d4..fb6034b869 100644 --- a/mobile/lib/presentation/widgets/bottom_sheet/favorite_bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/bottom_sheet/favorite_bottom_sheet.widget.dart @@ -17,7 +17,6 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/stack_action_b import 'package:immich_mobile/presentation/widgets/action_buttons/trash_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/unfavorite_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/unstack_action_button.widget.dart'; -import 'package:immich_mobile/presentation/widgets/action_buttons/upload_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/album/album_selector.widget.dart'; import 'package:immich_mobile/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart'; import 'package:immich_mobile/providers/infrastructure/album.provider.dart'; @@ -86,10 +85,7 @@ class FavoriteBottomSheet extends ConsumerWidget { if (multiselect.selectedAssets.length > 1) const StackActionButton(source: ActionSource.timeline), if (multiselect.hasStacked) const UnStackActionButton(source: ActionSource.timeline), ], - if (multiselect.hasLocal) ...[ - const DeleteLocalActionButton(source: ActionSource.timeline), - const UploadActionButton(source: ActionSource.timeline), - ], + if (multiselect.hasMerged) const DeleteLocalActionButton(source: ActionSource.timeline), ], slivers: multiselect.hasRemote ? [const AddToAlbumHeader(), AlbumSelector(onAlbumSelected: addAssetsToAlbum)] diff --git a/mobile/lib/presentation/widgets/bottom_sheet/remote_album_bottom_sheet.widget.dart b/mobile/lib/presentation/widgets/bottom_sheet/remote_album_bottom_sheet.widget.dart index 7db8a80af2..2f2a2e0a4e 100644 --- a/mobile/lib/presentation/widgets/bottom_sheet/remote_album_bottom_sheet.widget.dart +++ b/mobile/lib/presentation/widgets/bottom_sheet/remote_album_bottom_sheet.widget.dart @@ -18,7 +18,6 @@ import 'package:immich_mobile/presentation/widgets/action_buttons/share_link_act import 'package:immich_mobile/presentation/widgets/action_buttons/stack_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/trash_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/action_buttons/unstack_action_button.widget.dart'; -import 'package:immich_mobile/presentation/widgets/action_buttons/upload_action_button.widget.dart'; import 'package:immich_mobile/presentation/widgets/album/album_selector.widget.dart'; import 'package:immich_mobile/presentation/widgets/bottom_sheet/base_bottom_sheet.widget.dart'; import 'package:immich_mobile/providers/infrastructure/album.provider.dart'; @@ -112,10 +111,7 @@ class _RemoteAlbumBottomSheetState extends ConsumerState if (multiselect.hasStacked) const UnStackActionButton(source: ActionSource.timeline), ], ], - if (multiselect.hasLocal) ...[ - const DeleteLocalActionButton(source: ActionSource.timeline), - const UploadActionButton(source: ActionSource.timeline), - ], + if (multiselect.hasMerged) const DeleteLocalActionButton(source: ActionSource.timeline), if (ownsAlbum) RemoveFromAlbumActionButton(source: ActionSource.timeline, albumId: widget.album.id), ], slivers: ownsAlbum diff --git a/mobile/lib/widgets/activities/activity_text_field.dart b/mobile/lib/widgets/activities/activity_text_field.dart index e3958b6287..a61a284844 100644 --- a/mobile/lib/widgets/activities/activity_text_field.dart +++ b/mobile/lib/widgets/activities/activity_text_field.dart @@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_hooks/flutter_hooks.dart'; import 'package:hooks_riverpod/hooks_riverpod.dart'; +import 'package:immich_mobile/extensions/build_context_extensions.dart'; import 'package:immich_mobile/providers/activity.provider.dart'; import 'package:immich_mobile/providers/album/current_album.provider.dart'; import 'package:immich_mobile/providers/asset_viewer/current_asset.provider.dart'; @@ -68,11 +69,11 @@ class ActivityTextField extends HookConsumerWidget { suffixIcon: Padding( padding: const EdgeInsets.only(right: 10), child: IconButton( - icon: Icon(liked ? Icons.favorite_rounded : Icons.favorite_border_rounded), + icon: Icon(liked ? Icons.thumb_up : Icons.thumb_up_off_alt), onPressed: liked ? removeLike : addLike, ), ), - suffixIconColor: liked ? Colors.red[700] : null, + suffixIconColor: liked ? context.primaryColor : null, hintText: !isEnabled ? 'shared_album_activities_input_disable'.tr() : 'say_something'.tr(), hintStyle: TextStyle(fontWeight: FontWeight.normal, fontSize: 14, color: Colors.grey[600]), ), diff --git a/mobile/lib/widgets/activities/activity_tile.dart b/mobile/lib/widgets/activities/activity_tile.dart index 6812d1b90c..76c0b7bf2a 100644 --- a/mobile/lib/widgets/activities/activity_tile.dart +++ b/mobile/lib/widgets/activities/activity_tile.dart @@ -37,7 +37,7 @@ class ActivityTile extends HookConsumerWidget { ? Container( width: isBottomSheet ? 30 : 44, alignment: Alignment.center, - child: Icon(Icons.favorite_rounded, color: Colors.red[700]), + child: Icon(Icons.thumb_up, color: context.primaryColor), ) : isBottomSheet ? UserCircleAvatar(user: activity.user, size: 30, radius: 15) diff --git a/mobile/lib/widgets/activities/comment_bubble.dart b/mobile/lib/widgets/activities/comment_bubble.dart index 11d5c21cec..3dd46cd92a 100644 --- a/mobile/lib/widgets/activities/comment_bubble.dart +++ b/mobile/lib/widgets/activities/comment_bubble.dart @@ -67,8 +67,8 @@ class CommentBubble extends ConsumerWidget { bottom: 6, child: Container( padding: const EdgeInsets.all(4), - decoration: BoxDecoration(color: Colors.white.withValues(alpha: 0.7), shape: BoxShape.circle), - child: Icon(Icons.favorite, color: Colors.red[600], size: 18), + decoration: BoxDecoration(color: context.colorScheme.surfaceContainer, shape: BoxShape.circle), + child: Icon(Icons.thumb_up, color: context.primaryColor, size: 18), ), ), ], @@ -81,8 +81,8 @@ class CommentBubble extends ConsumerWidget { if (isLike && !showThumbnail) { likes = Container( padding: const EdgeInsets.all(8), - decoration: BoxDecoration(color: Colors.white.withValues(alpha: 0.7), shape: BoxShape.circle), - child: Icon(Icons.favorite, color: Colors.red[600], size: 18), + decoration: BoxDecoration(color: context.colorScheme.surfaceContainer, shape: BoxShape.circle), + child: Icon(Icons.thumb_up, color: context.primaryColor, size: 18), ); } diff --git a/mobile/test/modules/activity/activity_text_field_test.dart b/mobile/test/modules/activity/activity_text_field_test.dart index 8f28b7f28e..4f4a2c7068 100644 --- a/mobile/test/modules/activity/activity_text_field_test.dart +++ b/mobile/test/modules/activity/activity_text_field_test.dart @@ -77,15 +77,15 @@ void main() { overrides: overrides, ); - expect(find.widgetWithIcon(IconButton, Icons.favorite_rounded), findsOneWidget); - expect(find.widgetWithIcon(IconButton, Icons.favorite_border_rounded), findsNothing); + expect(find.widgetWithIcon(IconButton, Icons.thumb_up), findsOneWidget); + expect(find.widgetWithIcon(IconButton, Icons.thumb_up_off_alt), findsNothing); }); testWidgets('Bordered icon if likedId == null', (tester) async { await tester.pumpConsumerWidget(ActivityTextField(onSubmit: (_) {}), overrides: overrides); - expect(find.widgetWithIcon(IconButton, Icons.favorite_border_rounded), findsOneWidget); - expect(find.widgetWithIcon(IconButton, Icons.favorite_rounded), findsNothing); + expect(find.widgetWithIcon(IconButton, Icons.thumb_up_off_alt), findsOneWidget); + expect(find.widgetWithIcon(IconButton, Icons.thumb_up), findsNothing); }); testWidgets('Adds new like', (tester) async { diff --git a/mobile/test/modules/activity/activity_tile_test.dart b/mobile/test/modules/activity/activity_tile_test.dart index 718dfcce21..538e3c0911 100644 --- a/mobile/test/modules/activity/activity_tile_test.dart +++ b/mobile/test/modules/activity/activity_tile_test.dart @@ -91,17 +91,17 @@ void main() { group('Like Activity', () { final activity = Activity(id: '1', createdAt: DateTime(100), type: ActivityType.like, user: UserStub.admin); - testWidgets('Like contains filled heart as leading', (tester) async { + testWidgets('Like contains filled thumbs-up as leading', (tester) async { await tester.pumpConsumerWidget(ActivityTile(activity), overrides: overrides); // Leading widget should not be null final listTile = tester.widget(find.byType(ListTile)); expect(listTile.leading, isNotNull); - // And should have a favorite icon - final favoIconFinder = find.widgetWithIcon(listTile.leading!.runtimeType, Icons.favorite_rounded); + // And should have a thumb_up icon + final thumbUpIconFinder = find.widgetWithIcon(listTile.leading!.runtimeType, Icons.thumb_up); - expect(favoIconFinder, findsOneWidget); + expect(thumbUpIconFinder, findsOneWidget); }); testWidgets('Like title is center aligned', (tester) async { diff --git a/open-api/typescript-sdk/package.json b/open-api/typescript-sdk/package.json index 56520b0efe..b033fdfd7b 100644 --- a/open-api/typescript-sdk/package.json +++ b/open-api/typescript-sdk/package.json @@ -19,7 +19,7 @@ "@oazapfts/runtime": "^1.0.2" }, "devDependencies": { - "@types/node": "^24.10.1", + "@types/node": "^24.10.3", "typescript": "^5.3.3" }, "repository": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4831601dec..27c6c3f290 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -63,7 +63,7 @@ importers: specifier: ^4.13.1 version: 4.13.4 '@types/node': - specifier: ^24.10.1 + specifier: ^24.10.3 version: 24.10.4 '@vitest/coverage-v8': specifier: ^3.0.0 @@ -214,7 +214,7 @@ importers: specifier: ^3.4.2 version: 3.7.1 '@types/node': - specifier: ^24.10.1 + specifier: ^24.10.3 version: 24.10.4 '@types/oidc-provider': specifier: ^9.0.0 @@ -299,7 +299,7 @@ importers: version: 1.1.0 devDependencies: '@types/node': - specifier: ^24.10.1 + specifier: ^24.10.3 version: 24.10.4 typescript: specifier: ^5.3.3 @@ -615,7 +615,7 @@ importers: specifier: ^2.0.0 version: 2.0.0 '@types/node': - specifier: ^24.10.1 + specifier: ^24.10.3 version: 24.10.4 '@types/nodemailer': specifier: ^7.0.0 @@ -16567,7 +16567,7 @@ snapshots: '@types/connect-history-api-fallback@1.5.4': dependencies: - '@types/express-serve-static-core': 4.19.7 + '@types/express-serve-static-core': 5.1.0 '@types/node': 24.10.4 '@types/connect@3.4.38': @@ -16813,7 +16813,7 @@ snapshots: '@types/pg-pool@2.0.6': dependencies: - '@types/pg': 8.15.6 + '@types/pg': 8.16.0 '@types/pg@8.15.6': dependencies: diff --git a/server/package.json b/server/package.json index ae12ee8e61..045bc950bd 100644 --- a/server/package.json +++ b/server/package.json @@ -134,7 +134,7 @@ "@types/luxon": "^3.6.2", "@types/mock-fs": "^4.13.1", "@types/multer": "^2.0.0", - "@types/node": "^24.10.1", + "@types/node": "^24.10.3", "@types/nodemailer": "^7.0.0", "@types/picomatch": "^4.0.0", "@types/pngjs": "^6.0.5", diff --git a/server/src/database.ts b/server/src/database.ts index a3c38ae61e..9f4494b720 100644 --- a/server/src/database.ts +++ b/server/src/database.ts @@ -240,7 +240,7 @@ export type Session = { isPendingSyncReset: boolean; }; -export type Exif = Omit, 'updatedAt' | 'updateId'>; +export type Exif = Omit, 'updatedAt' | 'updateId' | 'lockedProperties'>; export type Person = { createdAt: Date; @@ -465,3 +465,13 @@ export const columns = { 'plugin.updatedAt as updatedAt', ], } as const; + +export type LockableProperty = (typeof lockableProperties)[number]; +export const lockableProperties = [ + 'description', + 'dateTimeOriginal', + 'latitude', + 'longitude', + 'rating', + 'timeZone', +] as const; diff --git a/server/src/queries/asset.job.repository.sql b/server/src/queries/asset.job.repository.sql index d1b4e5a72e..b736998e28 100644 --- a/server/src/queries/asset.job.repository.sql +++ b/server/src/queries/asset.job.repository.sql @@ -50,9 +50,11 @@ select where "asset"."id" = "tag_asset"."assetId" ) as agg - ) as "tags" + ) as "tags", + to_json("asset_exif") as "exifInfo" from "asset" + inner join "asset_exif" on "asset"."id" = "asset_exif"."assetId" where "asset"."id" = $2::uuid limit @@ -224,6 +226,14 @@ from where "asset"."id" = $2 +-- AssetJobRepository.getLockedPropertiesForMetadataExtraction +select + "asset_exif"."lockedProperties" +from + "asset_exif" +where + "asset_exif"."assetId" = $1 + -- AssetJobRepository.getAlbumThumbnailFiles select "asset_file"."id", diff --git a/server/src/queries/asset.repository.sql b/server/src/queries/asset.repository.sql index 01cc6a7a89..f25a0798d2 100644 --- a/server/src/queries/asset.repository.sql +++ b/server/src/queries/asset.repository.sql @@ -1,19 +1,49 @@ -- NOTE: This file is auto generated by ./sql-generator +-- AssetRepository.upsertExif +insert into + "asset_exif" ("dateTimeOriginal", "lockedProperties") +values + ($1, $2) +on conflict ("assetId") do update +set + "dateTimeOriginal" = "excluded"."dateTimeOriginal", + "lockedProperties" = nullif( + array( + select distinct + unnest("asset_exif"."lockedProperties" || $3) + ), + '{}' + ) + -- AssetRepository.updateAllExif update "asset_exif" set - "model" = $1 + "model" = $1, + "lockedProperties" = nullif( + array( + select distinct + unnest("asset_exif"."lockedProperties" || $2) + ), + '{}' + ) where - "assetId" in ($2) + "assetId" in ($3) -- AssetRepository.updateDateTimeOriginal update "asset_exif" set "dateTimeOriginal" = "dateTimeOriginal" + $1::interval, - "timeZone" = $2 + "timeZone" = $2, + "lockedProperties" = nullif( + array( + select distinct + unnest("asset_exif"."lockedProperties" || $3) + ), + '{}' + ) where - "assetId" in ($3) + "assetId" in ($4) returning "assetId", "dateTimeOriginal", diff --git a/server/src/repositories/asset-job.repository.ts b/server/src/repositories/asset-job.repository.ts index de994b08cd..214d42747f 100644 --- a/server/src/repositories/asset-job.repository.ts +++ b/server/src/repositories/asset-job.repository.ts @@ -50,6 +50,7 @@ export class AssetJobRepository { .whereRef('asset.id', '=', 'tag_asset.assetId'), ).as('tags'), ) + .$call(withExifInner) .limit(1) .executeTakeFirst(); } @@ -128,6 +129,16 @@ export class AssetJobRepository { .executeTakeFirst(); } + @GenerateSql({ params: [DummyValue.UUID] }) + async getLockedPropertiesForMetadataExtraction(assetId: string) { + return this.db + .selectFrom('asset_exif') + .select('asset_exif.lockedProperties') + .where('asset_exif.assetId', '=', assetId) + .executeTakeFirst() + .then((row) => row?.lockedProperties ?? []); + } + @GenerateSql({ params: [DummyValue.UUID, AssetFileType.Thumbnail] }) getAlbumThumbnailFiles(id: string, fileType?: AssetFileType) { return this.db diff --git a/server/src/repositories/asset.repository.ts b/server/src/repositories/asset.repository.ts index 4b8cbd7a7a..7db3a76f12 100644 --- a/server/src/repositories/asset.repository.ts +++ b/server/src/repositories/asset.repository.ts @@ -1,8 +1,8 @@ import { Injectable } from '@nestjs/common'; -import { Insertable, Kysely, NotNull, Selectable, sql, Updateable, UpdateResult } from 'kysely'; +import { ExpressionBuilder, Insertable, Kysely, NotNull, Selectable, sql, Updateable, UpdateResult } from 'kysely'; import { isEmpty, isUndefined, omitBy } from 'lodash'; import { InjectKysely } from 'nestjs-kysely'; -import { Stack } from 'src/database'; +import { LockableProperty, Stack } from 'src/database'; import { Chunked, ChunkedArray, DummyValue, GenerateSql } from 'src/decorators'; import { AuthDto } from 'src/dtos/auth.dto'; import { AssetFileType, AssetMetadataKey, AssetOrder, AssetStatus, AssetType, AssetVisibility } from 'src/enum'; @@ -113,51 +113,77 @@ interface GetByIdsRelations { tags?: boolean; } +const distinctLocked = (eb: ExpressionBuilder, columns: T) => + sql`nullif(array(select distinct unnest(${eb.ref('asset_exif.lockedProperties')} || ${columns})), '{}')`; + @Injectable() export class AssetRepository { constructor(@InjectKysely() private db: Kysely) {} - async upsertExif(exif: Insertable): Promise { - const value = { ...exif, assetId: asUuid(exif.assetId) }; + @GenerateSql({ + params: [ + { dateTimeOriginal: DummyValue.DATE, lockedProperties: ['dateTimeOriginal'] }, + { lockedPropertiesBehavior: 'append' }, + ], + }) + async upsertExif( + exif: Insertable, + { lockedPropertiesBehavior }: { lockedPropertiesBehavior: 'override' | 'append' | 'skip' }, + ): Promise { await this.db .insertInto('asset_exif') - .values(value) + .values(exif) .onConflict((oc) => - oc.column('assetId').doUpdateSet((eb) => - removeUndefinedKeys( - { - description: eb.ref('excluded.description'), - exifImageWidth: eb.ref('excluded.exifImageWidth'), - exifImageHeight: eb.ref('excluded.exifImageHeight'), - fileSizeInByte: eb.ref('excluded.fileSizeInByte'), - orientation: eb.ref('excluded.orientation'), - dateTimeOriginal: eb.ref('excluded.dateTimeOriginal'), - modifyDate: eb.ref('excluded.modifyDate'), - timeZone: eb.ref('excluded.timeZone'), - latitude: eb.ref('excluded.latitude'), - longitude: eb.ref('excluded.longitude'), - projectionType: eb.ref('excluded.projectionType'), - city: eb.ref('excluded.city'), - livePhotoCID: eb.ref('excluded.livePhotoCID'), - autoStackId: eb.ref('excluded.autoStackId'), - state: eb.ref('excluded.state'), - country: eb.ref('excluded.country'), - make: eb.ref('excluded.make'), - model: eb.ref('excluded.model'), - lensModel: eb.ref('excluded.lensModel'), - fNumber: eb.ref('excluded.fNumber'), - focalLength: eb.ref('excluded.focalLength'), - iso: eb.ref('excluded.iso'), - exposureTime: eb.ref('excluded.exposureTime'), - profileDescription: eb.ref('excluded.profileDescription'), - colorspace: eb.ref('excluded.colorspace'), - bitsPerSample: eb.ref('excluded.bitsPerSample'), - rating: eb.ref('excluded.rating'), - fps: eb.ref('excluded.fps'), - }, - value, - ), - ), + oc.column('assetId').doUpdateSet((eb) => { + const updateLocked = (col: T) => eb.ref(`excluded.${col}`); + const skipLocked = (col: T) => + eb + .case() + .when(sql`${col}`, '=', eb.fn.any('asset_exif.lockedProperties')) + .then(eb.ref(`asset_exif.${col}`)) + .else(eb.ref(`excluded.${col}`)) + .end(); + const ref = lockedPropertiesBehavior === 'skip' ? skipLocked : updateLocked; + return { + ...removeUndefinedKeys( + { + description: ref('description'), + exifImageWidth: ref('exifImageWidth'), + exifImageHeight: ref('exifImageHeight'), + fileSizeInByte: ref('fileSizeInByte'), + orientation: ref('orientation'), + dateTimeOriginal: ref('dateTimeOriginal'), + modifyDate: ref('modifyDate'), + timeZone: ref('timeZone'), + latitude: ref('latitude'), + longitude: ref('longitude'), + projectionType: ref('projectionType'), + city: ref('city'), + livePhotoCID: ref('livePhotoCID'), + autoStackId: ref('autoStackId'), + state: ref('state'), + country: ref('country'), + make: ref('make'), + model: ref('model'), + lensModel: ref('lensModel'), + fNumber: ref('fNumber'), + focalLength: ref('focalLength'), + iso: ref('iso'), + exposureTime: ref('exposureTime'), + profileDescription: ref('profileDescription'), + colorspace: ref('colorspace'), + bitsPerSample: ref('bitsPerSample'), + rating: ref('rating'), + fps: ref('fps'), + lockedProperties: + lockedPropertiesBehavior === 'append' + ? distinctLocked(eb, exif.lockedProperties ?? null) + : ref('lockedProperties'), + }, + exif, + ), + }; + }), ) .execute(); } @@ -169,19 +195,26 @@ export class AssetRepository { return; } - await this.db.updateTable('asset_exif').set(options).where('assetId', 'in', ids).execute(); + await this.db + .updateTable('asset_exif') + .set((eb) => ({ + ...options, + lockedProperties: distinctLocked(eb, Object.keys(options) as LockableProperty[]), + })) + .where('assetId', 'in', ids) + .execute(); } @GenerateSql({ params: [[DummyValue.UUID], DummyValue.NUMBER, DummyValue.STRING] }) @Chunked() - async updateDateTimeOriginal( - ids: string[], - delta?: number, - timeZone?: string, - ): Promise<{ assetId: string; dateTimeOriginal: Date | null; timeZone: string | null }[]> { - return await this.db + updateDateTimeOriginal(ids: string[], delta?: number, timeZone?: string) { + return this.db .updateTable('asset_exif') - .set({ dateTimeOriginal: sql`"dateTimeOriginal" + ${(delta ?? 0) + ' minute'}::interval`, timeZone }) + .set((eb) => ({ + dateTimeOriginal: sql`"dateTimeOriginal" + ${(delta ?? 0) + ' minute'}::interval`, + timeZone, + lockedProperties: distinctLocked(eb, ['dateTimeOriginal', 'timeZone']), + })) .where('assetId', 'in', ids) .returning(['assetId', 'dateTimeOriginal', 'timeZone']) .execute(); diff --git a/server/src/schema/migrations/1764957138636-AddLockedPropertiesToAssetExif.ts b/server/src/schema/migrations/1764957138636-AddLockedPropertiesToAssetExif.ts new file mode 100644 index 0000000000..0cd024a4d8 --- /dev/null +++ b/server/src/schema/migrations/1764957138636-AddLockedPropertiesToAssetExif.ts @@ -0,0 +1,9 @@ +import { Kysely, sql } from 'kysely'; + +export async function up(db: Kysely): Promise { + await sql`ALTER TABLE "asset_exif" ADD "lockedProperties" character varying[];`.execute(db); +} + +export async function down(db: Kysely): Promise { + await sql`ALTER TABLE "asset_exif" DROP COLUMN "lockedProperties";`.execute(db); +} diff --git a/server/src/schema/tables/asset-exif.table.ts b/server/src/schema/tables/asset-exif.table.ts index f28735a2db..346098a72c 100644 --- a/server/src/schema/tables/asset-exif.table.ts +++ b/server/src/schema/tables/asset-exif.table.ts @@ -1,3 +1,4 @@ +import { LockableProperty } from 'src/database'; import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators'; import { AssetTable } from 'src/schema/tables/asset.table'; import { Column, ForeignKeyColumn, Generated, Int8, Table, Timestamp, UpdateDateColumn } from 'src/sql-tools'; @@ -97,4 +98,7 @@ export class AssetExifTable { @UpdateIdColumn({ index: true }) updateId!: Generated; + + @Column({ type: 'character varying', array: true, nullable: true }) + lockedProperties!: Array | null; } diff --git a/server/src/services/asset-media.service.ts b/server/src/services/asset-media.service.ts index d2e1c14210..2bb8530c1c 100644 --- a/server/src/services/asset-media.service.ts +++ b/server/src/services/asset-media.service.ts @@ -370,7 +370,10 @@ export class AssetMediaService extends BaseService { : this.assetRepository.deleteFile({ assetId, type: AssetFileType.Sidecar })); await this.storageRepository.utimes(file.originalPath, new Date(), new Date(dto.fileModifiedAt)); - await this.assetRepository.upsertExif({ assetId, fileSizeInByte: file.size }); + await this.assetRepository.upsertExif( + { assetId, fileSizeInByte: file.size }, + { lockedPropertiesBehavior: 'override' }, + ); await this.jobRepository.queue({ name: JobName.AssetExtractMetadata, data: { id: assetId, source: 'upload' }, @@ -399,7 +402,10 @@ export class AssetMediaService extends BaseService { }); const { size } = await this.storageRepository.stat(created.originalPath); - await this.assetRepository.upsertExif({ assetId: created.id, fileSizeInByte: size }); + await this.assetRepository.upsertExif( + { assetId: created.id, fileSizeInByte: size }, + { lockedPropertiesBehavior: 'override' }, + ); await this.jobRepository.queue({ name: JobName.AssetExtractMetadata, data: { id: created.id, source: 'copy' } }); return created; } @@ -440,7 +446,10 @@ export class AssetMediaService extends BaseService { await this.storageRepository.utimes(sidecarFile.originalPath, new Date(), new Date(dto.fileModifiedAt)); } await this.storageRepository.utimes(file.originalPath, new Date(), new Date(dto.fileModifiedAt)); - await this.assetRepository.upsertExif({ assetId: asset.id, fileSizeInByte: file.size }); + await this.assetRepository.upsertExif( + { assetId: asset.id, fileSizeInByte: file.size }, + { lockedPropertiesBehavior: 'override' }, + ); await this.eventRepository.emit('AssetCreate', { asset }); diff --git a/server/src/services/asset.service.spec.ts b/server/src/services/asset.service.spec.ts index 878721e0a7..5e1cce2ccf 100755 --- a/server/src/services/asset.service.spec.ts +++ b/server/src/services/asset.service.spec.ts @@ -225,7 +225,10 @@ describe(AssetService.name, () => { await sut.update(authStub.admin, 'asset-1', { description: 'Test description' }); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith({ assetId: 'asset-1', description: 'Test description' }); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith( + { assetId: 'asset-1', description: 'Test description', lockedProperties: ['description'] }, + { lockedPropertiesBehavior: 'append' }, + ); }); it('should update the exif rating', async () => { @@ -235,7 +238,14 @@ describe(AssetService.name, () => { await sut.update(authStub.admin, 'asset-1', { rating: 3 }); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith({ assetId: 'asset-1', rating: 3 }); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith( + { + assetId: 'asset-1', + rating: 3, + lockedProperties: ['rating'], + }, + { lockedPropertiesBehavior: 'append' }, + ); }); it('should fail linking a live video if the motion part could not be found', async () => { @@ -427,9 +437,7 @@ describe(AssetService.name, () => { }); expect(mocks.asset.updateAll).toHaveBeenCalled(); expect(mocks.asset.updateAllExif).toHaveBeenCalledWith(['asset-1'], { latitude: 0, longitude: 0 }); - expect(mocks.job.queueAll).toHaveBeenCalledWith([ - { name: JobName.SidecarWrite, data: { id: 'asset-1', latitude: 0, longitude: 0 } }, - ]); + expect(mocks.job.queueAll).toHaveBeenCalledWith([{ name: JobName.SidecarWrite, data: { id: 'asset-1' } }]); }); it('should update exif table if latitude field is provided', async () => { @@ -450,9 +458,7 @@ describe(AssetService.name, () => { latitude: 30, longitude: 50, }); - expect(mocks.job.queueAll).toHaveBeenCalledWith([ - { name: JobName.SidecarWrite, data: { id: 'asset-1', dateTimeOriginal, latitude: 30, longitude: 50 } }, - ]); + expect(mocks.job.queueAll).toHaveBeenCalledWith([{ name: JobName.SidecarWrite, data: { id: 'asset-1' } }]); }); it('should update Assets table if duplicateId is provided as null', async () => { @@ -482,18 +488,7 @@ describe(AssetService.name, () => { timeZone, }); expect(mocks.asset.updateDateTimeOriginal).toHaveBeenCalledWith(['asset-1'], dateTimeRelative, timeZone); - expect(mocks.job.queueAll).toHaveBeenCalledWith([ - { - name: JobName.SidecarWrite, - data: { - id: 'asset-1', - dateTimeOriginal: '2020-02-25T06:41:00.000+02:00', - description: undefined, - latitude: undefined, - longitude: undefined, - }, - }, - ]); + expect(mocks.job.queueAll).toHaveBeenCalledWith([{ name: JobName.SidecarWrite, data: { id: 'asset-1' } }]); }); }); diff --git a/server/src/services/asset.service.ts b/server/src/services/asset.service.ts index 32c6526394..282d74a9b1 100644 --- a/server/src/services/asset.service.ts +++ b/server/src/services/asset.service.ts @@ -30,9 +30,10 @@ import { QueueName, } from 'src/enum'; import { BaseService } from 'src/services/base.service'; -import { ISidecarWriteJob, JobItem, JobOf } from 'src/types'; +import { JobItem, JobOf } from 'src/types'; import { requireElevatedPermission } from 'src/utils/access'; import { getAssetFiles, getMyPartnerIds, onAfterUnlink, onBeforeLink, onBeforeUnlink } from 'src/utils/asset.util'; +import { updateLockedColumns } from 'src/utils/database'; @Injectable() export class AssetService extends BaseService { @@ -142,56 +143,26 @@ export class AssetService extends BaseService { } = dto; await this.requireAccess({ auth, permission: Permission.AssetUpdate, ids }); - const assetDto = { isFavorite, visibility, duplicateId }; - const exifDto = { latitude, longitude, rating, description, dateTimeOriginal }; + const assetDto = _.omitBy({ isFavorite, visibility, duplicateId }, _.isUndefined); + const exifDto = _.omitBy({ latitude, longitude, rating, description, dateTimeOriginal }, _.isUndefined); - const isExifChanged = Object.values(exifDto).some((v) => v !== undefined); - if (isExifChanged) { + if (Object.keys(exifDto).length > 0) { await this.assetRepository.updateAllExif(ids, exifDto); } - const assets = - (dateTimeRelative !== undefined && dateTimeRelative !== 0) || timeZone !== undefined - ? await this.assetRepository.updateDateTimeOriginal(ids, dateTimeRelative, timeZone) - : undefined; - - const dateTimesWithTimezone = assets - ? assets.map((asset) => { - const isoString = asset.dateTimeOriginal?.toISOString(); - let dateTime = isoString ? DateTime.fromISO(isoString) : null; - - if (dateTime && asset.timeZone) { - dateTime = dateTime.setZone(asset.timeZone); - } - - return { - assetId: asset.assetId, - dateTimeOriginal: dateTime?.toISO() ?? null, - }; - }) - : ids.map((id) => ({ assetId: id, dateTimeOriginal })); - - if (dateTimesWithTimezone.length > 0) { - await this.jobRepository.queueAll( - dateTimesWithTimezone.map(({ assetId: id, dateTimeOriginal }) => ({ - name: JobName.SidecarWrite, - data: { - ...exifDto, - id, - dateTimeOriginal: dateTimeOriginal ?? undefined, - }, - })), - ); + if ((dateTimeRelative !== undefined && dateTimeRelative !== 0) || timeZone !== undefined) { + await this.assetRepository.updateDateTimeOriginal(ids, dateTimeRelative, timeZone); } - const isAssetChanged = Object.values(assetDto).some((v) => v !== undefined); - if (isAssetChanged) { + if (Object.keys(assetDto).length > 0) { await this.assetRepository.updateAll(ids, assetDto); - - if (visibility === AssetVisibility.Locked) { - await this.albumRepository.removeAssetsFromAll(ids); - } } + + if (visibility === AssetVisibility.Locked) { + await this.albumRepository.removeAssetsFromAll(ids); + } + + await this.jobRepository.queueAll(ids.map((id) => ({ name: JobName.SidecarWrite, data: { id } }))); } async copy( @@ -456,12 +427,25 @@ export class AssetService extends BaseService { return asset; } - private async updateExif(dto: ISidecarWriteJob) { + private async updateExif(dto: { + id: string; + description?: string; + dateTimeOriginal?: string; + latitude?: number; + longitude?: number; + rating?: number; + }) { const { id, description, dateTimeOriginal, latitude, longitude, rating } = dto; const writes = _.omitBy({ description, dateTimeOriginal, latitude, longitude, rating }, _.isUndefined); if (Object.keys(writes).length > 0) { - await this.assetRepository.upsertExif({ assetId: id, ...writes }); - await this.jobRepository.queue({ name: JobName.SidecarWrite, data: { id, ...writes } }); + await this.assetRepository.upsertExif( + updateLockedColumns({ + assetId: id, + ...writes, + }), + { lockedPropertiesBehavior: 'append' }, + ); + await this.jobRepository.queue({ name: JobName.SidecarWrite, data: { id } }); } } } diff --git a/server/src/services/metadata.service.spec.ts b/server/src/services/metadata.service.spec.ts index c0f930d3a6..98c906d9c7 100644 --- a/server/src/services/metadata.service.spec.ts +++ b/server/src/services/metadata.service.spec.ts @@ -187,7 +187,9 @@ describe(MetadataService.name, () => { await sut.handleMetadataExtraction({ id: assetStub.image.id }); expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.sidecar.id); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining({ dateTimeOriginal: sidecarDate })); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining({ dateTimeOriginal: sidecarDate }), { + lockedPropertiesBehavior: 'skip', + }); expect(mocks.asset.update).toHaveBeenCalledWith( expect.objectContaining({ id: assetStub.image.id, @@ -214,6 +216,7 @@ describe(MetadataService.name, () => { expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); expect(mocks.asset.upsertExif).toHaveBeenCalledWith( expect.objectContaining({ dateTimeOriginal: fileModifiedAt }), + { lockedPropertiesBehavior: 'skip' }, ); expect(mocks.asset.update).toHaveBeenCalledWith({ id: assetStub.image.id, @@ -238,7 +241,10 @@ describe(MetadataService.name, () => { await sut.handleMetadataExtraction({ id: assetStub.image.id }); expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining({ dateTimeOriginal: fileCreatedAt })); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith( + expect.objectContaining({ dateTimeOriginal: fileCreatedAt }), + { lockedPropertiesBehavior: 'skip' }, + ); expect(mocks.asset.update).toHaveBeenCalledWith({ id: assetStub.image.id, duration: null, @@ -258,6 +264,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ dateTimeOriginal: new Date('2022-01-01T00:00:00.000Z'), }), + { lockedPropertiesBehavior: 'skip' }, ); expect(mocks.asset.update).toHaveBeenCalledWith( @@ -281,7 +288,9 @@ describe(MetadataService.name, () => { await sut.handleMetadataExtraction({ id: assetStub.image.id }); expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining({ iso: 160 })); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining({ iso: 160 }), { + lockedPropertiesBehavior: 'skip', + }); expect(mocks.asset.update).toHaveBeenCalledWith({ id: assetStub.image.id, duration: null, @@ -310,6 +319,7 @@ describe(MetadataService.name, () => { expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); expect(mocks.asset.upsertExif).toHaveBeenCalledWith( expect.objectContaining({ city: null, state: null, country: null }), + { lockedPropertiesBehavior: 'skip' }, ); expect(mocks.asset.update).toHaveBeenCalledWith({ id: assetStub.withLocation.id, @@ -339,6 +349,7 @@ describe(MetadataService.name, () => { expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); expect(mocks.asset.upsertExif).toHaveBeenCalledWith( expect.objectContaining({ city: 'City', state: 'State', country: 'Country' }), + { lockedPropertiesBehavior: 'skip' }, ); expect(mocks.asset.update).toHaveBeenCalledWith({ id: assetStub.withLocation.id, @@ -358,7 +369,10 @@ describe(MetadataService.name, () => { await sut.handleMetadataExtraction({ id: assetStub.image.id }); expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining({ latitude: null, longitude: null })); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith( + expect.objectContaining({ latitude: null, longitude: null }), + { lockedPropertiesBehavior: 'skip' }, + ); }); it('should extract tags from TagsList', async () => { @@ -571,6 +585,7 @@ describe(MetadataService.name, () => { expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.video.id); expect(mocks.asset.upsertExif).toHaveBeenCalledWith( expect.objectContaining({ orientation: ExifOrientation.Rotate270CW.toString() }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -879,37 +894,40 @@ describe(MetadataService.name, () => { await sut.handleMetadataExtraction({ id: assetStub.image.id }); expect(mocks.assetJob.getForMetadataExtraction).toHaveBeenCalledWith(assetStub.image.id); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith({ - assetId: assetStub.image.id, - bitsPerSample: expect.any(Number), - autoStackId: null, - colorspace: tags.ColorSpace, - dateTimeOriginal: dateForTest, - description: tags.ImageDescription, - exifImageHeight: null, - exifImageWidth: null, - exposureTime: tags.ExposureTime, - fNumber: null, - fileSizeInByte: 123_456, - focalLength: tags.FocalLength, - fps: null, - iso: tags.ISO, - latitude: null, - lensModel: tags.LensModel, - livePhotoCID: tags.MediaGroupUUID, - longitude: null, - make: tags.Make, - model: tags.Model, - modifyDate: expect.any(Date), - orientation: tags.Orientation?.toString(), - profileDescription: tags.ProfileDescription, - projectionType: 'EQUIRECTANGULAR', - timeZone: tags.tz, - rating: tags.Rating, - country: null, - state: null, - city: null, - }); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith( + { + assetId: assetStub.image.id, + bitsPerSample: expect.any(Number), + autoStackId: null, + colorspace: tags.ColorSpace, + dateTimeOriginal: dateForTest, + description: tags.ImageDescription, + exifImageHeight: null, + exifImageWidth: null, + exposureTime: tags.ExposureTime, + fNumber: null, + fileSizeInByte: 123_456, + focalLength: tags.FocalLength, + fps: null, + iso: tags.ISO, + latitude: null, + lensModel: tags.LensModel, + livePhotoCID: tags.MediaGroupUUID, + longitude: null, + make: tags.Make, + model: tags.Model, + modifyDate: expect.any(Date), + orientation: tags.Orientation?.toString(), + profileDescription: tags.ProfileDescription, + projectionType: 'EQUIRECTANGULAR', + timeZone: tags.tz, + rating: tags.Rating, + country: null, + state: null, + city: null, + }, + { lockedPropertiesBehavior: 'skip' }, + ); expect(mocks.asset.update).toHaveBeenCalledWith( expect.objectContaining({ id: assetStub.image.id, @@ -943,6 +961,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ timeZone: 'UTC+0', }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1103,6 +1122,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ description: '', }), + { lockedPropertiesBehavior: 'skip' }, ); mockReadTags({ ImageDescription: ' my\n description' }); @@ -1111,6 +1131,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ description: 'my\n description', }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1123,6 +1144,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ description: '1000', }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1346,6 +1368,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ modifyDate: expect.any(Date), }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1358,6 +1381,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ rating: null, }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1370,6 +1394,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ rating: 5, }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1382,6 +1407,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ rating: -1, }), + { lockedPropertiesBehavior: 'skip' }, ); }); @@ -1503,7 +1529,9 @@ describe(MetadataService.name, () => { mockReadTags(exif); await sut.handleMetadataExtraction({ id: assetStub.image.id }); - expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining(expected)); + expect(mocks.asset.upsertExif).toHaveBeenCalledWith(expect.objectContaining(expected), { + lockedPropertiesBehavior: 'skip', + }); }); it.each([ @@ -1529,6 +1557,7 @@ describe(MetadataService.name, () => { expect.objectContaining({ lensModel: expected, }), + { lockedPropertiesBehavior: 'skip' }, ); }); }); @@ -1637,12 +1666,14 @@ describe(MetadataService.name, () => { describe('handleSidecarWrite', () => { it('should skip assets that no longer exist', async () => { + mocks.assetJob.getLockedPropertiesForMetadataExtraction.mockResolvedValue([]); mocks.assetJob.getForSidecarWriteJob.mockResolvedValue(void 0); await expect(sut.handleSidecarWrite({ id: 'asset-123' })).resolves.toBe(JobStatus.Failed); expect(mocks.metadata.writeTags).not.toHaveBeenCalled(); }); it('should skip jobs with no metadata', async () => { + mocks.assetJob.getLockedPropertiesForMetadataExtraction.mockResolvedValue([]); const asset = factory.jobAssets.sidecarWrite(); mocks.assetJob.getForSidecarWriteJob.mockResolvedValue(asset); await expect(sut.handleSidecarWrite({ id: asset.id })).resolves.toBe(JobStatus.Skipped); @@ -1655,20 +1686,22 @@ describe(MetadataService.name, () => { const gps = 12; const date = '2023-11-22T04:56:12.196Z'; + mocks.assetJob.getLockedPropertiesForMetadataExtraction.mockResolvedValue([ + 'description', + 'latitude', + 'longitude', + 'dateTimeOriginal', + ]); mocks.assetJob.getForSidecarWriteJob.mockResolvedValue(asset); await expect( sut.handleSidecarWrite({ id: asset.id, - description, - latitude: gps, - longitude: gps, - dateTimeOriginal: date, }), ).resolves.toBe(JobStatus.Success); expect(mocks.metadata.writeTags).toHaveBeenCalledWith(asset.files[0].path, { + DateTimeOriginal: date, Description: description, ImageDescription: description, - DateTimeOriginal: date, GPSLatitude: gps, GPSLongitude: gps, }); diff --git a/server/src/services/metadata.service.ts b/server/src/services/metadata.service.ts index a1267604b2..8da7c88ecc 100644 --- a/server/src/services/metadata.service.ts +++ b/server/src/services/metadata.service.ts @@ -290,7 +290,7 @@ export class MetadataService extends BaseService { }; const promises: Promise[] = [ - this.assetRepository.upsertExif(exifData), + this.assetRepository.upsertExif(exifData, { lockedPropertiesBehavior: 'skip' }), this.assetRepository.update({ id: asset.id, duration: this.getDuration(exifTags), @@ -393,22 +393,34 @@ export class MetadataService extends BaseService { @OnJob({ name: JobName.SidecarWrite, queue: QueueName.Sidecar }) async handleSidecarWrite(job: JobOf): Promise { - const { id, description, dateTimeOriginal, latitude, longitude, rating, tags } = job; + const { id, tags } = job; const asset = await this.assetJobRepository.getForSidecarWriteJob(id); if (!asset) { return JobStatus.Failed; } + const lockedProperties = await this.assetJobRepository.getLockedPropertiesForMetadataExtraction(id); const tagsList = (asset.tags || []).map((tag) => tag.value); const { sidecarFile } = getAssetFiles(asset.files); const sidecarPath = sidecarFile?.path || `${asset.originalPath}.xmp`; + const { description, dateTimeOriginal, latitude, longitude, rating } = _.pick( + { + description: asset.exifInfo.description, + dateTimeOriginal: asset.exifInfo.dateTimeOriginal, + latitude: asset.exifInfo.latitude, + longitude: asset.exifInfo.longitude, + rating: asset.exifInfo.rating, + }, + lockedProperties, + ); + const exif = _.omitBy( { Description: description, ImageDescription: description, - DateTimeOriginal: dateTimeOriginal, + DateTimeOriginal: dateTimeOriginal ? String(dateTimeOriginal) : undefined, GPSLatitude: latitude, GPSLongitude: longitude, Rating: rating, diff --git a/server/src/types.ts b/server/src/types.ts index a33dba490c..e404332fac 100644 --- a/server/src/types.ts +++ b/server/src/types.ts @@ -222,11 +222,6 @@ export interface IDeleteFilesJob extends IBaseJob { } export interface ISidecarWriteJob extends IEntityJob { - description?: string; - dateTimeOriginal?: string; - latitude?: number; - longitude?: number; - rating?: number; tags?: true; } diff --git a/server/src/utils/database.ts b/server/src/utils/database.ts index f8dbd5e78c..656e8e628a 100644 --- a/server/src/utils/database.ts +++ b/server/src/utils/database.ts @@ -15,7 +15,7 @@ import { PostgresJSDialect } from 'kysely-postgres-js'; import { jsonArrayFrom, jsonObjectFrom } from 'kysely/helpers/postgres'; import { parse } from 'pg-connection-string'; import postgres, { Notice, PostgresError } from 'postgres'; -import { columns, Exif, Person } from 'src/database'; +import { columns, Exif, lockableProperties, LockableProperty, Person } from 'src/database'; import { AssetFileType, AssetVisibility, DatabaseExtension, DatabaseSslMode } from 'src/enum'; import { AssetSearchBuilderOptions } from 'src/repositories/search.repository'; import { DB } from 'src/schema'; @@ -488,3 +488,10 @@ export function vectorIndexQuery({ vectorExtension, table, indexName, lists }: V } } } + +export const updateLockedColumns = & { lockedProperties?: LockableProperty[] }>( + exif: T, +) => { + exif.lockedProperties = lockableProperties.filter((property) => property in exif); + return exif; +}; diff --git a/server/test/medium.factory.ts b/server/test/medium.factory.ts index efcdc59793..82ea2cd1fc 100644 --- a/server/test/medium.factory.ts +++ b/server/test/medium.factory.ts @@ -202,7 +202,7 @@ export class MediumTestContext { } async newExif(dto: Insertable) { - const result = await this.get(AssetRepository).upsertExif(dto); + const result = await this.get(AssetRepository).upsertExif(dto, { lockedPropertiesBehavior: 'override' }); return { result }; } diff --git a/server/test/medium/specs/services/asset.service.spec.ts b/server/test/medium/specs/services/asset.service.spec.ts index 13bc1ca9a9..8b54019fcf 100644 --- a/server/test/medium/specs/services/asset.service.spec.ts +++ b/server/test/medium/specs/services/asset.service.spec.ts @@ -268,4 +268,65 @@ describe(AssetService.name, () => { }); }); }); + + describe('update', () => { + it('should update dateTimeOriginal', async () => { + const { sut, ctx } = setup(); + ctx.getMock(JobRepository).queue.mockResolvedValue(); + const { user } = await ctx.newUser(); + const auth = factory.auth({ user }); + const { asset } = await ctx.newAsset({ ownerId: user.id }); + await ctx.newExif({ assetId: asset.id, description: 'test' }); + + await expect( + ctx.database + .selectFrom('asset_exif') + .select('lockedProperties') + .where('assetId', '=', asset.id) + .executeTakeFirstOrThrow(), + ).resolves.toEqual({ lockedProperties: null }); + await sut.update(auth, asset.id, { dateTimeOriginal: '2023-11-19T18:11:00.000-07:00' }); + + await expect( + ctx.database + .selectFrom('asset_exif') + .select('lockedProperties') + .where('assetId', '=', asset.id) + .executeTakeFirstOrThrow(), + ).resolves.toEqual({ lockedProperties: ['dateTimeOriginal'] }); + await expect(ctx.get(AssetRepository).getById(asset.id, { exifInfo: true })).resolves.toEqual( + expect.objectContaining({ + exifInfo: expect.objectContaining({ dateTimeOriginal: '2023-11-20T01:11:00+00:00' }), + }), + ); + }); + }); + + describe('updateAll', () => { + it('should relatively update assets', async () => { + const { sut, ctx } = setup(); + ctx.getMock(JobRepository).queueAll.mockResolvedValue(); + const { user } = await ctx.newUser(); + const auth = factory.auth({ user }); + const { asset } = await ctx.newAsset({ ownerId: user.id }); + await ctx.newExif({ assetId: asset.id, dateTimeOriginal: '2023-11-19T18:11:00' }); + + await sut.updateAll(auth, { ids: [asset.id], dateTimeRelative: -11 }); + + await expect( + ctx.database + .selectFrom('asset_exif') + .select('lockedProperties') + .where('assetId', '=', asset.id) + .executeTakeFirstOrThrow(), + ).resolves.toEqual({ lockedProperties: ['timeZone', 'dateTimeOriginal'] }); + await expect(ctx.get(AssetRepository).getById(asset.id, { exifInfo: true })).resolves.toEqual( + expect.objectContaining({ + exifInfo: expect.objectContaining({ + dateTimeOriginal: '2023-11-19T18:00:00+00:00', + }), + }), + ); + }); + }); }); diff --git a/server/test/medium/specs/services/metadata.service.spec.ts b/server/test/medium/specs/services/metadata.service.spec.ts index 1d144e9c9c..4c3499857d 100644 --- a/server/test/medium/specs/services/metadata.service.spec.ts +++ b/server/test/medium/specs/services/metadata.service.spec.ts @@ -95,6 +95,7 @@ describe(MetadataService.name, () => { dateTimeOriginal: new Date(expected.dateTimeOriginal), timeZone: expected.timeZone, }), + { lockedPropertiesBehavior: 'skip' }, ); expect(mocks.asset.update).toHaveBeenCalledWith( diff --git a/server/test/medium/specs/sync/sync-album-asset-exif.spec.ts b/server/test/medium/specs/sync/sync-album-asset-exif.spec.ts index fd563f4db1..1865fc2c80 100644 --- a/server/test/medium/specs/sync/sync-album-asset-exif.spec.ts +++ b/server/test/medium/specs/sync/sync-album-asset-exif.spec.ts @@ -2,6 +2,7 @@ import { Kysely } from 'kysely'; import { AlbumUserRole, SyncEntityType, SyncRequestType } from 'src/enum'; import { AssetRepository } from 'src/repositories/asset.repository'; import { DB } from 'src/schema'; +import { updateLockedColumns } from 'src/utils/database'; import { SyncTestContext } from 'test/medium.factory'; import { factory } from 'test/small.factory'; import { getKyselyDB, wait } from 'test/utils'; @@ -288,10 +289,13 @@ describe(SyncRequestType.AlbumAssetExifsV1, () => { // update the asset const assetRepository = ctx.get(AssetRepository); - await assetRepository.upsertExif({ - assetId: asset.id, - city: 'New City', - }); + await assetRepository.upsertExif( + updateLockedColumns({ + assetId: asset.id, + city: 'New City', + }), + { lockedPropertiesBehavior: 'append' }, + ); await expect(ctx.syncStream(auth, [SyncRequestType.AlbumAssetExifsV1])).resolves.toEqual([ { @@ -346,10 +350,13 @@ describe(SyncRequestType.AlbumAssetExifsV1, () => { // update the asset const assetRepository = ctx.get(AssetRepository); - await assetRepository.upsertExif({ - assetId: assetDelayedExif.id, - city: 'Delayed Exif', - }); + await assetRepository.upsertExif( + updateLockedColumns({ + assetId: assetDelayedExif.id, + city: 'Delayed Exif', + }), + { lockedPropertiesBehavior: 'append' }, + ); await expect(ctx.syncStream(auth, [SyncRequestType.AlbumAssetExifsV1])).resolves.toEqual([ { diff --git a/server/test/small.factory.ts b/server/test/small.factory.ts index 13cccce176..53d7c70794 100644 --- a/server/test/small.factory.ts +++ b/server/test/small.factory.ts @@ -4,6 +4,7 @@ import { AuthApiKey, AuthSharedLink, AuthUser, + Exif, Library, Memory, Partner, @@ -319,18 +320,28 @@ const versionHistoryFactory = () => ({ version: '1.123.45', }); -const assetSidecarWriteFactory = () => ({ - id: newUuid(), - originalPath: '/path/to/original-path.jpg.xmp', - tags: [], - files: [ - { - id: newUuid(), - path: '/path/to/original-path.jpg.xmp', - type: AssetFileType.Sidecar, - }, - ], -}); +const assetSidecarWriteFactory = () => { + const id = newUuid(); + return { + id, + originalPath: '/path/to/original-path.jpg.xmp', + tags: [], + files: [ + { + id: newUuid(), + path: '/path/to/original-path.jpg.xmp', + type: AssetFileType.Sidecar, + }, + ], + exifInfo: { + assetId: id, + description: 'this is a description', + latitude: 12, + longitude: 12, + dateTimeOriginal: '2023-11-22T04:56:12.196Z', + } as unknown as Exif, + }; +}; const assetOcrFactory = ( ocr: { diff --git a/web/src/lib/components/album-page/album-viewer.svelte b/web/src/lib/components/album-page/album-viewer.svelte index 168637e134..d5fdb36822 100644 --- a/web/src/lib/components/album-page/album-viewer.svelte +++ b/web/src/lib/components/album-page/album-viewer.svelte @@ -12,6 +12,8 @@ import { AssetInteraction } from '$lib/stores/asset-interaction.svelte'; import { assetViewingStore } from '$lib/stores/asset-viewing.store'; import { dragAndDropFilesStore } from '$lib/stores/drag-and-drop-files.store'; + import { mobileDevice } from '$lib/stores/mobile-device.svelte'; + import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store'; import { handlePromiseError } from '$lib/utils'; import { cancelMultiselect } from '$lib/utils/asset-utils'; import { fileUploadHandler, openFileUploadDialog } from '$lib/utils/file-uploader'; @@ -22,7 +24,6 @@ import ControlAppBar from '../shared-components/control-app-bar.svelte'; import ThemeButton from '../shared-components/theme-button.svelte'; import AlbumSummary from './album-summary.svelte'; - import { SlideshowNavigation, SlideshowState, slideshowStore } from '$lib/stores/slideshow.store'; interface Props { sharedLink: SharedLinkResponseDto; @@ -110,7 +111,7 @@ {#snippet leading()} - + {/snippet} diff --git a/web/src/lib/components/asset-viewer/activity-status.svelte b/web/src/lib/components/asset-viewer/activity-status.svelte index 39c6f20b3b..dd06cf3ed0 100644 --- a/web/src/lib/components/asset-viewer/activity-status.svelte +++ b/web/src/lib/components/asset-viewer/activity-status.svelte @@ -2,7 +2,7 @@ import { locale } from '$lib/stores/preferences.store'; import type { ActivityResponseDto } from '@immich/sdk'; import { Icon } from '@immich/ui'; - import { mdiCommentOutline, mdiHeart, mdiHeartOutline } from '@mdi/js'; + import { mdiCommentOutline, mdiThumbUp, mdiThumbUpOutline } from '@mdi/js'; interface Props { isLiked: ActivityResponseDto | null; @@ -19,7 +19,7 @@