Skip to content

armgit / TREK

Public Imported from GitHub
0

The most complete open-source travel planner: real-time collaboration, bookings, budgets, packing lists, journals, offline PWA, SSO and an AI-ready MCP server, with planet-wide place search and routing built in.

1020 B
Raw Blame
import { Users } from '../../db/entities/Users.entity';
import { likeAny, StorageReclaimSource } from '../storage/storage-reclaim-source.service';
import { Injectable } from '@nestjs/common';

/**
 * Tells the storage reclaim pass which avatar objects a user row still names
 * (#2924). `users.avatar` holds the bare object name of an uploaded avatar;
 * an https picture taken from the OIDC claim names no object of ours and
 * parses as nothing.
 */
@Injectable()
export class AuthStorageRefsService extends StorageReclaimSource {
  readonly id = 'auth';
  readonly claims = [{ category: 'avatars', prefix: '' }] as const;
  protected override readonly keyOptions = { bare: 'avatars' } as const;

  protected async storedValues(containing: readonly string[] | null): Promise<Array<string | null | undefined>> {
    const rows = await this.em
      .getRepository(Users)
      .find(likeAny<Users>(this.em.getPlatform(), ['avatar'], containing), { fields: ['avatar'] });
    return rows.map((row) => row.avatar);
  }
}