From 80fd664cc8405b61e41177f476bbc2e2e993298a Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 27 Mar 2022 15:47:49 -0500 Subject: [PATCH] Better error message for duplicate file (#78) * Added try/catch block for saving new asset to database * Fixed typo for email field * Added check before generating thumbnail or tag images --- mobile/lib/modules/login/ui/login_form.dart | 2 +- server/src/api-v1/asset/asset.controller.ts | 23 +++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/mobile/lib/modules/login/ui/login_form.dart b/mobile/lib/modules/login/ui/login_form.dart index f6e07c188a..76e6f5bcb7 100644 --- a/mobile/lib/modules/login/ui/login_form.dart +++ b/mobile/lib/modules/login/ui/login_form.dart @@ -78,7 +78,7 @@ class EmailInput extends StatelessWidget { return TextFormField( controller: controller, decoration: - const InputDecoration(labelText: 'email', border: OutlineInputBorder(), hintText: 'youremail@email.com'), + const InputDecoration(labelText: 'Email', border: OutlineInputBorder(), hintText: 'youremail@email.com'), ); } } diff --git a/server/src/api-v1/asset/asset.controller.ts b/server/src/api-v1/asset/asset.controller.ts index dfb0a82b55..4af564caf6 100644 --- a/server/src/api-v1/asset/asset.controller.ts +++ b/server/src/api-v1/asset/asset.controller.ts @@ -13,6 +13,7 @@ import { Response, Headers, Delete, + Logger, } from '@nestjs/common'; import { JwtAuthGuard } from '../../modules/immich-jwt/guards/jwt-auth.guard'; import { AssetService } from './asset.service'; @@ -55,17 +56,21 @@ export class AssetController { @Body(ValidationPipe) assetInfo: CreateAssetDto, ) { for (const file of uploadFiles.assetData) { - const savedAsset = await this.assetService.createUserAsset(authUser, assetInfo, file.path, file.mimetype); + try { + const savedAsset = await this.assetService.createUserAsset(authUser, assetInfo, file.path, file.mimetype); - if (uploadFiles.thumbnailData != null) { - await this.assetService.updateThumbnailInfo(savedAsset.id, uploadFiles.thumbnailData[0].path); - await this.backgroundTaskService.tagImage(uploadFiles.thumbnailData[0].path, savedAsset); - await this.backgroundTaskService.detectObject(uploadFiles.thumbnailData[0].path, savedAsset); + if (uploadFiles.thumbnailData != null && savedAsset) { + await this.assetService.updateThumbnailInfo(savedAsset.id, uploadFiles.thumbnailData[0].path); + await this.backgroundTaskService.tagImage(uploadFiles.thumbnailData[0].path, savedAsset); + await this.backgroundTaskService.detectObject(uploadFiles.thumbnailData[0].path, savedAsset); + } + + await this.backgroundTaskService.extractExif(savedAsset, file.originalname, file.size); + + this.wsCommunicateionGateway.server.to(savedAsset.userId).emit('on_upload_success', JSON.stringify(savedAsset)); + } catch (e) { + Logger.error(`Error receiving upload file ${e}`); } - - await this.backgroundTaskService.extractExif(savedAsset, file.originalname, file.size); - - this.wsCommunicateionGateway.server.to(savedAsset.userId).emit('on_upload_success', JSON.stringify(savedAsset)); } return 'ok';