feat: invites
CI / CD / Unit tests (push) Successful in 38s
CI / CD / Build & push Helm chart (push) Successful in 11s
CI / CD / Build & push frontend-static (push) Successful in 31s
CI / CD / Build & push frontend (nginx) (push) Successful in 29s
CI / CD / Build & push backend (push) Successful in 1m49s

This commit is contained in:
2026-10-11 14:26:30 +04:00
parent f67a544d7a
commit 3d58fff4a7
7 changed files with 359 additions and 4 deletions
@@ -0,0 +1,20 @@
using MemeVault.Api.Services;
using Microsoft.AspNetCore.Mvc;
namespace MemeVault.Api.Controllers;
[ApiController]
[Route("api/bot")]
public sealed class BotController(BotInfoService botInfo) : ControllerBase
{
/// <summary>
/// Возвращает публичный username бота.
/// Не требует авторизации — username бота публичен.
/// </summary>
[HttpGet("info")]
public async Task<IActionResult> GetInfo(CancellationToken ct)
{
var username = await botInfo.GetBotUsernameAsync();
return Ok(new { username });
}
}
+2
View File
@@ -1,5 +1,6 @@
using MemeVault.Api.Middleware;
using MemeVault.Api.Auth;
using MemeVault.Api.Services;
using System.Text;
using MemeVault.Api.Options;
using MemeVault.Infrastructure;
@@ -29,6 +30,7 @@ builder.Services.Configure<JwtOptions>(
builder.Services.AddSingleton<TelegramInitDataValidator>();
builder.Services.AddSingleton<InlineAuthValidator>();
builder.Services.AddSingleton<JwtTokenService>();
builder.Services.AddSingleton<BotInfoService>();
builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<CurrentUser>();
@@ -0,0 +1,27 @@
using Telegram.Bot;
namespace MemeVault.Api.Services;
/// <summary>
/// Кэширует username бота на весь lifetime процесса.
/// GetMeAsync вызывается ровно один раз при первом обращении.
/// </summary>
public sealed class BotInfoService
{
private readonly Lazy<Task<string>> _username;
public BotInfoService(ITelegramBotClient botClient)
{
_username = new Lazy<Task<string>>(
() => FetchAsync(botClient),
LazyThreadSafetyMode.ExecutionAndPublication);
}
private static async Task<string> FetchAsync(ITelegramBotClient botClient)
{
var me = await botClient.GetMe();
return me.Username ?? string.Empty;
}
public Task<string> GetBotUsernameAsync() => _username.Value;
}
@@ -15,5 +15,6 @@ public sealed record CollectionDto(
bool IsNsfw,
string? ShareToken,
int ItemCount,
DateTimeOffset CreatedAt
DateTimeOffset CreatedAt,
CollectionRole MyRole
);
@@ -1,4 +1,5 @@
using MediatR;
using MemeVault.Domain.Enums;
using MemeVault.Domain.Repositories;
namespace MemeVault.Application.Queries.GetUserCollections;
@@ -35,7 +36,8 @@ public sealed class GetUserCollectionsQueryHandler(
c.IsNsfw,
c.ShareToken,
countByCollection.GetValueOrDefault(c.Id, 0),
c.CreatedAt
c.CreatedAt,
c.GetRole(request.OwnerTelegramId) ?? CollectionRole.Viewer
)).ToList();
}
}