Use database branding for PWA manifest
This commit is contained in:
1 parent
0231c468a4
commit
ea76ef29ba
4 files changed
+36
No files matched your search
@@ -16,6 +16,19 @@ public sealed class BusinessSettingsController(AppDbContext db, BusinessSettings
|
||||
[AllowAnonymous]
|
||||
public IActionResult Branding() => Ok(reader.Brand());
|
||||
|
||||
[HttpGet("manifest.webmanifest")]
|
||||
[AllowAnonymous]
|
||||
public IActionResult Manifest()
|
||||
{
|
||||
var brand = reader.Brand();
|
||||
Response.Headers.CacheControl = "no-store";
|
||||
return new JsonResult(new {
|
||||
name = brand.ProductName, short_name = brand.ShortName, description = brand.Description,
|
||||
theme_color = "#152550", background_color = "#152550", display = "standalone", start_url = "/", scope = "/",
|
||||
icons = new[] { new { src = "/favicon.svg", sizes = "any", type = "image/svg+xml", purpose = "any maskable" } }
|
||||
}) { ContentType = "application/manifest+json" };
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[Authorize(Roles = SystemRoles.SuperAdmin)]
|
||||
public IActionResult Get() => Ok(reader.Read());
|
||||
|
||||
@@ -5,6 +5,8 @@ using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Data.Sqlite;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace Jiaowu.Api.Tests;
|
||||
|
||||
@@ -37,5 +39,11 @@ public sealed class BusinessSettingsTests
|
||||
Assert.Equal("NEW", nextRequest.Document().DocumentNumberPrefix);
|
||||
Assert.Equal(30, nextRequest.Read().GradeAppealWindowDays);
|
||||
Assert.Single(await db.BusinessSettings.ToListAsync());
|
||||
var publicController = new BusinessSettingsController(db, nextRequest) { ControllerContext = new ControllerContext { HttpContext = new DefaultHttpContext() } };
|
||||
var manifest = Assert.IsType<JsonResult>(publicController.Manifest());
|
||||
var manifestJson = JsonSerializer.SerializeToElement(manifest.Value);
|
||||
Assert.Equal("新产品", manifestJson.GetProperty("name").GetString());
|
||||
Assert.Equal("新简称", manifestJson.GetProperty("short_name").GetString());
|
||||
Assert.Equal("no-store", publicController.Response.Headers.CacheControl.ToString());
|
||||
}
|
||||
}
|
||||
@@ -17,4 +17,5 @@ export async function refreshBranding() {
|
||||
if (!response.ok) throw new Error('Unable to load branding')
|
||||
Object.assign(branding, await response.json() as AppBranding)
|
||||
document.title = branding.productName
|
||||
document.querySelector('meta[name="description"]')?.setAttribute('content', branding.description)
|
||||
}
|
||||
Loaded 3 of 4 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user