Skip to content

Commit

Permalink
Namming convention + isUndefined on service
Browse files Browse the repository at this point in the history
  • Loading branch information
YFrendo committed Nov 21, 2023
1 parent c03fd59 commit c9274c1
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 48 deletions.
4 changes: 2 additions & 2 deletions cli/src/api/open-api/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mobile/openapi/doc/AssetBulkUpdateDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion mobile/openapi/doc/UpdateAssetDto.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions mobile/openapi/lib/model/asset_bulk_update_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions mobile/openapi/lib/model/update_asset_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mobile/openapi/test/asset_bulk_update_dto_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions mobile/openapi/test/update_asset_dto_test.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions server/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -6404,7 +6404,7 @@
},
"AssetBulkUpdateDto": {
"properties": {
"creationDate": {
"dateTimeOriginal": {
"type": "string"
},
"ids": {
Expand Down Expand Up @@ -9320,7 +9320,7 @@
},
"UpdateAssetDto": {
"properties": {
"creationDate": {
"dateTimeOriginal": {
"type": "string"
},
"description": {
Expand Down
12 changes: 6 additions & 6 deletions server/src/domain/asset/asset.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,17 @@ export class AssetService {
async update(authUser: AuthUserDto, id: string, dto: UpdateAssetDto): Promise<AssetResponseDto> {
await this.access.requirePermission(authUser, Permission.ASSET_UPDATE, id);

const { description, creationDate, latitude, longitude, ...rest } = dto;
const { description, dateTimeOriginal, latitude, longitude, ...rest } = dto;
if (description !== undefined) {
await this.assetRepository.upsertExif({ assetId: id, description });
}

if (creationDate !== undefined || latitude !== undefined || longitude !== undefined) {
if (dateTimeOriginal !== undefined || latitude !== undefined || longitude !== undefined) {
await this.jobRepository.queue({
name: JobName.WRITE_EXIF,
data: {
id: id,
creationDate: creationDate,
CreationDate: dateTimeOriginal,
GPSLatitude: latitude,
GPSLongitude: longitude,
},
Expand All @@ -412,7 +412,7 @@ export class AssetService {
}

async updateAll(authUser: AuthUserDto, dto: AssetBulkUpdateDto): Promise<void> {
const { ids, removeParent, creationDate, latitude, longitude, ...options } = dto;
const { ids, removeParent, dateTimeOriginal, latitude, longitude, ...options } = dto;
await this.access.requirePermission(authUser, Permission.ASSET_UPDATE, ids);

if (removeParent) {
Expand All @@ -432,13 +432,13 @@ export class AssetService {
await this.assetRepository.updateAll([options.stackParentId], { stackParentId: null });
}

if (creationDate !== undefined || latitude !== undefined || longitude !== undefined) {
if (dateTimeOriginal !== undefined || latitude !== undefined || longitude !== undefined) {
for (const id of ids) {
await this.jobRepository.queue({
name: JobName.WRITE_EXIF,
data: {
id: id,
creationDate: creationDate,
CreationDate: dateTimeOriginal,
GPSLatitude: latitude,
GPSLongitude: longitude,
},
Expand Down
4 changes: 2 additions & 2 deletions server/src/domain/asset/dto/asset.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export class AssetBulkUpdateDto extends BulkIdsDto {

@Optional()
@IsDateString()
creationDate?: string;
dateTimeOriginal?: string;

@ValidateGPS()
@IsLatitude()
Expand Down Expand Up @@ -219,7 +219,7 @@ export class UpdateAssetDto {

@Optional()
@IsDateString()
creationDate?: string;
dateTimeOriginal?: string;

@ValidateGPS()
@IsLatitude()
Expand Down
2 changes: 1 addition & 1 deletion server/src/domain/job/job.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export interface IDeleteFilesJob extends IBaseJob {
}

export interface IWriteExifJob extends IEntityJob {
creationDate?: string;
CreationDate?: string;
GPSLatitude?: number;
GPSLongitude?: number;
}
17 changes: 10 additions & 7 deletions server/src/domain/metadata/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Inject, Injectable, Logger } from '@nestjs/common';
import { ExifDateTime, Tags } from 'exiftool-vendored';
import { firstDateTime } from 'exiftool-vendored/dist/FirstDateTime';
import { constants } from 'fs/promises';
import _ from 'lodash';
import { Duration } from 'luxon';
import { Subscription } from 'rxjs';
import { usePagination } from '../domain.util';
Expand Down Expand Up @@ -239,8 +240,14 @@ export class MetadataService {
return true;
}

async handleWriteExif({ id, creationDate, GPSLatitude, GPSLongitude }: IWriteExifJob) {
async handleWriteExif({ id, CreationDate, GPSLatitude, GPSLongitude }: IWriteExifJob) {
const asset = await this.assetRepository.getById(id);
const newExifData = {
CreationDate: CreationDate,
GPSLatitude: GPSLatitude,
GPSLongitude: GPSLongitude,
};

if (!asset) {
return false;
}
Expand All @@ -253,13 +260,9 @@ export class MetadataService {
pathMetadata = asset.sidecarPath;
}

const newExifData = {
...(creationDate !== undefined && { CreationDate: creationDate }),
...(typeof GPSLatitude == 'number' && { GPSLatitude: GPSLatitude }),
...(typeof GPSLongitude === 'number' && { GPSLongitude: GPSLongitude }),
};
const cleanedExifData = _.omitBy(newExifData, _.isUndefined);

await this.assetRepository.writeExif(pathMetadata, newExifData);
await this.assetRepository.writeExif(pathMetadata, cleanedExifData);
await this.assetRepository.save({ id, sidecarPath: pathMetadata });
await this.jobRepository.queue({ name: JobName.METADATA_EXTRACTION, data: { id: id } });

Expand Down
4 changes: 2 additions & 2 deletions web/src/api/open-api/api.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion web/src/lib/components/asset-viewer/detail-panel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
await api.assetApi.updateAsset({
id: asset.id,
updateAssetDto: {
creationDate: event.detail,
dateTimeOriginal: event.detail,
},
});
notificationController.show({ message: 'Metadata updated please reload to apply', type: NotificationType.Info });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
await api.assetApi.updateAssets({
assetBulkUpdateDto: {
ids: ids,
creationDate: event.detail,
dateTimeOriginal: event.detail,
},
});
notificationController.show({ message: 'Metadata updated please reload to apply', type: NotificationType.Info });
Expand Down

0 comments on commit c9274c1

Please sign in to comment.