Skip to content

Commit 2db7183

Browse files
committed
Add auth.buyTheme function
1 parent 29206ed commit 2db7183

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

‎src/modules/auth.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,4 +640,43 @@ export async function clearBulkLoad() {
640640
await storage.idbDelete("adminCache").catch((e) => console.error('IDB delete failed', e));
641641
storage.delete("lastAdminBulkLoad");
642642
console.log('🟢 Bulk load cleared');
643+
}
644+
645+
export async function buyTheme(theme = null, cost = 0) {
646+
if (!theme || !cost || !storage.get("code")) return;
647+
await fetch(domain + '/buy_theme', {
648+
method: "POST",
649+
headers: {
650+
"Content-Type": "application/json",
651+
},
652+
body: JSON.stringify({
653+
"seatCode": storage.get("code"),
654+
"password": storage.get("password"),
655+
"theme": theme,
656+
"cost": cost,
657+
})
658+
})
659+
.then(async (r) => {
660+
if (!r.ok) {
661+
try {
662+
var re = await r.json();
663+
if (re.error || re.message) {
664+
ui.toast(re.error || re.message, 5000, "error", "bi bi-exclamation-triangle-fill");
665+
if ((re.error === "Access denied.") || (re.message === "Access denied.")) {
666+
if (storage.get("password")) storage.delete("password");
667+
}
668+
throw new Error(re.error || re.message);
669+
} else {
670+
throw new Error("API error");
671+
}
672+
} catch (e) {
673+
throw new Error(e.message || "API error");
674+
}
675+
}
676+
return await r.json();
677+
})
678+
.catch((e) => {
679+
console.error(e);
680+
if (!e.message || (e.message && !e.message.includes("."))) ui.view("api-fail");
681+
});
643682
}

0 commit comments

Comments
 (0)