Files
gaseous-server/gaseous-server/Controllers/V1.1/RatingsController.cs
Michael Green 60da78fa7d .Net8.0 update, add ARM support, various bug fixes (#277)
* Update to .net8.0 LTS (closes #271)
* Add ARM docker container support (closes #245)
* Library updates (closes #260 and #261)
* Database updates to support changes in the latest IGDB client version
* Version number will no longer be displayed when built from source
2024-02-02 11:35:20 +11:00

66 lines
2.4 KiB
C#

using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using gaseous_server.Classes;
using gaseous_server.Classes.Metadata;
using IGDB.Models;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.CodeAnalysis.Scripting;
using static gaseous_server.Classes.Metadata.AgeRatings;
using Asp.Versioning;
namespace gaseous_server.Controllers.v1_1
{
[Route("api/v{version:apiVersion}/[controller]")]
[ApiVersion("1.1")]
[ApiController]
public class RatingsController: ControllerBase
{
[MapToApiVersion("1.1")]
[HttpGet]
[Authorize]
[Route("Images/{RatingBoard}/{RatingId}/image.svg")]
[ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public ActionResult RatingsImageById(string RatingBoard, int RatingId)
{
IGDB.Models.AgeRatingTitle RatingTitle = (AgeRatingTitle)RatingId;
string resourceName = "gaseous_server.Assets.Ratings." + RatingBoard + "." + RatingTitle.ToString() + ".svg";
var assembly = Assembly.GetExecutingAssembly();
string[] resources = assembly.GetManifestResourceNames();
if (resources.Contains(resourceName))
{
using (Stream stream = assembly.GetManifestResourceStream(resourceName))
using (StreamReader reader = new StreamReader(stream))
{
byte[] filedata = new byte[stream.Length];
stream.Read(filedata, 0, filedata.Length);
string filename = RatingBoard + "-" + RatingTitle.ToString() + ".svg";
string contentType = "image/svg+xml";
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = true,
};
Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.Add("Cache-Control", "public, max-age=604800");
return File(filedata, contentType);
}
}
return NotFound();
}
}
}