xBiggs / fightcade-api

An unofficial TypeScript wrapper for the Fightcade API.
MIT License
7 stars 2 forks source link

Fix ReplaySchema inconsistencies #8

Closed JuAnXT closed 3 months ago

JuAnXT commented 3 months ago

The Fightcade API returns null or undefined values for some fields. The optimal solution would be to fix the issue on the server's side but this fix ensures the parser won't crash when retrieving data.

Quarkids used to reproduce the issue: : 1721068693697

Edit: updated the quarkids

xBiggs commented 3 months ago

@JuAnXT This quarkid is invalid 1721068693697. Send me the correct one so I can verify.

#! /usr/bin/env node

async function GetReplay(quarkid) {
  const response = await fetch("https://www.fightcade.com/api/", {
    method: "POST",
    headers: { "Content-Type": "application/json" },
    body: JSON.stringify({ req: "searchquarks", quarkid })
  });

  return await response.json();
}

const stuff = await GetReplay('1721068693697');

console.log(stuff);
{ results: { results: [], count: 15 }, res: 'OK' }
xBiggs commented 3 months ago

Talked to @JuAnXT on Discord and he sent me the following quarkids

1622985629352-7981: ranked property is null

[
  {
    quarkid: '1622985629352-7981',
    channelname: 'Samurai Shodown V Special / Samurai Spirits Zero Special (NGM-2720)',
    date: 1622985629352,
    duration: 1011.639,
    emulator: 'fbneo',
    gameid: 'samsh5sp',
    num_matches: 0,
    players: [ [Object], [Object] ],
    ranked: null,
    replay_file: '1622985629352-7981-replay.fs',
    realtime_views: 2,
    saved_views: 1
  }
]

1460150204220-5996: num_matches is missing

[
  {
    quarkid: '1460150204220-5996',
    channelname: 'Street Fighter III 3rd Strike: Fight for the Future (Japan 990512, NO CD) (ARCADE FC1)',
    gameid: 'fc1_sfiii3n',
    emulator: 'fc1',
    ranked: 0,
    date: 1460150222000,
    duration: 968,
    players: [ [Object], [Object] ],
    replay_file: '1460150204220-5996-replay.fs',
    realtime_views: 0,
    saved_views: 0
  }
]

The latter looks to be a FC1 replay. These changes are good so I'll merge it. Thanks for the fix.