Files
soroush.asadi 81912cac66
Build backend images / build content-svc (push) Failing after 14s
Build backend images / build file-svc (push) Failing after 1m28s
Build backend images / build gateway (push) Failing after 1m43s
Build backend images / build identity-svc (push) Failing after 3m0s
Build backend images / build notification-svc (push) Failing after 51s
Build backend images / build render-svc (push) Failing after 1m3s
Build backend images / build studio-svc (push) Failing after 1m1s
feat(render): full-screen render page, one-active-render limit, app-wide progress
Concurrent-render ceiling (a user runs 1 render at a time unless granted more):
- Identity: TokenService emits max_renders claim from User.ParallelRenderingCeiling
- Identity: admin POST /v1/users/{id}/render-slots (AdminService.SetRenderSlotsAsync,
  clamped 1..50) — gamification or admin raises a user's ceiling
- render-svc: middleware reads max_renders (default 1); CreateJob rejects with 409
  active_render_limit when active jobs >= ceiling
- render-svc: db.CountActiveJobs + ListActiveJobs; GET /v1/renders/active returns
  in-flight renders + can_start_new

Full-screen render page (replaces the modal):
- /studio/render/[projectId]: config (resolution/fps) → live preview + progress →
  download; resumes this project's in-flight render on mount; blocks when another
  render is active; reads ?preset=
- StudioTopBar export menu now navigates to the page; RenderModal deleted (dead)

App-wide minimal progress:
- GlobalRenderProgress pill mounted in the locale layout for authed users; polls
  /api/render/active every 4s, shows thumbnail + step + % on every page, click →
  the render page; hidden on the render page and when idle

Admin: UserActions gains a "concurrent render slots" control.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-05 16:48:05 +03:30

104 lines
4.8 KiB
C#

using FlatRender.IdentitySvc.Application.Services;
using FlatRender.IdentitySvc.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace FlatRender.IdentitySvc.Controllers;
[ApiController]
[Authorize(Roles = "Admin")]
public class AdminController(AdminService svc) : ControllerBase
{
private Guid TenantId =>
Guid.TryParse(User.FindFirst("tenant_id")?.Value, out var t)
? t : Guid.Parse("00000000-0000-0000-0000-000000000001");
// ── CRM analytics ────────────────────────────────────────────────────────
[HttpGet("v1/admin/crm/analytics")]
public async Task<IActionResult> Crm([FromQuery] DateTime? start, [FromQuery] DateTime? end)
{
var s = start ?? DateTime.UtcNow.AddDays(-30);
var e = end ?? DateTime.UtcNow;
return Ok(await svc.GetCrmAnalyticsAsync(TenantId, s, e));
}
// ── Plan statistics ──────────────────────────────────────────────────────
[HttpGet("v1/admin/plan-statistics")]
public async Task<IActionResult> PlanStats() => Ok(await svc.GetPlanStatisticsAsync(TenantId));
// ── OAuth provider config ──────────────────────────────────────────────────
[HttpGet("v1/admin/oauth/{provider}")]
public async Task<IActionResult> GetOAuth(string provider, [FromServices] OAuthService oauth)
{
var c = await oauth.GetConfigAsync(provider);
return Ok(new OAuthConfigResponse(provider, c?.ClientId, c?.RedirectUri, c?.Enabled ?? false,
!string.IsNullOrEmpty(c?.ClientSecret)));
}
[HttpPut("v1/admin/oauth/{provider}")]
public async Task<IActionResult> PutOAuth(string provider, [FromBody] UpsertOAuthConfigRequest req, [FromServices] OAuthService oauth)
{
var c = await oauth.UpsertConfigAsync(provider, req.ClientId, req.ClientSecret, req.RedirectUri, req.Enabled);
return Ok(new OAuthConfigResponse(provider, c.ClientId, c.RedirectUri, c.Enabled, !string.IsNullOrEmpty(c.ClientSecret)));
}
// ── CRM notes / tags ───────────────────────────────────────────────────────
[HttpGet("v1/users/{userId:guid}/crm")]
public async Task<IActionResult> GetCrm(Guid userId) => Ok(await svc.GetUserCrmAsync(userId));
[HttpPut("v1/users/{userId:guid}/crm")]
public async Task<IActionResult> PutCrm(Guid userId, [FromBody] UpsertUserCrmRequest req)
=> Ok(await svc.UpsertUserCrmAsync(userId, req));
// ── Power-actions ──────────────────────────────────────────────────────────
[HttpPost("v1/users/{userId:guid}/balance")]
public async Task<IActionResult> Balance(Guid userId, [FromBody] SetBalanceRequest req)
{
await svc.SetBalanceAsync(userId, req.AmountMinor, req.Add);
return Ok(new { ok = true });
}
[HttpPost("v1/users/{userId:guid}/password")]
public async Task<IActionResult> Password(Guid userId, [FromBody] ResetPasswordRequest req)
{
await svc.ResetPasswordAsync(userId, req.NewPassword);
return Ok(new { ok = true });
}
[HttpPost("v1/users/{userId:guid}/charge")]
public async Task<IActionResult> Charge(Guid userId, [FromBody] AddChargeRequest req)
{
await svc.AddChargeAsync(userId, req.Seconds, req.RenderCount);
return Ok(new { ok = true });
}
[HttpPost("v1/users/{userId:guid}/moderator")]
public async Task<IActionResult> Moderator(Guid userId, [FromBody] SetFlagRequest req)
{
await svc.SetModeratorAsync(userId, req.Enabled);
return Ok(new { ok = true });
}
// Grant a user extra concurrent render slots (takes effect on next token refresh).
[HttpPost("v1/users/{userId:guid}/render-slots")]
public async Task<IActionResult> RenderSlots(Guid userId, [FromBody] SetRenderSlotsRequest req)
{
await svc.SetRenderSlotsAsync(userId, req.Ceiling);
return Ok(new { ok = true });
}
[HttpPost("v1/users/{userId:guid}/grant-plan")]
public async Task<IActionResult> GrantPlan(Guid userId, [FromBody] GrantPlanDaysRequest req)
{
try
{
await svc.GrantPlanDaysAsync(userId, req.PlanId, req.Days);
return Ok(new { ok = true });
}
catch (KeyNotFoundException ex)
{
return BadRequest(new { error = new { message = ex.Message } });
}
}
}