Account flags
This commit is contained in:
@ -1,24 +1,56 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NostrStreamer.ApiModel;
|
||||
using NostrStreamer.Services;
|
||||
using NostrStreamer.Services.Dvr;
|
||||
using NostrStreamer.Services.StreamManager;
|
||||
|
||||
namespace NostrStreamer.Controllers;
|
||||
|
||||
[Authorize(AuthenticationSchemes = NostrAuth.Scheme, Roles = NostrAuth.RoleAdmin)]
|
||||
[Route("/api/admin")]
|
||||
public class AdminController : Controller
|
||||
{
|
||||
private readonly ILogger<AdminController> _logger;
|
||||
private readonly StreamManagerFactory _streamManagerFactory;
|
||||
|
||||
public AdminController(ILogger<AdminController> logger, StreamManagerFactory streamManagerFactory)
|
||||
private readonly IDvrStore _dvrStore;
|
||||
private readonly UserService _userService;
|
||||
|
||||
public AdminController(ILogger<AdminController> logger, StreamManagerFactory streamManagerFactory, IDvrStore dvrStore,
|
||||
UserService userService)
|
||||
{
|
||||
_logger = logger;
|
||||
_streamManagerFactory = streamManagerFactory;
|
||||
_dvrStore = dvrStore;
|
||||
_userService = userService;
|
||||
}
|
||||
|
||||
|
||||
[HttpPatch("stream/{id:guid}")]
|
||||
public async Task PublishEvent([FromRoute] Guid id)
|
||||
{
|
||||
var stream = await _streamManagerFactory.ForStream(id);
|
||||
await stream.UpdateEvent();
|
||||
}
|
||||
|
||||
[HttpDelete("stream/{id:guid}")]
|
||||
public async Task DeleteEvent([FromRoute] Guid id)
|
||||
{
|
||||
var mgr = await _streamManagerFactory.ForStream(id);
|
||||
var stream = mgr.GetStream();
|
||||
await _dvrStore.DeleteRecordings(stream);
|
||||
}
|
||||
|
||||
[HttpPatch("account/{pubkey}")]
|
||||
public async Task UpdateAccount([FromRoute] string pubkey, [FromBody] PatchAccount req)
|
||||
{
|
||||
if (req.Blocked.HasValue)
|
||||
{
|
||||
await _userService.SetBlocked(pubkey, req.Blocked.Value);
|
||||
}
|
||||
|
||||
if (req.Admin.HasValue)
|
||||
{
|
||||
await _userService.SetAdmin(pubkey, req.Admin.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -136,7 +136,7 @@ public class NostrController : Controller
|
||||
return NotFound();
|
||||
}
|
||||
|
||||
if (patch.AcceptTos)
|
||||
if (patch.AcceptTos.HasValue && patch.AcceptTos.Value)
|
||||
{
|
||||
await _userService.AcceptTos(user.PubKey);
|
||||
}
|
||||
@ -267,7 +267,7 @@ public class NostrController : Controller
|
||||
var existing = await _db.PushSubscriptions.FirstOrDefaultAsync(a => a.Key == sub.Key);
|
||||
if (existing != default)
|
||||
{
|
||||
return Json(new { id = existing.Id });
|
||||
return Json(new {id = existing.Id});
|
||||
}
|
||||
|
||||
var newId = Guid.NewGuid();
|
||||
@ -298,7 +298,7 @@ public class NostrController : Controller
|
||||
|
||||
var sub = await _db.PushSubscriptionTargets
|
||||
.Join(_db.PushSubscriptions, a => a.SubscriberPubkey, b => b.Pubkey,
|
||||
(a, b) => new { a.SubscriberPubkey, a.TargetPubkey, b.Auth })
|
||||
(a, b) => new {a.SubscriberPubkey, a.TargetPubkey, b.Auth})
|
||||
.Where(a => a.SubscriberPubkey == userPubkey && a.Auth == auth)
|
||||
.Select(a => a.TargetPubkey)
|
||||
.ToListAsync();
|
||||
@ -415,4 +415,4 @@ public class NostrController : Controller
|
||||
var claim = HttpContext.User.Claims.FirstOrDefault(a => a.Type == ClaimTypes.Name);
|
||||
return claim!.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user