🐛 Use api to fetch magic spell instead of page data

This commit is contained in:
2025-07-24 01:32:35 +08:00
parent d95ea249fb
commit 362713873b
3 changed files with 1 additions and 36 deletions

View File

@@ -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()

View File

@@ -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
};
}
}

View File

@@ -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();