feat(server): do not automatically download android motion videos (#11774)

feat(server): do not automatically download embedded android motion videos
This commit is contained in:
Jason Rasmussen 2024-08-15 16:06:16 -04:00 committed by GitHub
parent ed6971222c
commit 32c05ea950
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 151 additions and 28 deletions

View file

@ -33,12 +33,15 @@ class EmailNotificationsUpdate {
albumUpdate?: boolean;
}
class DownloadUpdate {
class DownloadUpdate implements Partial<DownloadResponse> {
@Optional()
@IsInt()
@IsPositive()
@ApiProperty({ type: 'integer' })
archiveSize?: number;
@ValidateBoolean({ optional: true })
includeEmbeddedVideos?: boolean;
}
class PurchaseUpdate {
@ -104,6 +107,8 @@ class EmailNotificationsResponse {
class DownloadResponse {
@ApiProperty({ type: 'integer' })
archiveSize!: number;
includeEmbeddedVideos: boolean = false;
}
class PurchaseResponse {

View file

@ -35,6 +35,7 @@ export interface UserPreferences {
};
download: {
archiveSize: number;
includeEmbeddedVideos: boolean;
};
purchase: {
showSupportBadge: boolean;
@ -65,6 +66,7 @@ export const getDefaultPreferences = (user: { email: string }): UserPreferences
},
download: {
archiveSize: HumanReadableSize.GiB * 4,
includeEmbeddedVideos: false,
},
purchase: {
showSupportBadge: true,

View file

@ -226,5 +226,31 @@ describe(DownloadService.name, () => {
],
});
});
it('should skip the video portion of an android live photo by default', async () => {
const assetIds = [assetStub.livePhotoStillAsset.id];
const assets = [
assetStub.livePhotoStillAsset,
{ ...assetStub.livePhotoMotionAsset, originalPath: 'upload/encoded-video/uuid-MP.mp4' },
];
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set(assetIds));
assetMock.getByIds.mockImplementation(
(ids) =>
Promise.resolve(
ids.map((id) => assets.find((asset) => asset.id === id)).filter((asset) => !!asset),
) as Promise<AssetEntity[]>,
);
await expect(sut.getDownloadInfo(authStub.admin, { assetIds })).resolves.toEqual({
totalSize: 25_000,
archives: [
{
assetIds: [assetStub.livePhotoStillAsset.id],
size: 25_000,
},
],
});
});
});
});

View file

@ -1,6 +1,7 @@
import { BadRequestException, Inject, Injectable } from '@nestjs/common';
import { parse } from 'node:path';
import { AccessCore } from 'src/cores/access.core';
import { StorageCore } from 'src/cores/storage.core';
import { AssetIdsDto } from 'src/dtos/asset.dto';
import { AuthDto } from 'src/dtos/auth.dto';
import { DownloadArchiveInfo, DownloadInfoDto, DownloadResponseDto } from 'src/dtos/download.dto';
@ -12,6 +13,7 @@ import { ILoggerRepository } from 'src/interfaces/logger.interface';
import { ImmichReadStream, IStorageRepository } from 'src/interfaces/storage.interface';
import { HumanReadableSize } from 'src/utils/bytes';
import { usePagination } from 'src/utils/pagination';
import { getPreferences } from 'src/utils/preferences';
@Injectable()
export class DownloadService {
@ -32,12 +34,22 @@ export class DownloadService {
const archives: DownloadArchiveInfo[] = [];
let archive: DownloadArchiveInfo = { size: 0, assetIds: [] };
const preferences = getPreferences(auth.user);
const assetPagination = await this.getDownloadAssets(auth, dto);
for await (const assets of assetPagination) {
// motion part of live photos
const motionIds = assets.map((asset) => asset.livePhotoVideoId).filter<string>((id): id is string => !!id);
const motionIds = assets.map((asset) => asset.livePhotoVideoId).filter((id): id is string => !!id);
if (motionIds.length > 0) {
assets.push(...(await this.assetRepository.getByIds(motionIds, { exifInfo: true })));
const motionAssets = await this.assetRepository.getByIds(motionIds, { exifInfo: true });
for (const motionAsset of motionAssets) {
if (
!StorageCore.isAndroidMotionPath(motionAsset.originalPath) ||
preferences.download.includeEmbeddedVideos
) {
assets.push(motionAsset);
}
}
}
for (const asset of assets) {