mirror of
https://github.com/DorkSquadRR/DorkNet.git
synced 2026-10-26 07:28:45 -07:00
Import december-2020-12-18 from private repo (scrubbed 2026-05-27)
Targets Rec Room 2020.12.18 client.
Re-import after adding:
- DorkNet.ClientMod/dorknet-clientmod.json.template — config schema
the launcher's manifest-driven patcher renders into UserData/.
- tools/build-patcher-zip.ps1 — produces the dorknet-clientpatch-{key}.zip
Release asset the launcher fetches.
- .github/workflows/release.yml — auto-publishes both Release assets
on v1-december-* tag push.
Scrubbed via maintainer-side scrub-for-public.ps1: same drop rules as
the prior import, plus build-patcher-zip.ps1 added to the tools/
allow-list so it survives the scrub.
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using DorkNet.Models.Notification;
|
||||
using DorkNet.Server.Auth;
|
||||
using DorkNet.Server.Data;
|
||||
using DorkNet.Server.Data.Entities;
|
||||
using DorkNet.Server.Services;
|
||||
|
||||
namespace DorkNet.Server.Controllers.API.PlayerSubscriptions;
|
||||
|
||||
/// <summary>
|
||||
/// api.rec.net/api/playersubscriptions/v1/* — asymmetric follow
|
||||
/// graph. The <c>my</c> endpoint returns who the caller follows;
|
||||
/// subscribe/unsubscribe mutate the row directly. Reputation
|
||||
/// aggregates pull SubscriberCount / SubscribedCount counts from
|
||||
/// here.
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/[controller]/v1")]
|
||||
[Authorize]
|
||||
public class PlayerSubscriptionsController(
|
||||
DorkNetDbContext db,
|
||||
NotificationService notifications) : ControllerBase
|
||||
{
|
||||
private long Me => this.RequireCurrentPlayerId();
|
||||
|
||||
[HttpGet("my")]
|
||||
public async Task<ActionResult> My()
|
||||
{
|
||||
var subs = await db.Subscriptions
|
||||
.Where(s => s.SubscriberPlayerId == Me)
|
||||
.Select(s => new { s.TargetPlayerId, s.CreatedAt })
|
||||
.ToListAsync();
|
||||
return Ok(subs);
|
||||
}
|
||||
|
||||
[HttpGet("{playerId:long}/subscribers")]
|
||||
public async Task<ActionResult> Subscribers(long playerId)
|
||||
{
|
||||
var subs = await db.Subscriptions
|
||||
.Where(s => s.TargetPlayerId == playerId)
|
||||
.Select(s => new { s.SubscriberPlayerId, s.CreatedAt })
|
||||
.ToListAsync();
|
||||
return Ok(subs);
|
||||
}
|
||||
|
||||
[HttpPost("subscribe/{targetId:long}")]
|
||||
public async Task<ActionResult> Subscribe(long targetId)
|
||||
{
|
||||
if (targetId == Me) return BadRequest("cannot_subscribe_to_self");
|
||||
|
||||
var existing = await db.Subscriptions.FirstOrDefaultAsync(s =>
|
||||
s.SubscriberPlayerId == Me && s.TargetPlayerId == targetId);
|
||||
if (existing is not null) return Ok(new { already_subscribed = true });
|
||||
|
||||
db.Subscriptions.Add(new SubscriptionEntity
|
||||
{
|
||||
SubscriberPlayerId = Me,
|
||||
TargetPlayerId = targetId,
|
||||
});
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Tell the target their subscriber count changed so the watch
|
||||
// refreshes their profile page if open.
|
||||
await notifications.NotifyAsync(targetId,
|
||||
PushNotificationId.SubscriptionUpdateProfile,
|
||||
new { Reason = "NewSubscriber", From = Me });
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("subscribe/{targetId:long}")]
|
||||
[HttpPost("unsubscribe/{targetId:long}")]
|
||||
public async Task<ActionResult> Unsubscribe(long targetId)
|
||||
{
|
||||
var row = await db.Subscriptions.FirstOrDefaultAsync(s =>
|
||||
s.SubscriberPlayerId == Me && s.TargetPlayerId == targetId);
|
||||
if (row is null) return NotFound();
|
||||
db.Subscriptions.Remove(row);
|
||||
await db.SaveChangesAsync();
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user