RiiConnect24 / RiiTag-Next

A customizable Gamertag for Wii, Wii U and more! Now powered by Next.js.
https://tag.rc24.xyz
GNU Affero General Public License v3.0
15 stars 14 forks source link

Fix JSON output #15

Closed larsenv closed 2 years ago

larsenv commented 2 years ago

https://github.com/RiiConnect24/RiiTag-RPC relies on getting a JSON file formatted in the format used with RiiTag v1 in order to read what games are being played. Since RiiTag v2 doesn't output this properly, RiiTag-RPC is currently broken. I think it might be only checking the games played and the timestamp.

Example JSON https://transfer.archivete.am/Pk8XE/314466499312222208.json

Brawl345 commented 2 years ago

Looks like it expects a dictionary: https://github.com/RiiConnect24/RiiTag-RPC/blob/master/riitag/user.py#L15 not an array what we currently have/what's in your JSON. Maybe @DismissedGuy can say something about this?

malmeloo commented 2 years ago

Larsen's example JSON is an example of V1's internal "database" and does not follow the same format as the public JSON API. This is where V1 generated its response: https://github.com/RiiConnect24/RiiTag/blob/b83c9bd3a1152df7eb22876dec60f5b643584e5a/app.js#L472

It's been way too long since I've touched RiiTag-RPC, but IIRC, it should expect the following format:

{
  "user": {
    "name": <name on riitag>,
    "id": <user id>
  },
  "tag_url": {
    "normal": <url to regularly sized tag>,
    "max": <url to max resolution tag>
  },
  "game_data": {
    "last_played": {
      "game_id": <game id>,
      "console": <console>,
      "region": <game region>,
      "cover_url": <url to game cover>,
      "time": <time of last launch as unix epoch>
    },
    "games": [ <chronologically ordered list of recently played game IDs> ]
  }
}

game_data.last_played can also be an empty dict if the user hasn't played any games yet.

It's worth noting that I haven't had time yet to actually check the error myself, but following the above format should in theory fix it.

Brawl345 commented 2 years ago

Thank you, I think I can work with this! I think some fields are unused (region? is the games array even used?) and I would like to reorganize them (making games not an array of ids but an array of dicts)

malmeloo commented 2 years ago

Some fields are indeed unused; which ones exactly I cannot tell right now but I'll look into it. I do know that the games array is used to display a simple list of games the user has played in the past.

I do agree that the current format isn't the best. Feel free to change it around, I can update RiiTag-RPC to support the new format. Maybe even introduce some new features if the endpoint returns more interesting data to work with.

In any case, I won't be able to actually work on it until the end of the week, probably. So if a "quick fix" is required, it might be better to temporarily use that old format until then. Unless someone else feels like working on it of course.

Brawl345 commented 2 years ago

The API should have the same output as the original one now:

JSON Output ```json { "user":{ "name":"Brawl", "id":"110806999020625920" }, "tag_url":{ "normal":"http://localhost:3000/110806999020625920/tag.png", "max":"http://localhost:3000/110806999020625920/tag.max.png" }, "game_data":{ "last_played":{ "game_id":"RSBJ01", "console":"wii", "region":"JA", "cover_url":"http://localhost:3000/api/cover/wii/RSBJ01", "time":1660063539985 }, "games":[ "wii-RSBJ01" ] } } ```

I will make a new endpoint (like /api/user/v2 or something) that returns new data with improved structure.

malmeloo commented 2 years ago

Looks good, but RiiTag-RPC wants the last played epoch in seconds instead of milliseconds. I made a PR to fix that: #18

malmeloo commented 2 years ago

By the way, I dug into the source code a bit, and the only data that it currently needs is the time of the last played game, the ID of that game, and the game history. All other fields appear to be unused as far as I can tell.