mirror of
https://github.com/immich-app/immich
synced 2026-08-22 13:13:05 +00:00
Some checks are pending
CodeQL / Analyze (push) Waiting to run
Docker / pre-job (push) Waiting to run
Docker / Re-Tag ML (push) Blocked by required conditions
Docker / Re-Tag Server (push) Blocked by required conditions
Docker / Build and Push ML (push) Blocked by required conditions
Docker / Build and Push Server (push) Blocked by required conditions
Docker / Docker Build & Push Server Success (push) Blocked by required conditions
Docker / Docker Build & Push ML Success (push) Blocked by required conditions
Docs build / pre-job (push) Waiting to run
Docs build / Docs Build (push) Blocked by required conditions
Zizmor / Zizmor (push) Waiting to run
Static Code Analysis / pre-job (push) Waiting to run
Static Code Analysis / Run Dart Code Analysis (push) Blocked by required conditions
Test / pre-job (push) Waiting to run
Test / Test & Lint Server (push) Blocked by required conditions
Test / Unit Test CLI (push) Blocked by required conditions
Test / Unit Test CLI (Windows) (push) Blocked by required conditions
Test / Lint Web (push) Blocked by required conditions
Test / Test Web (push) Blocked by required conditions
Test / Test i18n (push) Blocked by required conditions
Test / End-to-End Lint (push) Blocked by required conditions
Test / Medium Tests (Server) (push) Blocked by required conditions
Test / End-to-End Tests (Server & CLI) (push) Blocked by required conditions
Test / End-to-End Tests (Web) (push) Blocked by required conditions
Test / End-to-End Tests Success (push) Blocked by required conditions
Test / Unit Test Mobile (push) Blocked by required conditions
Test / Unit Test ML (push) Blocked by required conditions
Test / .github Files Formatting (push) Blocked by required conditions
Test / ShellCheck (push) Waiting to run
Test / OpenAPI Clients (push) Waiting to run
Test / SQL Schema Checks (push) Waiting to run
* fix: Any asset update disables isFavorite action in GUI. Only owner of asset in album should see favorited image. * Fix unit tests * Fix formatting * better query, add medium test * update sql --------- Co-authored-by: mertalev <101130780+mertalev@users.noreply.github.com>
81 lines
3 KiB
TypeScript
81 lines
3 KiB
TypeScript
import { BadRequestException, Injectable } from '@nestjs/common';
|
|
import { AuthDto } from 'src/dtos/auth.dto';
|
|
import { TimeBucketAssetDto, TimeBucketDto, TimeBucketsResponseDto } from 'src/dtos/time-bucket.dto';
|
|
import { AssetVisibility, Permission } from 'src/enum';
|
|
import { TimeBucketOptions } from 'src/repositories/asset.repository';
|
|
import { BaseService } from 'src/services/base.service';
|
|
import { requireElevatedPermission } from 'src/utils/access';
|
|
import { getMyPartnerIds } from 'src/utils/asset.util';
|
|
|
|
@Injectable()
|
|
export class TimelineService extends BaseService {
|
|
async getTimeBuckets(auth: AuthDto, dto: TimeBucketDto): Promise<TimeBucketsResponseDto[]> {
|
|
await this.timeBucketChecks(auth, dto);
|
|
const timeBucketOptions = await this.buildTimeBucketOptions(auth, dto);
|
|
return await this.assetRepository.getTimeBuckets(timeBucketOptions);
|
|
}
|
|
|
|
// pre-jsonified response
|
|
async getTimeBucket(auth: AuthDto, dto: TimeBucketAssetDto): Promise<string> {
|
|
await this.timeBucketChecks(auth, dto);
|
|
const timeBucketOptions = await this.buildTimeBucketOptions(auth, { ...dto });
|
|
|
|
// TODO: use id cursor for pagination
|
|
const bucket = await this.assetRepository.getTimeBucket(dto.timeBucket, timeBucketOptions, auth);
|
|
return bucket.assets;
|
|
}
|
|
|
|
private async buildTimeBucketOptions(auth: AuthDto, dto: TimeBucketDto): Promise<TimeBucketOptions> {
|
|
const { userId, ...options } = dto;
|
|
let userIds: string[] | undefined = undefined;
|
|
|
|
if (userId) {
|
|
userIds = [userId];
|
|
if (dto.withPartners) {
|
|
const partnerIds = await getMyPartnerIds({
|
|
userId: auth.user.id,
|
|
repository: this.partnerRepository,
|
|
timelineEnabled: true,
|
|
});
|
|
userIds.push(...partnerIds);
|
|
}
|
|
}
|
|
|
|
return { ...options, userIds };
|
|
}
|
|
|
|
private async timeBucketChecks(auth: AuthDto, dto: TimeBucketDto) {
|
|
if (dto.visibility === AssetVisibility.Locked) {
|
|
requireElevatedPermission(auth);
|
|
}
|
|
|
|
if (dto.albumId) {
|
|
await this.requireAccess({ auth, permission: Permission.AlbumRead, ids: [dto.albumId] });
|
|
} else {
|
|
dto.userId = dto.userId || auth.user.id;
|
|
}
|
|
|
|
if (dto.userId) {
|
|
await this.requireAccess({ auth, permission: Permission.TimelineRead, ids: [dto.userId] });
|
|
if (dto.visibility === AssetVisibility.Archive) {
|
|
await this.requireAccess({ auth, permission: Permission.ArchiveRead, ids: [dto.userId] });
|
|
}
|
|
}
|
|
|
|
if (dto.tagId) {
|
|
await this.requireAccess({ auth, permission: Permission.TagRead, ids: [dto.tagId] });
|
|
}
|
|
|
|
if (dto.withPartners) {
|
|
const requestedArchived = dto.visibility === AssetVisibility.Archive || dto.visibility === undefined;
|
|
const requestedFavorite = dto.isFavorite === true || dto.isFavorite === false;
|
|
const requestedTrash = dto.isTrashed === true;
|
|
|
|
if (requestedArchived || requestedFavorite || requestedTrash) {
|
|
throw new BadRequestException(
|
|
'withPartners is only supported for non-archived, non-trashed, non-favorited assets',
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|