mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Add /api/v1/accounts/search endpoint
This commit is contained in:
parent
4b9f7d6b14
commit
b1fccf6d82
2 changed files with 37 additions and 0 deletions
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Api;
|
|||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Str;
|
||||
use App\Util\ActivityPub\Helpers;
|
||||
use App\Jobs\StatusPipeline\StatusDelete;
|
||||
use App\Jobs\FollowPipeline\FollowPipeline;
|
||||
use Laravel\Passport\Passport;
|
||||
|
@ -468,6 +469,40 @@ class ApiV1Controller extends Controller
|
|||
return response()->json($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* GET /api/v1/accounts/search
|
||||
*
|
||||
*
|
||||
*
|
||||
* @return \App\Transformer\Api\AccountTransformer
|
||||
*/
|
||||
public function accountSearch(Request $request)
|
||||
{
|
||||
abort_if(!$request->user(), 403);
|
||||
|
||||
$this->validate($request, [
|
||||
'q' => 'required|string|min:1|max:255',
|
||||
'limit' => 'nullable|integer|min:1|max:40',
|
||||
'resolve' => 'nullable'
|
||||
]);
|
||||
|
||||
$user = $request->user();
|
||||
$query = $request->input('q');
|
||||
$limit = $request->input('limit') ?? 20;
|
||||
$resolve = (bool) $request->input('resolve', false);
|
||||
$q = '%' . $query . '%';
|
||||
|
||||
$profiles = Profile::whereNull('status')
|
||||
->where('username', 'like', $q)
|
||||
->orWhere('name', 'like', $q)
|
||||
->limit($limit)
|
||||
->get();
|
||||
|
||||
$resource = new Fractal\Resource\Collection($profiles, new AccountTransformer());
|
||||
$res = $this->fractal->createData($resource)->toArray();
|
||||
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
|
||||
}
|
||||
|
||||
public function statusById(Request $request, $id)
|
||||
{
|
||||
$status = Status::whereVisibility('public')->findOrFail($id);
|
||||
|
|
|
@ -80,6 +80,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
|||
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials')->middleware('auth:api');
|
||||
Route::patch('accounts/update_credentials', 'Api\ApiV1Controller@accountUpdateCredentials')->middleware('auth:api');
|
||||
Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById')->middleware('auth:api');
|
||||
Route::get('accounts/search', 'Api\ApiV1Controller@accountSearch')->middleware('auth:api');
|
||||
Route::get('accounts/{id}/statuses', 'Api\ApiV1Controller@accountStatusesById')->middleware('auth:api');
|
||||
Route::get('accounts/{id}/following', 'Api\ApiV1Controller@accountFollowingById')->middleware('auth:api');
|
||||
Route::get('accounts/{id}/followers', 'Api\ApiV1Controller@accountFollowersById')->middleware('auth:api');
|
||||
|
@ -116,6 +117,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
|||
Route::group(['prefix' => 'v1'], function() {
|
||||
Route::get('accounts/verify_credentials', 'ApiController@verifyCredentials');
|
||||
Route::get('accounts/relationships', 'Api\ApiV1Controller@accountRelationshipsById');
|
||||
Route::get('accounts/search', 'Api\ApiV1Controller@accountSearch');
|
||||
Route::get('accounts/{id}/statuses', 'PublicApiController@accountStatuses');
|
||||
Route::get('accounts/{id}/following', 'PublicApiController@accountFollowing');
|
||||
Route::get('accounts/{id}/followers', 'PublicApiController@accountFollowers');
|
||||
|
|
Loading…
Reference in a new issue