Files
RRAC/RecRoomArchive/Controllers/API/Images/V2/ImagesController.cs
2026-02-27 19:30:49 -08:00

35 lines
1.2 KiB
C#

using Microsoft.AspNetCore.Mvc;
using RecRoomArchive.Controllers.API.Notification;
using RecRoomArchive.Models.API.Notification;
using RecRoomArchive.Models.API.Players;
using RecRoomArchive.Services;
using System.Text.Json;
namespace RecRoomArchive.Controllers.API.Images.V2
{
[Route("api/[controller]/v2")]
[ApiController]
public class ImagesController(FileService fileService, ImageService imageService) : ControllerBase
{
[HttpPost(template: "profile")]
public async Task<ActionResult> SetProfileImage(IFormFile image)
{
using var stream = image.OpenReadStream();
var imageName = await imageService.SaveImageAsync(stream);
var profileData = fileService.GetData("profile.json");
if (profileData == null)
return BadRequest("Profile is not populated");
var profile = JsonSerializer.Deserialize<BaseProfile>(profileData)!;
profile.ProfileImageName = imageName;
fileService.SetData("profile.json", JsonSerializer.Serialize(profile));
await NotificationController.Notify(profile.Id, PushNotificationId.SubscriptionUpdateProfile, profile);
return Ok();
}
}
}