🐛 Use api to fetch magic spell instead of page data
This commit is contained in:
		| @@ -58,7 +58,7 @@ const submitting = ref(false) | ||||
| const done = ref(false) | ||||
|  | ||||
| const spellTypes = [ | ||||
|   'Account Acivation', | ||||
|   'Account Activation', | ||||
|   'Account Deactivation', | ||||
|   'Account Deletion', | ||||
|   'Reset Password', | ||||
| @@ -66,12 +66,6 @@ const spellTypes = [ | ||||
| ] | ||||
|  | ||||
| async function fetchSpell() { | ||||
|   // @ts-ignore | ||||
|   if (window.__APP_DATA__ != null) { | ||||
|     // @ts-ignore | ||||
|     spell.value = window.__APP_DATA__['Spell'] | ||||
|     return | ||||
|   } | ||||
|   const resp = await fetch(`/api/spells/${encodeURIComponent(spellWord)}`) | ||||
|   if (resp.status === 200) { | ||||
|     const data = await resp.json() | ||||
|   | ||||
| @@ -1,28 +0,0 @@ | ||||
| using DysonNetwork.Shared.PageData; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using NodaTime; | ||||
|  | ||||
| namespace DysonNetwork.Pass.Pages.Data; | ||||
|  | ||||
| public class SpellPageData(AppDatabase db) : IPageDataProvider | ||||
| { | ||||
|     public bool CanHandlePath(PathString path) => path.StartsWithSegments("/spells"); | ||||
|  | ||||
|     public async Task<IDictionary<string, object?>> GetAppDataAsync(HttpContext context) | ||||
|     { | ||||
|         var spellWord = context.Request.Path.Value!.Split('/').Last(); | ||||
|         spellWord = Uri.UnescapeDataString(spellWord); | ||||
|         var now = SystemClock.Instance.GetCurrentInstant(); | ||||
|         var spell = await db.MagicSpells | ||||
|             .Where(e => e.Spell == spellWord) | ||||
|             .Where(e => e.ExpiresAt == null || now < e.ExpiresAt) | ||||
|             .Where(e => e.AffectedAt == null || now >= e.AffectedAt) | ||||
|             .Include(e => e.Account) | ||||
|             .ThenInclude(e => e.Profile) | ||||
|             .FirstOrDefaultAsync(); | ||||
|         return new Dictionary<string, object?> | ||||
|         { | ||||
|             ["Spell"] = spell | ||||
|         }; | ||||
|     } | ||||
| } | ||||
| @@ -34,7 +34,6 @@ builder.Services.AddAppScheduledJobs(); | ||||
|  | ||||
| builder.Services.AddTransient<IPageDataProvider, VersionPageData>(); | ||||
| builder.Services.AddTransient<IPageDataProvider, CaptchaPageData>(); | ||||
| builder.Services.AddTransient<IPageDataProvider, SpellPageData>(); | ||||
|  | ||||
| var app = builder.Build(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user