feat(server): user and server license endpoints (#10682)
* feat: user license endpoints * feat: server license endpoints * chore: pr feedback * chore: add more test cases * chore: add prod license public keys * chore: open-api generation
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { IsNotEmpty, IsString, Matches } from 'class-validator';
|
||||
|
||||
export class LicenseKeyDto {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/IM(SV|CL)(-[\dA-Za-z]{4}){8}/)
|
||||
licenseKey!: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
activationKey!: string;
|
||||
}
|
||||
|
||||
export class LicenseResponseDto extends LicenseKeyDto {
|
||||
activatedAt!: Date;
|
||||
}
|
||||
@@ -28,6 +28,8 @@ export class ServerAboutResponseDto {
|
||||
imagemagick?: string;
|
||||
libvips?: string;
|
||||
exiftool?: string;
|
||||
|
||||
licensed!: boolean;
|
||||
}
|
||||
|
||||
export class ServerStorageResponseDto {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import { IsBoolean, IsEmail, IsNotEmpty, IsNumber, IsPositive, IsString } from 'class-validator';
|
||||
import { UserAvatarColor } from 'src/entities/user-metadata.entity';
|
||||
import { UserAvatarColor, UserMetadataEntity, UserMetadataKey } from 'src/entities/user-metadata.entity';
|
||||
import { UserEntity, UserStatus } from 'src/entities/user.entity';
|
||||
import { getPreferences } from 'src/utils/preferences';
|
||||
import { Optional, ValidateBoolean, toEmail, toSanitized } from 'src/validation';
|
||||
import { Optional, toEmail, toSanitized, ValidateBoolean } from 'src/validation';
|
||||
|
||||
export class UserUpdateMeDto {
|
||||
@Optional()
|
||||
@@ -33,6 +33,12 @@ export class UserResponseDto {
|
||||
avatarColor!: UserAvatarColor;
|
||||
}
|
||||
|
||||
export class UserLicense {
|
||||
licenseKey!: string;
|
||||
activationKey!: string;
|
||||
activatedAt!: Date;
|
||||
}
|
||||
|
||||
export const mapUser = (entity: UserEntity): UserResponseDto => {
|
||||
return {
|
||||
id: entity.id,
|
||||
@@ -130,9 +136,13 @@ export class UserAdminResponseDto extends UserResponseDto {
|
||||
quotaUsageInBytes!: number | null;
|
||||
@ApiProperty({ enumName: 'UserStatus', enum: UserStatus })
|
||||
status!: string;
|
||||
license!: UserLicense | null;
|
||||
}
|
||||
|
||||
export function mapUserAdmin(entity: UserEntity): UserAdminResponseDto {
|
||||
const license = entity.metadata.find(
|
||||
(item): item is UserMetadataEntity<UserMetadataKey.LICENSE> => item.key === UserMetadataKey.LICENSE,
|
||||
)?.value;
|
||||
return {
|
||||
...mapUser(entity),
|
||||
storageLabel: entity.storageLabel,
|
||||
@@ -145,5 +155,6 @@ export function mapUserAdmin(entity: UserEntity): UserAdminResponseDto {
|
||||
quotaSizeInBytes: entity.quotaSizeInBytes,
|
||||
quotaUsageInBytes: entity.quotaUsageInBytes,
|
||||
status: entity.status,
|
||||
license: license ?? null,
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user