mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 00:34:50 +00:00
Add /api/v1/timelines/public endpoint
This commit is contained in:
parent
336f906968
commit
f3eeb9c978
2 changed files with 78 additions and 0 deletions
|
@ -1236,6 +1236,83 @@ class ApiV1Controller extends Controller
|
||||||
return response()->json([]);
|
return response()->json([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GET /api/v1/timelines/public
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @return App\Transformer\Api\StatusTransformer
|
||||||
|
*/
|
||||||
|
public function timelinePublic(Request $request)
|
||||||
|
{
|
||||||
|
$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;
|
||||||
|
|
||||||
|
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)
|
||||||
|
->whereVisibility('public')
|
||||||
|
->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')
|
||||||
|
->whereVisibility('public')
|
||||||
|
->latest()
|
||||||
|
->simplePaginate($limit);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
||||||
|
$res = $this->fractal->createData($fractal)->toArray();
|
||||||
|
return response()->json($res);
|
||||||
|
}
|
||||||
|
|
||||||
public function statusById(Request $request, $id)
|
public function statusById(Request $request, $id)
|
||||||
{
|
{
|
||||||
$status = Status::whereVisibility('public')->findOrFail($id);
|
$status = Status::whereVisibility('public')->findOrFail($id);
|
||||||
|
|
|
@ -118,6 +118,7 @@ Route::domain(config('pixelfed.domain.app'))->middleware(['validemail', 'twofact
|
||||||
|
|
||||||
Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware('auth:api');
|
Route::get('timelines/home', 'Api\ApiV1Controller@timelineHome')->middleware('auth:api');
|
||||||
Route::get('conversations', 'Api\ApiV1Controller@conversations')->middleware('auth:api');
|
Route::get('conversations', 'Api\ApiV1Controller@conversations')->middleware('auth:api');
|
||||||
|
Route::get('timelines/public', 'Api\ApiV1Controller@timelinePublic');
|
||||||
|
|
||||||
// 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');
|
||||||
|
|
Loading…
Reference in a new issue