[backend/razor] Add UI for setting instance banner
This commit is contained in:
parent
66c003daeb
commit
8c50211efb
4 changed files with 20 additions and 8 deletions
|
@ -277,9 +277,10 @@ public class InstanceService(
|
||||||
return rule;
|
return rule;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<string?> GetInstanceImageAsync()
|
public async Task<(string?, string?)> GetInstanceImageAsync()
|
||||||
{
|
{
|
||||||
var iconId = await meta.GetAsync(MetaEntity.IconFileId);
|
var (iconId, bannerId) = await meta.GetManyAsync(MetaEntity.IconFileId, MetaEntity.BannerFileId);
|
||||||
return await db.DriveFiles.Where(p => p.Id == iconId).Select(p => p.RawAccessUrl).FirstOrDefaultAsync();
|
return (await db.DriveFiles.Where(p => p.Id == iconId).Select(p => p.RawAccessUrl).FirstOrDefaultAsync(),
|
||||||
|
await db.DriveFiles.Where(p => p.Id == bannerId).Select(p => p.RawAccessUrl).FirstOrDefaultAsync());
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -81,6 +81,7 @@ public static class MetaEntity
|
||||||
public static readonly NullableStringMeta AdminContactEmail = new("admin_contact_email");
|
public static readonly NullableStringMeta AdminContactEmail = new("admin_contact_email");
|
||||||
public static readonly NullableStringMeta ThemeColor = new("theme_color");
|
public static readonly NullableStringMeta ThemeColor = new("theme_color");
|
||||||
public static readonly NullableStringMeta IconFileId = new("icon_file_id");
|
public static readonly NullableStringMeta IconFileId = new("icon_file_id");
|
||||||
|
public static readonly NullableStringMeta BannerFileId = new("banner_file_id");
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Meta<T>(
|
public class Meta<T>(
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
<EditForm FormName="update-metadata" Model="Model" OnSubmit="@OnSubmit" enctype="multipart/form-data">
|
<EditForm FormName="update-metadata" Model="Model" OnSubmit="@OnSubmit" enctype="multipart/form-data">
|
||||||
<label for="icon">Icon</label>
|
<label for="icon">Icon</label>
|
||||||
<InputFile name="Model.IconFile" id="icon" accept="image/*"/>
|
<InputFile name="Model.IconFile" id="icon" accept="image/*"/>
|
||||||
|
<label for="banner">Banner</label>
|
||||||
|
<InputFile name="Model.BannerFile" id="banner" accept="image/*"/>
|
||||||
<label for="name">Instance name</label>
|
<label for="name">Instance name</label>
|
||||||
<InputText @bind-Value="@Model.Name" id="name" placeholder="Shrimp & friends"/>
|
<InputText @bind-Value="@Model.Name" id="name" placeholder="Shrimp & friends"/>
|
||||||
<label for="desc">Instance description</label>
|
<label for="desc">Instance description</label>
|
||||||
|
@ -38,6 +40,7 @@
|
||||||
public string? AdminContact { get; set; }
|
public string? AdminContact { get; set; }
|
||||||
public string? ThemeColor { get; set; }
|
public string? ThemeColor { get; set; }
|
||||||
public IFormFile? IconFile { get; set; }
|
public IFormFile? IconFile { get; set; }
|
||||||
|
public IFormFile? BannerFile { get; set; }
|
||||||
|
|
||||||
public void Canonicalize()
|
public void Canonicalize()
|
||||||
{
|
{
|
||||||
|
@ -58,6 +61,8 @@
|
||||||
ThemeColor = null;
|
ThemeColor = null;
|
||||||
if (!IconFile?.ContentType.StartsWith("image/") ?? false)
|
if (!IconFile?.ContentType.StartsWith("image/") ?? false)
|
||||||
IconFile = null;
|
IconFile = null;
|
||||||
|
if (!BannerFile?.ContentType.StartsWith("image/") ?? false)
|
||||||
|
BannerFile = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,14 +86,19 @@
|
||||||
await Meta.SetAsync(MetaEntity.AdminContactEmail, Model.AdminContact);
|
await Meta.SetAsync(MetaEntity.AdminContactEmail, Model.AdminContact);
|
||||||
await Meta.SetAsync(MetaEntity.ThemeColor, Model.ThemeColor);
|
await Meta.SetAsync(MetaEntity.ThemeColor, Model.ThemeColor);
|
||||||
|
|
||||||
|
var ia = await SystemUser.GetInstanceActorAsync();
|
||||||
if (Model.IconFile != null)
|
if (Model.IconFile != null)
|
||||||
{
|
{
|
||||||
var ia = await SystemUser.GetInstanceActorAsync();
|
|
||||||
var req = new DriveFileCreationRequest { Filename = Model.IconFile.Name, IsSensitive = false, MimeType = Model.IconFile.ContentType };
|
var req = new DriveFileCreationRequest { Filename = Model.IconFile.Name, IsSensitive = false, MimeType = Model.IconFile.ContentType };
|
||||||
|
|
||||||
var file = await Drive.StoreFileAsync(Model.IconFile.OpenReadStream(), ia, req);
|
var file = await Drive.StoreFileAsync(Model.IconFile.OpenReadStream(), ia, req);
|
||||||
await Meta.SetAsync(MetaEntity.IconFileId, file.Id);
|
await Meta.SetAsync(MetaEntity.IconFileId, file.Id);
|
||||||
}
|
}
|
||||||
|
if (Model.BannerFile != null)
|
||||||
|
{
|
||||||
|
var req = new DriveFileCreationRequest { Filename = Model.BannerFile.Name, IsSensitive = false, MimeType = Model.BannerFile.ContentType };
|
||||||
|
var file = await Drive.StoreFileAsync(Model.BannerFile.OpenReadStream(), ia, req);
|
||||||
|
await Meta.SetAsync(MetaEntity.BannerFileId, file.Id);
|
||||||
|
}
|
||||||
|
|
||||||
ReloadPage();
|
ReloadPage();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@
|
||||||
_user = Context.GetUser();
|
_user = Context.GetUser();
|
||||||
|
|
||||||
_instanceName = await Meta.GetAsync(MetaEntity.InstanceName);
|
_instanceName = await Meta.GetAsync(MetaEntity.InstanceName);
|
||||||
_instanceIcon = await InstanceSvc.GetInstanceImageAsync();
|
(_instanceIcon, _) = await InstanceSvc.GetInstanceImageAsync();
|
||||||
|
|
||||||
if (Context.GetEndpoint()?.Metadata.GetMetadata<RequireAuthorizationAttribute>() == null)
|
if (Context.GetEndpoint()?.Metadata.GetMetadata<RequireAuthorizationAttribute>() == null)
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Add table
Reference in a new issue