MCPcopy
hub / github.com/immich-app/immich / create

Method create

server/src/services/api-key.service.ts:11–27  ·  view source on GitHub ↗
(auth: AuthDto, dto: ApiKeyCreateDto)

Source from the content-addressed store, hash-verified

9@Injectable()
10export class ApiKeyService extends BaseService {
11 async create(auth: AuthDto, dto: ApiKeyCreateDto): Promise<ApiKeyCreateResponseDto> {
12 const token = this.cryptoRepository.randomBytesAsText(32);
13 const hashed = this.cryptoRepository.hashSha256(token);
14
15 if (auth.apiKey && !isGranted({ requested: dto.permissions, current: auth.apiKey.permissions })) {
16 throw new BadRequestException('Cannot grant permissions you do not have');
17 }
18
19 const entity = await this.apiKeyRepository.create({
20 key: hashed,
21 name: dto.name || 'API Key',
22 userId: auth.user.id,
23 permissions: dto.permissions,
24 });
25
26 return { secret: token, apiKey: this.map(entity) };
27 }
28
29 async update(auth: AuthDto, id: string, dto: ApiKeyUpdateDto): Promise<ApiKeyResponseDto> {
30 const exists = await this.apiKeyRepository.getById(auth.user.id, id);

Callers

nothing calls this directly

Calls 4

mapMethod · 0.95
isGrantedFunction · 0.90
randomBytesAsTextMethod · 0.80
hashSha256Method · 0.80

Tested by

no test coverage detected