mirror of
https://github.com/immich-app/immich.git
synced 2025-12-21 17:25:35 +03:00
* refactor(server): tsconfigs * chore: dummy commit * fix: start.sh * chore: restore original entry scripts
28 lines
815 B
TypeScript
28 lines
815 B
TypeScript
import { Injectable, UnauthorizedException } from '@nestjs/common';
|
|
import { AuthUserDto } from '../auth';
|
|
import { ICryptoRepository } from '../crypto';
|
|
import { IKeyRepository } from './api-key.repository';
|
|
|
|
@Injectable()
|
|
export class APIKeyCore {
|
|
constructor(private crypto: ICryptoRepository, private repository: IKeyRepository) {}
|
|
|
|
async validate(token: string): Promise<AuthUserDto | null> {
|
|
const hashedToken = this.crypto.hashSha256(token);
|
|
const keyEntity = await this.repository.getKey(hashedToken);
|
|
if (keyEntity?.user) {
|
|
const user = keyEntity.user;
|
|
|
|
return {
|
|
id: user.id,
|
|
email: user.email,
|
|
isAdmin: user.isAdmin,
|
|
isPublicUser: false,
|
|
isAllowUpload: true,
|
|
};
|
|
}
|
|
|
|
throw new UnauthorizedException('Invalid API key');
|
|
}
|
|
}
|