summaryrefslogtreecommitdiff
path: root/src/SMAPI.Web/Controllers/ModsController.cs
blob: 99d19f76942171be8d86fad834bff32203045198 (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.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.Clients.Wiki;
using StardewModdingAPI.Web.ViewModels;

namespace StardewModdingAPI.Web.Controllers
{
    /// <summary>Provides user-friendly info about SMAPI mods.</summary>
    internal class ModsController : Controller
    {
        /*********
        ** Public methods
        *********/
        /// <summary>Display information for all mods.</summary>
        [HttpGet]
        [Route("mods")]
        public async Task<ViewResult> Index()
        {
            WikiModEntry[] mods = await new ModToolkit().GetWikiCompatibilityListAsync();
            ModListModel viewModel = new ModListModel(
                stableVersion: "1.3.28",
                betaVersion: "1.3.31-beta",
                mods: mods
                    .Select(mod => new ModModel(mod))
                    .OrderBy(p => Regex.Replace(p.Name.ToLower(), "[^a-z0-9]", "")) // ignore case, spaces, and special characters when sorting
            );
            return this.View("Index", viewModel);
        }
    }
}