Pathoschild / SMAPI

The modding API for Stardew Valley.
https://smapi.io/
GNU Lesser General Public License v3.0
1.86k stars 263 forks source link

Add mod update-check service #336

Closed Pathoschild closed 7 years ago

Pathoschild commented 7 years ago

Add a feature wherein SMAPI automatically performs update checks against the Nexus Mods API if the mod's manifest.json contains its Nexus Mods ID.

Pathoschild commented 7 years ago

Background

Nexus Mod Manager uses a hidden API to fetch mod info. I figured out that SMAPI can use it by querying the normal mod URL with a user agent of Nexus Client v{recent version}:

Per discussion with Tom Mason (@MrMason) from Nexus, they're okay with SMAPI using the old API this way. They're working on a new REST API for their upcoming Vortex mod manager, and they'll send me an API key next week to help them test it.

Proposed implementation

  1. Create a public web API that accepts a request like this:

    POST https://updates.smapi.io/v2.0/check
    
    [
      { "NexusID": 518, "Version": "1.9" },
      // list any number of mods
    ]

    ...and returns a response containing any new versions available (probably omit up-to-date mods?):

    [
      {
         "NexusID": 518,
         "Valid": true, // false if the mod doesn't exist
         "Name": "Lookup Anything",
         "Version": "1.11.1",
         "Url": "http://www.nexusmods.com/stardewvalley/mods/518"
      }
    ]
  2. This API should fetch the mod info from the old Nexus Mods API, and cache the important bits in Redis or similar. (Longer-term, it will use an API key to fetch the data from the Vortex API.)

  3. During startup, SMAPI should check for any mods with a NexusID field set in their manifest.json, send a batch update check to this API, and display alerts for any new versions available.

  4. (Optional bonus) Use the data collected for the SMAPI 2.0 compatibility page to create a unique ID → Nexus ID map for existing mods. That way existing mods get update checks right away, without needing to wait until the authors start using it explicitly.

The API should ideally be written in .NET Core Web API. This matches the tech stack used by the rest of SMAPI, but lets us deploy it to Linux instances for reduced costs.

Pathoschild commented 7 years ago

See Dewdrop prototype by @LeonBlade.

Pathoschild commented 7 years ago

The update API is pretty much done for the initial release in 2.0.

The API supports Nexus Mods and GitHub (authenticated to increase rate limit), with a half-hour cache for each mod lookup. You just call the endpoint with any number of namespaced mod keys (which take the form site name:mod ID):

GET https://api.smapi.io/v2.0/mods?modKeys=Nexus:541,GitHub:Pathoschild/SMAPI
{
  "GitHub:Pathoschild/SMAPI": {
    "name": "Pathoschild/SMAPI",
    "version": "1.15.4",
    "url": "https://github.com/Pathoschild/SMAPI/releases"
  },
  "Nexus:541": {
    "name": "Lookup Anything",
    "version": "1.16",
    "url": "http://www.nexusmods.com/stardewvalley/mods/541"
  }
}

Next is adding the clientside update check feature.

Pathoschild commented 7 years ago

Done and merged into develop for the upcoming 2.0 release. I moved retroactive update keys to #361.