Merge branch 'staging' of https://github.com/pixelfed/pixelfed into translation-coverage-extension

This commit is contained in:
Jeff Poirier 2024-07-07 20:06:18 +00:00
commit 042bef1fb2
3 changed files with 40 additions and 8 deletions

View file

@ -1,6 +1,10 @@
# Release Notes
## [Unreleased](https://github.com/pixelfed/pixelfed/compare/v0.12.3...dev)
### Updates
- Update ApiV1Controller, add support for notification filter types ([f61159a1](https://github.com/pixelfed/pixelfed/commit/f61159a1))
- Update ApiV1Dot1Controller, fix mutual api ([a8bb97b2](https://github.com/pixelfed/pixelfed/commit/a8bb97b2))
- ([](https://github.com/pixelfed/pixelfed/commit/))
## [v0.12.3 (2024-07-01)](https://github.com/pixelfed/pixelfed/compare/v0.12.2...v0.12.3)

View file

@ -211,6 +211,7 @@ class ApiV1Controller extends Controller
abort_if(! $request->user() || ! $request->user()->token(), 403);
abort_unless($request->user()->tokenCan('read'), 403);
$withInstanceMeta = $request->has('_wim');
$res = $request->has(self::PF_API_ENTITY_KEY) ? AccountService::get($id, true) : AccountService::getMastodon($id, true);
if (! $res) {
return response()->json(['error' => 'Record not found'], 404);
@ -752,7 +753,15 @@ class ApiV1Controller extends Controller
$dir = $min_id ? '>' : '<';
$id = $min_id ?? $max_id;
$res = Status::whereProfileId($profile['id'])
$res = Status::select(
'profile_id',
'in_reply_to_id',
'reblog_of_id',
'type',
'id',
'scope'
)
->whereProfileId($profile['id'])
->whereNull('in_reply_to_id')
->whereNull('reblog_of_id')
->whereIn('type', $scope)
@ -2272,14 +2281,17 @@ class ApiV1Controller extends Controller
'max_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
'since_id' => 'nullable|integer|min:1|max:'.PHP_INT_MAX,
'types[]' => 'sometimes|array',
'types[].*' => 'string|in:mention,reblog,follow,favourite',
'type' => 'sometimes|string|in:mention,reblog,follow,favourite',
'_pe' => 'sometimes',
]);
$pid = $request->user()->profile_id;
$limit = $request->input('limit', 20);
$ogLimit = $request->input('limit', 20);
if ($limit > 40) {
$limit = 40;
$ogLimit = 40;
}
$since = $request->input('since_id');
@ -2297,6 +2309,10 @@ class ApiV1Controller extends Controller
$types = $request->input('types');
if ($request->has('types')) {
$limit = 150;
}
$maxId = null;
$minId = null;
AccountService::setLastActive($request->user()->id);
@ -2319,7 +2335,12 @@ class ApiV1Controller extends Controller
}
}
$baseUrl = config('app.url').'/api/v1/notifications?limit='.$limit.'&';
if ($request->has('types')) {
$typesParams = collect($types)->implode('&types[]=');
$baseUrl = config('app.url').'/api/v1/notifications?types[]='.$typesParams.'&limit='.$ogLimit.'&';
} else {
$baseUrl = config('app.url').'/api/v1/notifications?limit='.$ogLimit.'&';
}
if ($minId == $maxId) {
$minId = null;
@ -2361,7 +2382,16 @@ class ApiV1Controller extends Controller
}
return true;
})->values();
})
->filter(function ($n) use ($types) {
if (! $types) {
return true;
}
return in_array($n['type'], $types);
})
->take($ogLimit)
->values();
if ($maxId) {
$link = '<'.$baseUrl.'max_id='.$minId.'>; rel="next"';

View file

@ -487,8 +487,7 @@ class ApiV1Dot1Controller extends Controller
abort_if(BouncerService::checkIp($request->ip()), 404);
}
$rl = RateLimiter::attempt('pf:apiv1.1:iar:'.$request->ip(), config('pixelfed.app_registration_rate_limit_attempts', 3), function () {
}, config('pixelfed.app_registration_rate_limit_decay', 1800));
$rl = RateLimiter::attempt('pf:apiv1.1:iar:'.$request->ip(), config('pixelfed.app_registration_rate_limit_attempts', 3), function () {}, config('pixelfed.app_registration_rate_limit_decay', 1800));
abort_if(! $rl, 400, 'Too many requests');
$this->validate($request, [
@ -618,8 +617,7 @@ class ApiV1Dot1Controller extends Controller
abort_if(BouncerService::checkIp($request->ip()), 404);
}
$rl = RateLimiter::attempt('pf:apiv1.1:iarc:'.$request->ip(), config('pixelfed.app_registration_confirm_rate_limit_attempts', 20), function () {
}, config('pixelfed.app_registration_confirm_rate_limit_decay', 1800));
$rl = RateLimiter::attempt('pf:apiv1.1:iarc:'.$request->ip(), config('pixelfed.app_registration_confirm_rate_limit_attempts', 20), function () {}, config('pixelfed.app_registration_confirm_rate_limit_decay', 1800));
abort_if(! $rl, 429, 'Too many requests');
$request->validate([
@ -929,7 +927,7 @@ class ApiV1Dot1Controller extends Controller
public function getMutualAccounts(Request $request, $id)
{
abort_if(! $request->user() || ! $request->user()->token(), 403);
abort_unless($request->user()->tokenCan('follows'), 403);
abort_unless($request->user()->tokenCan('follow'), 403);
$account = AccountService::get($id, true);
if (! $account || ! isset($account['id'])) {