Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions apps/api/v2/src/modules/deployments/deployments.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const CACHING_TIME = 86400000; // 24 hours in milliseconds
const getLicenseCacheKey = (key: string) => `api-v2-license-key-goblin-url-${key}`;

type LicenseCheckResponse = {
status: boolean;
valid?: boolean;
status?: boolean;
};
@Injectable()
export class DeploymentsService {
Expand Down Expand Up @@ -36,12 +37,13 @@ export class DeploymentsService {
const licenseKeyUrl = this.configService.get("api.licenseKeyUrl") + `/${licenseKey}`;
const cachedData = await this.redisService.redis.get(getLicenseCacheKey(licenseKey));
if (cachedData) {
return (JSON.parse(cachedData) as LicenseCheckResponse)?.status;
const cached = JSON.parse(cachedData) as LicenseCheckResponse;
return cached.valid ?? cached.status ?? false;
}
const response = await fetch(licenseKeyUrl, { mode: "cors" });
const data = (await response.json()) as LicenseCheckResponse;
const cacheKey = getLicenseCacheKey(licenseKey);
this.redisService.redis.set(cacheKey, JSON.stringify(data), "EX", CACHING_TIME);
return data.status;
return data.valid ?? data.status ?? false;
}
}