Update ApiV1Dot1Controller, fix username to id endpoint

This commit is contained in:
Daniel Supernault 2024-06-08 06:56:29 -06:00
parent 679ef677b7
commit 4d6cea9aa4
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
1 changed files with 6 additions and 1 deletions

View File

@ -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 [];