= `${P}_${string}`; // eslint-disable-next-line @typescript-eslint/no-empty-interface export interface Model {} diff --git a/resources/scripts/api/server/getServer.ts b/resources/scripts/api/server/getServer.ts index d2aa2e054..16743ef87 100644 --- a/resources/scripts/api/server/getServer.ts +++ b/resources/scripts/api/server/getServer.ts @@ -1,6 +1,7 @@ import http, { FractalResponseData, FractalResponseList } from '@/api/http'; import { rawDataToServerAllocation, rawDataToServerEggVariable } from '@/api/transformers'; import { ServerEggVariable, ServerStatus } from '@/api/server/types'; +import { Identifier } from '@/api/definitions'; export interface Allocation { id: number; @@ -12,8 +13,24 @@ export interface Allocation { } export interface Server { - id: string; + /** + * This value is determined by the presence of the `PTERODACTYL_USE_SERVER_IDENTIFIERS` environment + * variable which changes what the API can respond with. It will eventually be removed and referenced + * as the "identifier" key, but this allows users to slowly opt-in to these new URLs and trial it + * as they wish. + * + * @deprecated this is the "uuid_short" which will be removed in 2.0, prefer use of "identifier" + */ + id: string | Identifier<'serv'>; + identifier: Identifier<'serv'>; // Set from "server_identifier" and should be used moving forward to reference a server. internalId: number | string; + /** + * Exists only to maintain support in cases where the short-uuid is necessary for server reference + * and cannot be easily replaced with "identifier". + * + * @deprecated + */ + __deprecatedUuidShort: string; uuid: string; name: string; node: string; @@ -47,7 +64,9 @@ export interface Server { export const rawDataToServerObject = ({ attributes: data }: FractalResponseData): Server => ({ id: data.identifier, + identifier: data.server_identifier, internalId: data.internal_id, + __deprecatedUuidShort: data.__deprecated_uuid_short, uuid: data.uuid, name: data.name, node: data.node, diff --git a/tests/Integration/Api/Client/ClientControllerTest.php b/tests/Integration/Api/Client/ClientControllerTest.php index 954ca6f53..44084450a 100644 --- a/tests/Integration/Api/Client/ClientControllerTest.php +++ b/tests/Integration/Api/Client/ClientControllerTest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Tests\Integration\Api\Client; +use Ramsey\Uuid\Uuid; use Pterodactyl\Models\User; use Pterodactyl\Models\Server; use Pterodactyl\Models\Subuser; @@ -53,8 +54,8 @@ class ClientControllerTest extends ClientApiIntegrationTestCase $servers = [ $this->createServerModel(['user_id' => $users[0]->id, 'name' => 'Julia']), $this->createServerModel(['user_id' => $users[1]->id, 'uuidShort' => '12121212', 'name' => 'Janice']), - $this->createServerModel(['user_id' => $users[1]->id, 'uuid' => '88788878-12356789', 'external_id' => 'ext123', 'name' => 'Julia']), - $this->createServerModel(['user_id' => $users[1]->id, 'uuid' => '88788878-abcdefgh', 'name' => 'Jennifer']), + $this->createServerModel(['user_id' => $users[1]->id, 'uuid' => Uuid::uuid4()->toString(), 'external_id' => 'ext123', 'name' => 'Julia']), + $this->createServerModel(['user_id' => $users[1]->id, 'uuid' => Uuid::uuid4()->toString(), 'name' => 'Jennifer']), ]; $this->actingAs($users[1])->getJson('/api/client?filter[*]=Julia') @@ -77,16 +78,14 @@ class ClientControllerTest extends ClientApiIntegrationTestCase ->assertJsonCount(1, 'data') ->assertJsonPath('data.0.attributes.identifier', $servers[1]->uuidShort); - $this->actingAs($users[1])->getJson('/api/client?filter[*]=88788878') + $this->actingAs($users[1])->getJson("/api/client?filter[*]={$servers[2]->uuidShort}") ->assertOk() - ->assertJsonCount(2, 'data') - ->assertJsonPath('data.0.attributes.identifier', $servers[2]->uuidShort) - ->assertJsonPath('data.1.attributes.identifier', $servers[3]->uuidShort); + ->assertJsonCount(1, 'data') + ->assertJsonPath('data.0.attributes.identifier', $servers[2]->uuidShort); $this->actingAs($users[1])->getJson('/api/client?filter[*]=88788878-abcd') ->assertOk() - ->assertJsonCount(1, 'data') - ->assertJsonPath('data.0.attributes.identifier', $servers[3]->uuidShort); + ->assertJsonCount(0, 'data'); $this->actingAs($users[0])->getJson('/api/client?filter[*]=Julia&type=admin-all') ->assertOk()