@@ -615,11 +753,81 @@
}
}
+ async function loadUserGuilds() {
+ try {
+ const res = await fetch('/api/user');
+ if (!res.ok) return;
+
+ const data = await res.json();
+ if (!data.user?.guilds) return;
+
+ const adminGuilds = data.user.guilds.filter(g => g.isAdmin);
+
+ const premiumSelect = document.getElementById('premiumGuildSelect');
+ const featuredSelect = document.getElementById('featuredGuildSelect');
+
+ adminGuilds.forEach(g => {
+ const option1 = new Option(g.name, g.id);
+ const option2 = new Option(g.name, g.id);
+ premiumSelect.appendChild(option1);
+ featuredSelect.appendChild(option2);
+ });
+ } catch (e) {
+ console.error('Failed to load user guilds:', e);
+ }
+ }
+
+ async function upgradePlan(planType) {
+ const selectId = planType === 'premium' ? 'premiumGuildSelect' : 'featuredGuildSelect';
+ const guildId = document.getElementById(selectId).value;
+
+ if (!guildId) {
+ alert('Please select a server first');
+ return;
+ }
+
+ try {
+ const res = await fetch('/api/stripe/create-checkout', {
+ method: 'POST',
+ headers: { 'Content-Type': 'application/json' },
+ body: JSON.stringify({ guildId, planType })
+ });
+
+ if (!res.ok) {
+ const error = await res.json();
+ if (res.status === 401) {
+ alert('Please log in first using Discord');
+ window.location.href = '/auth/discord';
+ return;
+ }
+ throw new Error(error.error || 'Failed to create checkout');
+ }
+
+ const data = await res.json();
+ if (data.url) {
+ window.location.href = data.url;
+ }
+ } catch (e) {
+ alert('Failed to start checkout: ' + e.message);
+ }
+ }
+
+ const urlParams = new URLSearchParams(window.location.search);
+ if (urlParams.get('success') === 'true') {
+ const plan = urlParams.get('plan');
+ alert(`Successfully upgraded to ${plan === 'premium' ? 'Premium' : 'Featured Slot'}! Your server is now protected.`);
+ window.history.replaceState({}, '', '/federation');
+ }
+ if (urlParams.get('canceled') === 'true') {
+ window.history.replaceState({}, '', '/federation');
+ }
+
loadStats();
loadServers();
loadBans();
loadApplications();
loadLeaderboard();
+ loadUserGuilds();