mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
refactor: api key response dto (#30887)
This commit is contained in:
parent
a066b5f301
commit
47c5a3dbf6
8 changed files with 104 additions and 37 deletions
|
|
@ -1,4 +1,5 @@
|
|||
import { createZodDto } from 'nestjs-zod';
|
||||
import { HistoryBuilder } from 'src/decorators';
|
||||
import { Permission } from 'src/enum';
|
||||
import { isoDatetimeToDate } from 'src/validation';
|
||||
import z from 'zod';
|
||||
|
|
@ -31,8 +32,9 @@ const ApiKeyResponseSchema = z
|
|||
|
||||
const ApiKeyCreateResponseSchema = z
|
||||
.object({
|
||||
...ApiKeyResponseSchema.shape,
|
||||
secret: z.string().describe('API key secret (only shown once)'),
|
||||
apiKey: ApiKeyResponseSchema,
|
||||
apiKey: ApiKeyResponseSchema.meta({ ...new HistoryBuilder().added('v1').deprecated('v3.2.0').getExtensions() }),
|
||||
})
|
||||
.meta({ id: 'ApiKeyCreateResponseDto' });
|
||||
|
||||
|
|
|
|||
|
|
@ -23,8 +23,9 @@ export class ApiKeyService extends BaseService {
|
|||
userId: auth.user.id,
|
||||
permissions: dto.permissions,
|
||||
});
|
||||
const apiKey = this.map(entity);
|
||||
|
||||
return { secret: token, apiKey: this.map(entity) };
|
||||
return { ...apiKey, secret: token, apiKey };
|
||||
}
|
||||
|
||||
async update(auth: AuthDto, id: string, dto: ApiKeyUpdateDto): Promise<ApiKeyResponseDto> {
|
||||
|
|
@ -58,10 +59,10 @@ export class ApiKeyService extends BaseService {
|
|||
|
||||
const token = this.cryptoRepository.randomBytesAsText(32);
|
||||
const hashed = this.cryptoRepository.hashSha256(token);
|
||||
|
||||
const newKey = await this.apiKeyRepository.update(auth.user.id, id, { key: hashed });
|
||||
const apiKey = this.map(newKey);
|
||||
|
||||
return { secret: token, apiKey: this.map(newKey) };
|
||||
return { ...apiKey, secret: token, apiKey };
|
||||
}
|
||||
|
||||
async delete(auth: AuthDto, id: string): Promise<void> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue