summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web.LegacyRedirects/Controllers/ModsApiController.cs
blob: 44ed0b6b57a9f97b382ab3636b2ff8990e94a15e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Pathoschild.Http.Client;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;

namespace SMAPI.Web.LegacyRedirects.Controllers
{
    /// <summary>Provides an API to perform mod update checks.</summary>
    [ApiController]
    [Produces("application/json")]
    [Route("api/v{version}/mods")]
    public class ModsApiController : Controller
    {
        /*********
        ** Public methods
        *********/
        /// <summary>Fetch version metadata for the given mods.</summary>
        /// <param name="model">The mod search criteria.</param>
        [HttpPost]
        public async Task<IEnumerable<ModEntryModel>> PostAsync([FromBody] ModSearchModel model)
        {
            using IClient client = new FluentClient("https://smapi.io/api");

            Startup.ConfigureJsonNet(client.Formatters.JsonFormatter.SerializerSettings);

            return await client
                .PostAsync(this.Request.Path)
                .WithBody(model)
                .AsArray<ModEntryModel>();
        }
    }
}