mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-25 15:55:22 +00:00
Add /api/v1/timelines/home endpoint
This commit is contained in:
parent
ed65136109
commit
cf3405d852
2 changed files with 90 additions and 1 deletions
|
@ -1134,6 +1134,94 @@ class ApiV1Controller extends Controller
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/v1/timelines/home
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return App\Transformer\Api\StatusTransformer
|
||||||
|
*/
|
||||||
|
public function timelineHome(Request $request)
|
||||||
|
{
|
||||||
|
abort_if(!$request->user(), 403);
|
||||||
|
|
||||||
|
$this->validate($request,[
|
||||||
|
'page' => 'nullable|integer|max:40',
|
||||||
|
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
|
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
|
'limit' => 'nullable|integer|max:40'
|
||||||
|
]);
|
||||||
|
|
||||||
|
$page = $request->input('page');
|
||||||
|
$min = $request->input('min_id');
|
||||||
|
$max = $request->input('max_id');
|
||||||
|
$limit = $request->input('limit') ?? 3;
|
||||||
|
|
||||||
|
$pid = $request->user()->profile_id;
|
||||||
|
|
||||||
|
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
||||||
|
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
||||||
|
return $following->push($pid)->toArray();
|
||||||
|
});
|
||||||
|
|
||||||
|
if($min || $max) {
|
||||||
|
$dir = $min ? '>' : '<';
|
||||||
|
$id = $min ?? $max;
|
||||||
|
$timeline = Status::select(
|
||||||
|
'id',
|
||||||
|
'uri',
|
||||||
|
'caption',
|
||||||
|
'rendered',
|
||||||
|
'profile_id',
|
||||||
|
'type',
|
||||||
|
'in_reply_to_id',
|
||||||
|
'reblog_of_id',
|
||||||
|
'is_nsfw',
|
||||||
|
'scope',
|
||||||
|
'local',
|
||||||
|
'reply_count',
|
||||||
|
'comments_disabled',
|
||||||
|
'place_id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at'
|
||||||
|
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
||||||
|
->with('profile', 'hashtags', 'mentions')
|
||||||
|
->where('id', $dir, $id)
|
||||||
|
->whereIn('profile_id', $following)
|
||||||
|
->whereIn('visibility',['public', 'unlisted', 'private'])
|
||||||
|
->latest()
|
||||||
|
->limit($limit)
|
||||||
|
->get();
|
||||||
|
} else {
|
||||||
|
$timeline = Status::select(
|
||||||
|
'id',
|
||||||
|
'uri',
|
||||||
|
'caption',
|
||||||
|
'rendered',
|
||||||
|
'profile_id',
|
||||||
|
'type',
|
||||||
|
'in_reply_to_id',
|
||||||
|
'reblog_of_id',
|
||||||
|
'is_nsfw',
|
||||||
|
'scope',
|
||||||
|
'local',
|
||||||
|
'reply_count',
|
||||||
|
'comments_disabled',
|
||||||
|
'place_id',
|
||||||
|
'created_at',
|
||||||
|
'updated_at'
|
||||||
|
)->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
||||||
|
->with('profile', 'hashtags', 'mentions')
|
||||||
|
->whereIn('profile_id', $following)
|
||||||
|
->whereIn('visibility',['public', 'unlisted', 'private'])
|
||||||
|
->latest()
|
||||||
|
->simplePaginate($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
||||||
|
$res = $this->fractal->createData($fractal)->toArray();
|
||||||
|
return response()->json($res, 200, [], JSON_PRETTY_PRINT);
|
||||||
|
}
|
||||||
|
|
||||||
public function statusById(Request $request, $id)
|
public function statusById(Request $request, $id)
|
||||||
{
|
{
|
||||||
$status = Status::whereVisibility('public')->findOrFail($id);
|
$status = Status::whereVisibility('public')->findOrFail($id);
|
||||||
|
|
|
@ -115,13 +115,14 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware('auth:api');
|
Route::post('accounts/{id}/mute', 'Api\ApiV1Controller@accountMuteById')->middleware('auth:api');
|
||||||
Route::post('accounts/{id}/unmute', 'Api\ApiV1Controller@accountUnmuteById')->middleware('auth:api');
|
Route::post('accounts/{id}/unmute', 'Api\ApiV1Controller@accountUnmuteById')->middleware('auth:api');
|
||||||
Route::get('notifications', 'Api\ApiV1Controller@accountNotifications')->middleware('auth:api');
|
Route::get('notifications', 'Api\ApiV1Controller@accountNotifications')->middleware('auth:api');
|
||||||
|
|
||||||
|
Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome');
|
||||||
|
|
||||||
// Route::get('likes', 'ApiController@hydrateLikes');
|
// Route::get('likes', 'ApiController@hydrateLikes');
|
||||||
// Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');
|
// Route::post('media', 'ApiController@uploadMedia')->middleware('auth:api');
|
||||||
// Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api');
|
// Route::delete('media', 'ApiController@deleteMedia')->middleware('auth:api');
|
||||||
// Route::get('notifications', 'ApiController@notifications')->middleware('auth:api');
|
// Route::get('notifications', 'ApiController@notifications')->middleware('auth:api');
|
||||||
// Route::get('timelines/public', 'PublicApiController@publicTimelineApi');
|
// Route::get('timelines/public', 'PublicApiController@publicTimelineApi');
|
||||||
// Route::get('timelines/home', 'PublicApiController@homeTimelineApi')->middleware('auth:api');
|
|
||||||
// Route::post('status', 'Api\ApiV1Controller@createStatus')->middleware('auth:api');
|
// Route::post('status', 'Api\ApiV1Controller@createStatus')->middleware('auth:api');
|
||||||
Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById');
|
Route::get('accounts/{id}', 'Api\ApiV1Controller@accountById');
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue