[backend/api] Use UserRenderer in AuthController instead of instantiating the response object directly (ISH-209)
This commit is contained in:
parent
d5e0587048
commit
62469e2ea4
3 changed files with 7 additions and 24 deletions
|
@ -1,5 +1,6 @@
|
||||||
using System.Diagnostics.CodeAnalysis;
|
using System.Diagnostics.CodeAnalysis;
|
||||||
using System.Net.Mime;
|
using System.Net.Mime;
|
||||||
|
using Iceshrimp.Backend.Controllers.Renderers;
|
||||||
using Iceshrimp.Backend.Controllers.Schemas;
|
using Iceshrimp.Backend.Controllers.Schemas;
|
||||||
using Iceshrimp.Backend.Core.Database;
|
using Iceshrimp.Backend.Core.Database;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
@ -17,12 +18,12 @@ namespace Iceshrimp.Backend.Controllers;
|
||||||
[EnableRateLimiting("sliding")]
|
[EnableRateLimiting("sliding")]
|
||||||
[Produces(MediaTypeNames.Application.Json)]
|
[Produces(MediaTypeNames.Application.Json)]
|
||||||
[Route("/api/iceshrimp/v1/auth")]
|
[Route("/api/iceshrimp/v1/auth")]
|
||||||
public class AuthController(DatabaseContext db, UserService userSvc) : ControllerBase
|
public class AuthController(DatabaseContext db, UserService userSvc, UserRenderer userRenderer) : ControllerBase
|
||||||
{
|
{
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[Authenticate]
|
[Authenticate]
|
||||||
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthResponse))]
|
[ProducesResponseType(StatusCodes.Status200OK, Type = typeof(AuthResponse))]
|
||||||
public IActionResult GetAuthStatus()
|
public async Task<IActionResult> GetAuthStatus()
|
||||||
{
|
{
|
||||||
var session = HttpContext.GetSession();
|
var session = HttpContext.GetSession();
|
||||||
|
|
||||||
|
@ -33,16 +34,7 @@ public class AuthController(DatabaseContext db, UserService userSvc) : Controlle
|
||||||
{
|
{
|
||||||
Status = session.Active ? AuthStatusEnum.Authenticated : AuthStatusEnum.TwoFactor,
|
Status = session.Active ? AuthStatusEnum.Authenticated : AuthStatusEnum.TwoFactor,
|
||||||
Token = session.Token,
|
Token = session.Token,
|
||||||
User = new UserResponse
|
User = await userRenderer.RenderOne(session.User)
|
||||||
{
|
|
||||||
Username = session.User.Username,
|
|
||||||
Id = session.User.Id,
|
|
||||||
AvatarUrl = session.User.AvatarUrl,
|
|
||||||
BannerUrl = session.User.BannerUrl,
|
|
||||||
DisplayName = session.User.DisplayName,
|
|
||||||
InstanceName = null,
|
|
||||||
InstanceIconUrl = null
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,16 +78,7 @@ public class AuthController(DatabaseContext db, UserService userSvc) : Controlle
|
||||||
{
|
{
|
||||||
Status = session.Active ? AuthStatusEnum.Authenticated : AuthStatusEnum.TwoFactor,
|
Status = session.Active ? AuthStatusEnum.Authenticated : AuthStatusEnum.TwoFactor,
|
||||||
Token = session.Token,
|
Token = session.Token,
|
||||||
User = new UserResponse
|
User = await userRenderer.RenderOne(user)
|
||||||
{
|
|
||||||
Username = session.User.Username,
|
|
||||||
Id = session.User.Id,
|
|
||||||
AvatarUrl = session.User.AvatarUrl,
|
|
||||||
BannerUrl = session.User.BannerUrl,
|
|
||||||
DisplayName = session.User.DisplayName,
|
|
||||||
InstanceName = null,
|
|
||||||
InstanceIconUrl = null
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, MfmConverter
|
||||||
StatusesCount = user.NotesCount,
|
StatusesCount = user.NotesCount,
|
||||||
Note = await mfmConverter.ToHtmlAsync(profile?.Description ?? "", mentions, user.Host),
|
Note = await mfmConverter.ToHtmlAsync(profile?.Description ?? "", mentions, user.Host),
|
||||||
Url = profile?.Url ?? user.Uri ?? user.GetPublicUrl(config.Value),
|
Url = profile?.Url ?? user.Uri ?? user.GetPublicUrl(config.Value),
|
||||||
AvatarStaticUrl = user.AvatarUrl ?? user.GetIdenticonUrl(config.Value), //TODO
|
AvatarStaticUrl = user.AvatarUrl ?? user.GetIdenticonUrlPng(config.Value), //TODO
|
||||||
HeaderUrl = user.BannerUrl ?? _transparent,
|
HeaderUrl = user.BannerUrl ?? _transparent,
|
||||||
HeaderStaticUrl = user.BannerUrl ?? _transparent, //TODO
|
HeaderStaticUrl = user.BannerUrl ?? _transparent, //TODO
|
||||||
MovedToAccount = null, //TODO
|
MovedToAccount = null, //TODO
|
||||||
|
|
|
@ -25,7 +25,7 @@ public class UserRenderer(IOptions<Config.InstanceSection> config, DatabaseConte
|
||||||
Id = user.Id,
|
Id = user.Id,
|
||||||
Username = user.Username,
|
Username = user.Username,
|
||||||
DisplayName = user.DisplayName,
|
DisplayName = user.DisplayName,
|
||||||
AvatarUrl = user.AvatarUrl ?? $"https://{config.Value.WebDomain}/identicon/{user.Id}",
|
AvatarUrl = user.AvatarUrl ?? user.GetIdenticonUrl(config.Value),
|
||||||
BannerUrl = user.BannerUrl,
|
BannerUrl = user.BannerUrl,
|
||||||
InstanceName = instanceName,
|
InstanceName = instanceName,
|
||||||
InstanceIconUrl = instanceIcon
|
InstanceIconUrl = instanceIcon
|
||||||
|
|
Loading…
Add table
Reference in a new issue