Skip to content

Commit

Permalink
chore: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
zackpollard committed Jul 1, 2024
1 parent 0192416 commit 7282e0b
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 35 deletions.
32 changes: 24 additions & 8 deletions mobile/openapi/lib/model/license_response_dto.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 13 additions & 3 deletions open-api/immich-openapi-specs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8943,12 +8943,22 @@
},
"LicenseResponseDto": {
"properties": {
"valid": {
"type": "boolean"
"activatedAt": {
"format": "date-time",
"type": "string"
},
"activationKey": {
"type": "string"
},
"licenseKey": {
"pattern": "/IM(SV|CL)(-[\\dA-Za-z]{4}){8}/",
"type": "string"
}
},
"required": [
"valid"
"activatedAt",
"activationKey",
"licenseKey"
],
"type": "object"
},
Expand Down
4 changes: 3 additions & 1 deletion open-api/typescript-sdk/src/fetch-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,9 @@ export type LicenseKeyDto = {
licenseKey: string;
};
export type LicenseResponseDto = {
valid: boolean;
activatedAt: string;
activationKey: string;
licenseKey: string;
};
export type SessionResponseDto = {
createdAt: string;
Expand Down
4 changes: 2 additions & 2 deletions server/src/dtos/license.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ export class LicenseKeyDto {
activationKey!: string;
}

export class LicenseResponseDto {
valid!: boolean;
export class LicenseResponseDto extends LicenseKeyDto {
activatedAt!: Date;
}
20 changes: 11 additions & 9 deletions server/src/services/server.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,21 +172,23 @@ export class ServerService implements OnEvents {
if (!license.licenseKey.startsWith('IMSV-')) {
throw new BadRequestException('Invalid license key');
}
const trimmedLicenseKey = license.licenseKey;
const licenseValid = this.cryptoRepository.verifySha256(
trimmedLicenseKey,
license.licenseKey,
license.activationKey,
getServerLicensePublicKey(),
);

if (licenseValid) {
await this.systemMetadataRepository.set(SystemMetadataKey.LICENSE, {
licenseKey: license.licenseKey,
activationKey: license.activationKey,
activatedAt: new Date(),
});
if (!licenseValid) {
throw new BadRequestException('Invalid license key');
}

return { valid: licenseValid };
const licenseData = {
...license,
activatedAt: new Date(),
};

await this.systemMetadataRepository.set(SystemMetadataKey.LICENSE, licenseData);

return licenseData;
}
}
26 changes: 14 additions & 12 deletions server/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,25 +133,27 @@ export class UserService {
if (!license.licenseKey.startsWith('IMCL-')) {
throw new BadRequestException('Invalid license key');
}
const trimmedLicenseKey = license.licenseKey;
const licenseValid = this.cryptoRepository.verifySha256(
trimmedLicenseKey,
license.licenseKey,
license.activationKey,
getClientLicensePublicKey(),
);

if (licenseValid) {
await this.userRepository.upsertMetadata(auth.user.id, {
key: UserMetadataKey.LICENSE,
value: {
licenseKey: license.licenseKey,
activationKey: license.activationKey,
activatedAt: new Date(),
},
});
if (!licenseValid) {
throw new BadRequestException('Invalid license key');
}

return { valid: licenseValid };
const licenseData = {
...license,
activatedAt: new Date(),
};

await this.userRepository.upsertMetadata(auth.user.id, {
key: UserMetadataKey.LICENSE,
value: licenseData,
});

return licenseData;
}

async handleUserSyncUsage(): Promise<JobStatus> {
Expand Down

0 comments on commit 7282e0b

Please sign in to comment.