mirror of
https://codeberg.org/demostf/api.git
synced 2026-06-03 09:54:17 +02:00
allow more steamid formats in user api
This commit is contained in:
parent
13e6f950d2
commit
ecb9e41999
4 changed files with 11 additions and 11 deletions
|
|
@ -4,6 +4,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Demostf\API\Controllers;
|
||||
|
||||
use Demostf\API\Demo\Parser;
|
||||
use Demostf\API\Providers\UserProvider;
|
||||
use flight\net\Request;
|
||||
use flight\net\Response;
|
||||
|
|
@ -20,6 +21,9 @@ class UserController extends BaseController {
|
|||
}
|
||||
|
||||
public function get($steamId) {
|
||||
if (!is_numeric($steamId)) {
|
||||
$steamId = Parser::convertSteamIdToCommunityId($steamId);
|
||||
}
|
||||
\Flight::json($this->userProvider->get($steamId));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ class Parser {
|
|||
$players[] = new ParsedPlayer(
|
||||
$player['name'],
|
||||
$player['userId'],
|
||||
$this->convertSteamIdToCommunityId($player['steamId']),
|
||||
self::convertSteamIdToCommunityId($player['steamId']),
|
||||
$player['team'] ?? '',
|
||||
$this->getClassName((int) $class)
|
||||
);
|
||||
|
|
@ -151,7 +151,7 @@ class Parser {
|
|||
*
|
||||
* @return string The converted 64bit numeric SteamID
|
||||
*/
|
||||
public function convertSteamIdToCommunityId(string $steamId): string {
|
||||
public static function convertSteamIdToCommunityId(string $steamId): string {
|
||||
if ($steamId === 'STEAM_ID_LAN' || $steamId === 'BOT') {
|
||||
throw new \InvalidArgumentException("Cannot convert SteamID \"$steamId\" to a community ID.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ class ParserTest extends TestCase {
|
|||
$this->assertEquals($expectedPlayers[0]['demo_user_id'], $result->getPlayers()[0]->getDemoUserId());
|
||||
$this->assertEquals($expectedPlayers[0]['team'], $result->getPlayers()[0]->getTeam());
|
||||
$this->assertEquals($expectedPlayers[0]['class'], $result->getPlayers()[0]->getClass());
|
||||
$this->assertEquals($parser->convertSteamIdToCommunityId($expectedPlayers[0]['steam_id']), $result->getPlayers()[0]->getSteamId());
|
||||
$this->assertEquals(Parser::convertSteamIdToCommunityId($expectedPlayers[0]['steam_id']), $result->getPlayers()[0]->getSteamId());
|
||||
|
||||
$expectedKills = $expectedRaw['kills'];
|
||||
$this->assertCount(count($expectedKills), $result->getKills());
|
||||
|
|
@ -79,18 +79,14 @@ class ParserTest extends TestCase {
|
|||
}
|
||||
|
||||
public function testConvertSteamIdToCommunityId() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('STEAM_0:0:12345');
|
||||
$steamId64 = Parser::convertSteamIdToCommunityId('STEAM_0:0:12345');
|
||||
$this->assertEquals('76561197960290418', $steamId64);
|
||||
}
|
||||
|
||||
public function testConvertUIdToCommunityId() {
|
||||
$parser = new Parser($this->rawParser);
|
||||
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('[U:1:12345]');
|
||||
$steamId64 = Parser::convertSteamIdToCommunityId('[U:1:12345]');
|
||||
$this->assertEquals('76561197960278073', $steamId64);
|
||||
$steamId64 = $parser->convertSteamIdToCommunityId('[U:1:39743963]');
|
||||
$steamId64 = Parser::convertSteamIdToCommunityId('[U:1:39743963]');
|
||||
$this->assertEquals('76561198000009691', $steamId64);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ class UploadProviderTest extends TestCase {
|
|||
}
|
||||
|
||||
private function saveSteamId($steamId, $name) {
|
||||
$steamId = $this->getSteamId($this->parser->convertSteamIdToCommunityId($steamId), $name);
|
||||
$steamId = $this->getSteamId(Parser::convertSteamIdToCommunityId($steamId), $name);
|
||||
$this->userProvider->store($steamId);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue