mirror of
https://github.com/fosrl/pangolin.git
synced 2025-08-29 06:08:15 +02:00
fix try catch in supporter keys
This commit is contained in:
parent
f2a14e6a36
commit
7118ae374d
1 changed files with 35 additions and 32 deletions
|
@ -245,9 +245,7 @@ export class Config {
|
||||||
: "false";
|
: "false";
|
||||||
process.env.DASHBOARD_URL = parsedConfig.data.app.dashboard_url;
|
process.env.DASHBOARD_URL = parsedConfig.data.app.dashboard_url;
|
||||||
|
|
||||||
this.checkSupporterKey().catch((error) => {
|
this.checkSupporterKey();
|
||||||
console.error("Error checking supporter key:", error);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.rawConfig = parsedConfig.data;
|
this.rawConfig = parsedConfig.data;
|
||||||
}
|
}
|
||||||
|
@ -295,43 +293,44 @@ export class Config {
|
||||||
|
|
||||||
const { key: licenseKey, githubUsername } = key;
|
const { key: licenseKey, githubUsername } = key;
|
||||||
|
|
||||||
const response = await fetch(
|
try {
|
||||||
"https://api.dev.fossorial.io/api/v1/license/validate",
|
const response = await fetch(
|
||||||
{
|
"https://api.dev.fossorial.io/api/v1/license/validate",
|
||||||
method: "POST",
|
{
|
||||||
headers: {
|
method: "POST",
|
||||||
"Content-Type": "application/json"
|
headers: {
|
||||||
},
|
"Content-Type": "application/json"
|
||||||
body: JSON.stringify({
|
},
|
||||||
licenseKey,
|
body: JSON.stringify({
|
||||||
githubUsername
|
licenseKey,
|
||||||
})
|
githubUsername
|
||||||
|
})
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
this.supporterData = key;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
const data = await response.json();
|
||||||
this.supporterData = key;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
if (!data.data.valid) {
|
||||||
|
this.supporterData = {
|
||||||
|
...key,
|
||||||
|
valid: false
|
||||||
|
};
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!data.data.valid) {
|
|
||||||
this.supporterData = {
|
this.supporterData = {
|
||||||
...key,
|
...key,
|
||||||
valid: false
|
tier: data.data.tier,
|
||||||
|
valid: true
|
||||||
};
|
};
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.supporterData = {
|
// update the supporter key in the database
|
||||||
...key,
|
await db
|
||||||
tier: data.data.tier,
|
|
||||||
valid: true
|
|
||||||
};
|
|
||||||
|
|
||||||
// update the supporter key in the database
|
|
||||||
await db
|
|
||||||
.update(supporterKey)
|
.update(supporterKey)
|
||||||
.set({
|
.set({
|
||||||
tier: data.data.tier || null,
|
tier: data.data.tier || null,
|
||||||
|
@ -339,6 +338,10 @@ export class Config {
|
||||||
valid: true
|
valid: true
|
||||||
})
|
})
|
||||||
.where(eq(supporterKey.keyId, key.keyId));
|
.where(eq(supporterKey.keyId, key.keyId));
|
||||||
|
} catch (e) {
|
||||||
|
this.supporterData = key;
|
||||||
|
console.error("Failed to validate supporter key", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public getSupporterData() {
|
public getSupporterData() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue