1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02:00

refactor(server): change asset entity to date type (#2599)

* refactor(server): change asset entity to date type

* lower coverage threshold
This commit is contained in:
Michel Heusschen 2023-05-29 16:05:14 +02:00 committed by GitHub
parent caba462703
commit 94d0705607
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 72 additions and 67 deletions

View File

@ -15,9 +15,9 @@ class Asset {
Asset.remote(AssetResponseDto remote) Asset.remote(AssetResponseDto remote)
: remoteId = remote.id, : remoteId = remote.id,
isLocal = false, isLocal = false,
fileCreatedAt = DateTime.parse(remote.fileCreatedAt), fileCreatedAt = remote.fileCreatedAt,
fileModifiedAt = DateTime.parse(remote.fileModifiedAt), fileModifiedAt = remote.fileModifiedAt,
updatedAt = DateTime.parse(remote.updatedAt), updatedAt = remote.updatedAt,
durationInSeconds = remote.duration.toDuration()?.inSeconds ?? 0, durationInSeconds = remote.duration.toDuration()?.inSeconds ?? 0,
type = remote.type.toAssetType(), type = remote.type.toAssetType(),
fileName = p.basename(remote.originalPath), fileName = p.basename(remote.originalPath),

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -37,8 +37,8 @@ const _getCreateAssetDto = (): CreateAssetDto => {
createAssetDto.deviceAssetId = 'deviceAssetId'; createAssetDto.deviceAssetId = 'deviceAssetId';
createAssetDto.deviceId = 'deviceId'; createAssetDto.deviceId = 'deviceId';
createAssetDto.assetType = AssetType.OTHER; createAssetDto.assetType = AssetType.OTHER;
createAssetDto.fileCreatedAt = '2022-06-19T23:41:36.910Z'; createAssetDto.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z');
createAssetDto.fileModifiedAt = '2022-06-19T23:41:36.910Z'; createAssetDto.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z');
createAssetDto.isFavorite = false; createAssetDto.isFavorite = false;
createAssetDto.isArchived = false; createAssetDto.isArchived = false;
createAssetDto.duration = '0:00:00.000000'; createAssetDto.duration = '0:00:00.000000';
@ -56,9 +56,9 @@ const _getAsset_1 = () => {
asset_1.type = AssetType.VIDEO; asset_1.type = AssetType.VIDEO;
asset_1.originalPath = 'fake_path/asset_1.jpeg'; asset_1.originalPath = 'fake_path/asset_1.jpeg';
asset_1.resizePath = ''; asset_1.resizePath = '';
asset_1.fileModifiedAt = '2022-06-19T23:41:36.910Z'; asset_1.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z');
asset_1.fileCreatedAt = '2022-06-19T23:41:36.910Z'; asset_1.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z');
asset_1.updatedAt = '2022-06-19T23:41:36.910Z'; asset_1.updatedAt = new Date('2022-06-19T23:41:36.910Z');
asset_1.isFavorite = false; asset_1.isFavorite = false;
asset_1.isArchived = false; asset_1.isArchived = false;
asset_1.mimeType = 'image/jpeg'; asset_1.mimeType = 'image/jpeg';
@ -81,9 +81,9 @@ const _getAsset_2 = () => {
asset_2.type = AssetType.VIDEO; asset_2.type = AssetType.VIDEO;
asset_2.originalPath = 'fake_path/asset_2.jpeg'; asset_2.originalPath = 'fake_path/asset_2.jpeg';
asset_2.resizePath = ''; asset_2.resizePath = '';
asset_2.fileModifiedAt = '2022-06-19T23:41:36.910Z'; asset_2.fileModifiedAt = new Date('2022-06-19T23:41:36.910Z');
asset_2.fileCreatedAt = '2022-06-19T23:41:36.910Z'; asset_2.fileCreatedAt = new Date('2022-06-19T23:41:36.910Z');
asset_2.updatedAt = '2022-06-19T23:41:36.910Z'; asset_2.updatedAt = new Date('2022-06-19T23:41:36.910Z');
asset_2.isFavorite = false; asset_2.isFavorite = false;
asset_2.isArchived = false; asset_2.isArchived = false;
asset_2.mimeType = 'image/jpeg'; asset_2.mimeType = 'image/jpeg';

View File

@ -16,10 +16,10 @@ export class CreateAssetDto {
assetType!: AssetType; assetType!: AssetType;
@IsNotEmpty() @IsNotEmpty()
fileCreatedAt!: string; fileCreatedAt!: Date;
@IsNotEmpty() @IsNotEmpty()
fileModifiedAt!: string; fileModifiedAt!: Date;
@IsNotEmpty() @IsNotEmpty()
isFavorite!: boolean; isFavorite!: boolean;

View File

@ -214,7 +214,7 @@ export class MetadataExtractionProcessor {
} }
await this.exifRepository.upsert(newExif, { conflictPaths: ['assetId'] }); await this.exifRepository.upsert(newExif, { conflictPaths: ['assetId'] });
await this.assetRepository.save({ id: asset.id, fileCreatedAt: fileCreatedAt?.toISOString() }); await this.assetRepository.save({ id: asset.id, fileCreatedAt: fileCreatedAt || undefined });
return true; return true;
} }
@ -227,9 +227,9 @@ export class MetadataExtractionProcessor {
const videoTags = data.format.tags; const videoTags = data.format.tags;
if (videoTags) { if (videoTags) {
if (videoTags['com.apple.quicktime.creationdate']) { if (videoTags['com.apple.quicktime.creationdate']) {
fileCreatedAt = String(videoTags['com.apple.quicktime.creationdate']); fileCreatedAt = new Date(videoTags['com.apple.quicktime.creationdate']);
} else if (videoTags['creation_time']) { } else if (videoTags['creation_time']) {
fileCreatedAt = String(videoTags['creation_time']); fileCreatedAt = new Date(videoTags['creation_time']);
} }
} }

View File

@ -4450,12 +4450,15 @@
"type": "boolean" "type": "boolean"
}, },
"fileCreatedAt": { "fileCreatedAt": {
"format": "date-time",
"type": "string" "type": "string"
}, },
"fileModifiedAt": { "fileModifiedAt": {
"format": "date-time",
"type": "string" "type": "string"
}, },
"updatedAt": { "updatedAt": {
"format": "date-time",
"type": "string" "type": "string"
}, },
"isFavorite": { "isFavorite": {
@ -5783,9 +5786,11 @@
"type": "string" "type": "string"
}, },
"fileCreatedAt": { "fileCreatedAt": {
"format": "date-time",
"type": "string" "type": "string"
}, },
"fileModifiedAt": { "fileModifiedAt": {
"format": "date-time",
"type": "string" "type": "string"
}, },
"isFavorite": { "isFavorite": {

View File

@ -15,8 +15,8 @@ export interface LivePhotoSearchOptions {
export interface MapMarkerSearchOptions { export interface MapMarkerSearchOptions {
isFavorite?: boolean; isFavorite?: boolean;
fileCreatedBefore?: string; fileCreatedBefore?: Date;
fileCreatedAfter?: string; fileCreatedAfter?: Date;
} }
export interface MapMarker { export interface MapMarker {

View File

@ -1,7 +1,7 @@
import { ApiProperty } from '@nestjs/swagger'; import { ApiProperty } from '@nestjs/swagger';
import { toBoolean } from 'apps/immich/src/utils/transform.util'; import { toBoolean } from 'apps/immich/src/utils/transform.util';
import { Transform } from 'class-transformer'; import { Transform, Type } from 'class-transformer';
import { IsBoolean, IsISO8601, IsOptional } from 'class-validator'; import { IsBoolean, IsDate, IsOptional } from 'class-validator';
export class MapMarkerDto { export class MapMarkerDto {
@ApiProperty() @ApiProperty()
@ -10,13 +10,13 @@ export class MapMarkerDto {
@Transform(toBoolean) @Transform(toBoolean)
isFavorite?: boolean; isFavorite?: boolean;
@ApiProperty({ format: 'date-time' })
@IsOptional() @IsOptional()
@IsISO8601({ strict: true, strictSeparator: true }) @IsDate()
fileCreatedAfter?: string; @Type(() => Date)
fileCreatedAfter?: Date;
@ApiProperty({ format: 'date-time' })
@IsOptional() @IsOptional()
@IsISO8601({ strict: true, strictSeparator: true }) @IsDate()
fileCreatedBefore?: string; @Type(() => Date)
fileCreatedBefore?: Date;
} }

View File

@ -16,9 +16,9 @@ export class AssetResponseDto {
originalPath!: string; originalPath!: string;
originalFileName!: string; originalFileName!: string;
resized!: boolean; resized!: boolean;
fileCreatedAt!: string; fileCreatedAt!: Date;
fileModifiedAt!: string; fileModifiedAt!: Date;
updatedAt!: string; updatedAt!: Date;
isFavorite!: boolean; isFavorite!: boolean;
isArchived!: boolean; isArchived!: boolean;
mimeType!: string | null; mimeType!: string | null;

View File

@ -107,7 +107,7 @@ export class StorageTemplateCore {
this.render( this.render(
template, template,
{ {
fileCreatedAt: new Date().toISOString(), fileCreatedAt: new Date(),
originalPath: '/upload/test/IMG_123.jpg', originalPath: '/upload/test/IMG_123.jpg',
type: AssetType.IMAGE, type: AssetType.IMAGE,
} as AssetEntity, } as AssetEntity,
@ -140,7 +140,7 @@ export class StorageTemplateCore {
filetypefull: asset.type == AssetType.IMAGE ? 'IMAGE' : 'VIDEO', filetypefull: asset.type == AssetType.IMAGE ? 'IMAGE' : 'VIDEO',
}; };
const dt = luxon.DateTime.fromISO(new Date(asset.fileCreatedAt).toISOString()); const dt = luxon.DateTime.fromJSDate(asset.fileCreatedAt);
const dateTokens = [ const dateTokens = [
...supportedYearTokens, ...supportedYearTokens,

View File

@ -140,8 +140,8 @@ export const assetEntityStub = {
id: 'asset-id', id: 'asset-id',
originalFileName: 'asset_1.jpeg', originalFileName: 'asset_1.jpeg',
deviceAssetId: 'device-asset-id', deviceAssetId: 'device-asset-id',
fileModifiedAt: '2023-02-23T05:06:29.716Z', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'),
fileCreatedAt: '2023-02-23T05:06:29.716Z', fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'),
owner: userEntityStub.user1, owner: userEntityStub.user1,
ownerId: 'user-id', ownerId: 'user-id',
deviceId: 'device-id', deviceId: 'device-id',
@ -151,8 +151,8 @@ export const assetEntityStub = {
type: AssetType.IMAGE, type: AssetType.IMAGE,
webpPath: null, webpPath: null,
encodedVideoPath: null, encodedVideoPath: null,
createdAt: '2023-02-23T05:06:29.716Z', createdAt: new Date('2023-02-23T05:06:29.716Z'),
updatedAt: '2023-02-23T05:06:29.716Z', updatedAt: new Date('2023-02-23T05:06:29.716Z'),
mimeType: null, mimeType: null,
isFavorite: true, isFavorite: true,
isArchived: false, isArchived: false,
@ -168,8 +168,8 @@ export const assetEntityStub = {
image: Object.freeze<AssetEntity>({ image: Object.freeze<AssetEntity>({
id: 'asset-id', id: 'asset-id',
deviceAssetId: 'device-asset-id', deviceAssetId: 'device-asset-id',
fileModifiedAt: '2023-02-23T05:06:29.716Z', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'),
fileCreatedAt: '2023-02-23T05:06:29.716Z', fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'),
owner: userEntityStub.user1, owner: userEntityStub.user1,
ownerId: 'user-id', ownerId: 'user-id',
deviceId: 'device-id', deviceId: 'device-id',
@ -179,8 +179,8 @@ export const assetEntityStub = {
type: AssetType.IMAGE, type: AssetType.IMAGE,
webpPath: null, webpPath: null,
encodedVideoPath: null, encodedVideoPath: null,
createdAt: '2023-02-23T05:06:29.716Z', createdAt: new Date('2023-02-23T05:06:29.716Z'),
updatedAt: '2023-02-23T05:06:29.716Z', updatedAt: new Date('2023-02-23T05:06:29.716Z'),
mimeType: null, mimeType: null,
isFavorite: true, isFavorite: true,
isArchived: false, isArchived: false,
@ -198,8 +198,8 @@ export const assetEntityStub = {
id: 'asset-id', id: 'asset-id',
originalFileName: 'asset-id.ext', originalFileName: 'asset-id.ext',
deviceAssetId: 'device-asset-id', deviceAssetId: 'device-asset-id',
fileModifiedAt: '2023-02-23T05:06:29.716Z', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'),
fileCreatedAt: '2023-02-23T05:06:29.716Z', fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'),
owner: userEntityStub.user1, owner: userEntityStub.user1,
ownerId: 'user-id', ownerId: 'user-id',
deviceId: 'device-id', deviceId: 'device-id',
@ -209,8 +209,8 @@ export const assetEntityStub = {
type: AssetType.VIDEO, type: AssetType.VIDEO,
webpPath: null, webpPath: null,
encodedVideoPath: null, encodedVideoPath: null,
createdAt: '2023-02-23T05:06:29.716Z', createdAt: new Date('2023-02-23T05:06:29.716Z'),
updatedAt: '2023-02-23T05:06:29.716Z', updatedAt: new Date('2023-02-23T05:06:29.716Z'),
mimeType: null, mimeType: null,
isFavorite: true, isFavorite: true,
isArchived: false, isArchived: false,
@ -229,8 +229,8 @@ export const assetEntityStub = {
ownerId: authStub.user1.id, ownerId: authStub.user1.id,
type: AssetType.VIDEO, type: AssetType.VIDEO,
isVisible: false, isVisible: false,
fileModifiedAt: '2022-06-19T23:41:36.910Z', fileModifiedAt: new Date('2022-06-19T23:41:36.910Z'),
fileCreatedAt: '2022-06-19T23:41:36.910Z', fileCreatedAt: new Date('2022-06-19T23:41:36.910Z'),
} as AssetEntity), } as AssetEntity),
livePhotoStillAsset: Object.freeze({ livePhotoStillAsset: Object.freeze({
@ -240,15 +240,15 @@ export const assetEntityStub = {
type: AssetType.IMAGE, type: AssetType.IMAGE,
livePhotoVideoId: 'live-photo-motion-asset', livePhotoVideoId: 'live-photo-motion-asset',
isVisible: true, isVisible: true,
fileModifiedAt: '2022-06-19T23:41:36.910Z', fileModifiedAt: new Date('2022-06-19T23:41:36.910Z'),
fileCreatedAt: '2022-06-19T23:41:36.910Z', fileCreatedAt: new Date('2022-06-19T23:41:36.910Z'),
} as AssetEntity), } as AssetEntity),
withLocation: Object.freeze<AssetEntity>({ withLocation: Object.freeze<AssetEntity>({
id: 'asset-with-favorite-id', id: 'asset-with-favorite-id',
deviceAssetId: 'device-asset-id', deviceAssetId: 'device-asset-id',
fileModifiedAt: '2023-02-23T05:06:29.716Z', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'),
fileCreatedAt: '2023-02-23T05:06:29.716Z', fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'),
owner: userEntityStub.user1, owner: userEntityStub.user1,
ownerId: 'user-id', ownerId: 'user-id',
deviceId: 'device-id', deviceId: 'device-id',
@ -259,8 +259,8 @@ export const assetEntityStub = {
type: AssetType.IMAGE, type: AssetType.IMAGE,
webpPath: null, webpPath: null,
encodedVideoPath: null, encodedVideoPath: null,
createdAt: '2023-02-23T05:06:29.716Z', createdAt: new Date('2023-02-23T05:06:29.716Z'),
updatedAt: '2023-02-23T05:06:29.716Z', updatedAt: new Date('2023-02-23T05:06:29.716Z'),
mimeType: null, mimeType: null,
isFavorite: false, isFavorite: false,
isArchived: false, isArchived: false,
@ -280,8 +280,8 @@ export const assetEntityStub = {
sidecar: Object.freeze<AssetEntity>({ sidecar: Object.freeze<AssetEntity>({
id: 'asset-id', id: 'asset-id',
deviceAssetId: 'device-asset-id', deviceAssetId: 'device-asset-id',
fileModifiedAt: '2023-02-23T05:06:29.716Z', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'),
fileCreatedAt: '2023-02-23T05:06:29.716Z', fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'),
owner: userEntityStub.user1, owner: userEntityStub.user1,
ownerId: 'user-id', ownerId: 'user-id',
deviceId: 'device-id', deviceId: 'device-id',
@ -291,8 +291,8 @@ export const assetEntityStub = {
type: AssetType.IMAGE, type: AssetType.IMAGE,
webpPath: null, webpPath: null,
encodedVideoPath: null, encodedVideoPath: null,
createdAt: '2023-02-23T05:06:29.716Z', createdAt: new Date('2023-02-23T05:06:29.716Z'),
updatedAt: '2023-02-23T05:06:29.716Z', updatedAt: new Date('2023-02-23T05:06:29.716Z'),
mimeType: null, mimeType: null,
isFavorite: true, isFavorite: true,
isArchived: false, isArchived: false,
@ -447,9 +447,9 @@ const assetResponse: AssetResponseDto = {
originalPath: 'fake_path/jpeg', originalPath: 'fake_path/jpeg',
originalFileName: 'asset_1.jpeg', originalFileName: 'asset_1.jpeg',
resized: false, resized: false,
fileModifiedAt: today.toISOString(), fileModifiedAt: today,
fileCreatedAt: today.toISOString(), fileCreatedAt: today,
updatedAt: today.toISOString(), updatedAt: today,
isFavorite: false, isFavorite: false,
isArchived: false, isArchived: false,
mimeType: 'image/jpeg', mimeType: 'image/jpeg',
@ -700,10 +700,10 @@ export const sharedLinkStub = {
originalPath: 'fake_path/jpeg', originalPath: 'fake_path/jpeg',
resizePath: '', resizePath: '',
checksum: Buffer.from('file hash', 'utf8'), checksum: Buffer.from('file hash', 'utf8'),
fileModifiedAt: today.toISOString(), fileModifiedAt: today,
fileCreatedAt: today.toISOString(), fileCreatedAt: today,
createdAt: today.toISOString(), createdAt: today,
updatedAt: today.toISOString(), updatedAt: today,
isFavorite: false, isFavorite: false,
isArchived: false, isArchived: false,
mimeType: 'image/jpeg', mimeType: 'image/jpeg',

View File

@ -55,16 +55,16 @@ export class AssetEntity {
encodedVideoPath!: string | null; encodedVideoPath!: string | null;
@CreateDateColumn({ type: 'timestamptz' }) @CreateDateColumn({ type: 'timestamptz' })
createdAt!: string; createdAt!: Date;
@UpdateDateColumn({ type: 'timestamptz' }) @UpdateDateColumn({ type: 'timestamptz' })
updatedAt!: string; updatedAt!: Date;
@Column({ type: 'timestamptz' }) @Column({ type: 'timestamptz' })
fileCreatedAt!: string; fileCreatedAt!: Date;
@Column({ type: 'timestamptz' }) @Column({ type: 'timestamptz' })
fileModifiedAt!: string; fileModifiedAt!: Date;
@Column({ type: 'boolean', default: false }) @Column({ type: 'boolean', default: false })
isFavorite!: boolean; isFavorite!: boolean;

View File

@ -141,7 +141,7 @@
"./libs/domain/": { "./libs/domain/": {
"branches": 80, "branches": 80,
"functions": 87, "functions": 87,
"lines": 93.8, "lines": 93.7,
"statements": 93 "statements": 93
} }
}, },