import { Exif } from 'src/database'; import { MapAsset } from 'src/dtos/asset-response.dto'; import { AssetEditAction, AssetEditActionItem } from 'src/dtos/editing.dto'; import { AssetFileType, AssetStatus, AssetType, AssetVisibility } from 'src/enum'; import { StorageAsset } from 'src/types'; import { userStub } from 'test/fixtures/user.stub'; import { factory } from 'test/small.factory'; export const previewFile = factory.assetFile({ type: AssetFileType.Preview }); const thumbnailFile = factory.assetFile({ type: AssetFileType.Thumbnail, path: '/uploads/user-id/webp/path.ext', }); const fullsizeFile = factory.assetFile({ type: AssetFileType.FullSize, path: '/uploads/user-id/fullsize/path.webp', }); const files = [fullsizeFile, previewFile, thumbnailFile]; export const stackStub = (stackId: string, assets: (MapAsset & { exifInfo: Exif })[]) => { return { id: stackId, assets, ownerId: assets[0].ownerId, primaryAsset: assets[0], primaryAssetId: assets[0].id, createdAt: new Date('2023-02-23T05:06:29.716Z'), updatedAt: new Date('2023-02-23T05:06:29.716Z'), updateId: expect.any(String), }; }; export const assetStub = { storageAsset: (asset: Partial = {}) => ({ id: 'asset-id', ownerId: 'user-id', livePhotoVideoId: null, type: AssetType.Image, isExternal: false, checksum: Buffer.from('file hash'), timeZone: null, fileCreatedAt: new Date('2022-06-19T23:41:36.910Z'), originalPath: '/original/path.jpg', originalFileName: 'IMG_123.jpg', fileSizeInByte: 12_345, files: [], make: 'FUJIFILM', model: 'X-T50', lensModel: 'XF27mm F2.8 R WR', isEdited: false, ...asset, }), primaryImage: Object.freeze({ id: 'primary-asset-id', status: AssetStatus.Active, deviceAssetId: 'device-asset-id', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'), fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'), owner: userStub.admin, ownerId: 'admin-id', deviceId: 'device-id', originalPath: '/original/path.jpg', checksum: Buffer.from('file hash', 'utf8'), files, type: AssetType.Image, thumbhash: Buffer.from('blablabla', 'base64'), encodedVideoPath: null, createdAt: new Date('2023-02-23T05:06:29.716Z'), updatedAt: new Date('2023-02-23T05:06:29.716Z'), localDateTime: new Date('2023-02-23T05:06:29.716Z'), isFavorite: true, duration: null, isExternal: false, livePhotoVideo: null, livePhotoVideoId: null, sharedLinks: [], originalFileName: 'asset-id.jpg', faces: [], deletedAt: null, exifInfo: { fileSizeInByte: 5000, exifImageHeight: 1000, exifImageWidth: 1000, } as Exif, stackId: 'stack-1', stack: stackStub('stack-1', [ { id: 'primary-asset-id' } as MapAsset & { exifInfo: Exif }, { id: 'stack-child-asset-1' } as MapAsset & { exifInfo: Exif }, { id: 'stack-child-asset-2' } as MapAsset & { exifInfo: Exif }, ]), duplicateId: null, isOffline: false, updateId: '42', libraryId: null, visibility: AssetVisibility.Timeline, width: null, height: null, edits: [], isEdited: false, }), withLocation: Object.freeze({ id: 'asset-with-favorite-id', status: AssetStatus.Active, deviceAssetId: 'device-asset-id', fileModifiedAt: new Date('2023-02-22T05:06:29.716Z'), fileCreatedAt: new Date('2023-02-22T05:06:29.716Z'), owner: userStub.user1, ownerId: 'user-id', deviceId: 'device-id', checksum: Buffer.from('file hash', 'utf8'), originalPath: '/original/path.ext', type: AssetType.Image, files: [previewFile], thumbhash: null, encodedVideoPath: null, createdAt: new Date('2023-02-22T05:06:29.716Z'), updatedAt: new Date('2023-02-22T05:06:29.716Z'), localDateTime: new Date('2020-12-31T23:59:00.000Z'), isFavorite: false, isExternal: false, duration: null, livePhotoVideo: null, livePhotoVideoId: null, updateId: 'foo', libraryId: null, stackId: null, sharedLinks: [], originalFileName: 'asset-id.ext', faces: [], exifInfo: { latitude: 100, longitude: 100, fileSizeInByte: 23_456, city: 'test-city', state: 'test-state', country: 'test-country', } as Exif, deletedAt: null, duplicateId: null, isOffline: false, tags: [], visibility: AssetVisibility.Timeline, width: null, height: null, edits: [], isEdited: false, }), hasEncodedVideo: Object.freeze({ id: 'asset-id', status: AssetStatus.Active, originalFileName: 'asset-id.ext', deviceAssetId: 'device-asset-id', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'), fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'), owner: userStub.user1, ownerId: 'user-id', deviceId: 'device-id', originalPath: '/original/path.ext', checksum: Buffer.from('file hash', 'utf8'), type: AssetType.Video, files: [previewFile], thumbhash: null, encodedVideoPath: '/encoded/video/path.mp4', createdAt: new Date('2023-02-23T05:06:29.716Z'), updatedAt: new Date('2023-02-23T05:06:29.716Z'), localDateTime: new Date('2023-02-23T05:06:29.716Z'), isFavorite: true, isExternal: false, duration: null, livePhotoVideo: null, livePhotoVideoId: null, sharedLinks: [], faces: [], exifInfo: { fileSizeInByte: 100_000, } as Exif, deletedAt: null, duplicateId: null, isOffline: false, updateId: '42', libraryId: null, stackId: null, stack: null, visibility: AssetVisibility.Timeline, width: null, height: null, edits: [], isEdited: false, }), imageDng: Object.freeze({ id: 'asset-id', status: AssetStatus.Active, deviceAssetId: 'device-asset-id', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'), fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'), owner: userStub.user1, ownerId: 'user-id', deviceId: 'device-id', originalPath: '/original/path.dng', checksum: Buffer.from('file hash', 'utf8'), type: AssetType.Image, files, thumbhash: Buffer.from('blablabla', 'base64'), encodedVideoPath: null, createdAt: new Date('2023-02-23T05:06:29.716Z'), updatedAt: new Date('2023-02-23T05:06:29.716Z'), localDateTime: new Date('2023-02-23T05:06:29.716Z'), isFavorite: true, duration: null, isExternal: false, livePhotoVideo: null, livePhotoVideoId: null, sharedLinks: [], originalFileName: 'asset-id.dng', faces: [], deletedAt: null, exifInfo: { fileSizeInByte: 5000, profileDescription: 'Adobe RGB', bitsPerSample: 14, } as Exif, duplicateId: null, isOffline: false, updateId: '42', libraryId: null, stackId: null, visibility: AssetVisibility.Timeline, width: null, height: null, edits: [], isEdited: false, }), withCropEdit: Object.freeze({ id: 'asset-id', status: AssetStatus.Active, deviceAssetId: 'device-asset-id', fileModifiedAt: new Date('2023-02-23T05:06:29.716Z'), fileCreatedAt: new Date('2023-02-23T05:06:29.716Z'), owner: userStub.user1, ownerId: 'user-id', deviceId: 'device-id', originalPath: '/original/path.jpg', files, checksum: Buffer.from('file hash', 'utf8'), type: AssetType.Image, thumbhash: Buffer.from('blablabla', 'base64'), encodedVideoPath: null, createdAt: new Date('2023-02-23T05:06:29.716Z'), updatedAt: new Date('2023-02-23T05:06:29.716Z'), localDateTime: new Date('2025-01-01T01:02:03.456Z'), isFavorite: true, duration: null, isExternal: false, livePhotoVideo: null, livePhotoVideoId: null, updateId: 'foo', libraryId: null, stackId: null, sharedLinks: [], originalFileName: 'asset-id.jpg', faces: [], deletedAt: null, sidecarPath: null, exifInfo: { fileSizeInByte: 5000, exifImageHeight: 3840, exifImageWidth: 2160, } as Exif, duplicateId: null, isOffline: false, stack: null, orientation: '', projectionType: null, height: 3840, width: 2160, visibility: AssetVisibility.Timeline, edits: [ { action: AssetEditAction.Crop, parameters: { width: 1512, height: 1152, x: 216, y: 1512, }, }, ] as AssetEditActionItem[], isEdited: true, }), };