From 4d6cea9aa4714f7400ce7fc2effcfc5a140efbac Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 8 Jun 2024 06:56:29 -0600 Subject: [PATCH 1/2] Update ApiV1Dot1Controller, fix username to id endpoint --- app/Http/Controllers/Api/ApiV1Dot1Controller.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Dot1Controller.php b/app/Http/Controllers/Api/ApiV1Dot1Controller.php index dc34594e5..8c3fd57fa 100644 --- a/app/Http/Controllers/Api/ApiV1Dot1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Dot1Controller.php @@ -950,7 +950,7 @@ class ApiV1Dot1Controller extends Controller { abort_if(! $request->user() || ! $request->user()->token() || ! $username, 403); abort_unless($request->user()->tokenCan('read'), 403); - + $username = trim($username); $rateLimiting = (bool) config_cache('api.rate-limits.v1Dot1.accounts.usernameToId.enabled'); $ipRateLimiting = (bool) config_cache('api.rate-limits.v1Dot1.accounts.usernameToId.ip_enabled'); if ($ipRateLimiting) { @@ -997,6 +997,11 @@ class ApiV1Dot1Controller extends Controller 'X-Rate-Limit-Reset' => RateLimiter::availableIn($userKey), ]; } + if(str_ends_with($username, config_cache('pixelfed.domain.app'))) { + $pre = str_starts_with($username, '@') ? substr($username, 1) : $username; + $parts = explode('@', $pre); + $username = $parts[0]; + } $accountId = AccountService::usernameToId($username, true); if (! $accountId) { return []; From 5b85efb5705a274990cbfcbe8d6483c6a258af46 Mon Sep 17 00:00:00 2001 From: Daniel Supernault Date: Sat, 8 Jun 2024 06:57:09 -0600 Subject: [PATCH 2/2] Update ApiV1Dot1Controller, lint --- app/Http/Controllers/Api/ApiV1Dot1Controller.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/ApiV1Dot1Controller.php b/app/Http/Controllers/Api/ApiV1Dot1Controller.php index 8c3fd57fa..7165629c2 100644 --- a/app/Http/Controllers/Api/ApiV1Dot1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Dot1Controller.php @@ -997,7 +997,7 @@ class ApiV1Dot1Controller extends Controller 'X-Rate-Limit-Reset' => RateLimiter::availableIn($userKey), ]; } - if(str_ends_with($username, config_cache('pixelfed.domain.app'))) { + if (str_ends_with($username, config_cache('pixelfed.domain.app'))) { $pre = str_starts_with($username, '@') ? substr($username, 1) : $username; $parts = explode('@', $pre); $username = $parts[0];