mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Update ApiV1Controller, use PublicTimelineService
This commit is contained in:
parent
d43e6d8d07
commit
f67c67bce1
1 changed files with 19 additions and 70 deletions
|
@ -49,8 +49,10 @@ use App\Jobs\VideoPipeline\{
|
||||||
VideoThumbnail
|
VideoThumbnail
|
||||||
};
|
};
|
||||||
use App\Services\{
|
use App\Services\{
|
||||||
|
LikeService,
|
||||||
NotificationService,
|
NotificationService,
|
||||||
MediaPathService,
|
MediaPathService,
|
||||||
|
PublicTimelineService,
|
||||||
SearchApiV2Service,
|
SearchApiV2Service,
|
||||||
StatusService,
|
StatusService,
|
||||||
MediaBlocklistService
|
MediaBlocklistService
|
||||||
|
@ -1462,90 +1464,37 @@ class ApiV1Controller extends Controller
|
||||||
public function timelinePublic(Request $request)
|
public function timelinePublic(Request $request)
|
||||||
{
|
{
|
||||||
$this->validate($request,[
|
$this->validate($request,[
|
||||||
'page' => 'nullable|integer|max:40',
|
|
||||||
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
'min_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
'max_id' => 'nullable|integer|min:0|max:' . PHP_INT_MAX,
|
||||||
'limit' => 'nullable|integer|max:80'
|
'limit' => 'nullable|integer|max:80'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$page = $request->input('page');
|
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 3;
|
$limit = $request->input('limit') ?? 3;
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
if($user) {
|
if(PublicTimelineService::count() == 0) {
|
||||||
$key = 'user:last_active_at:id:'.$user->id;
|
PublicTimelineService::warmCache(true, 400);
|
||||||
$ttl = now()->addMinutes(5);
|
}
|
||||||
Cache::remember($key, $ttl, function() use($user) {
|
|
||||||
$user->last_active_at = now();
|
|
||||||
$user->save();
|
|
||||||
return;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if($min || $max) {
|
if ($max) {
|
||||||
$dir = $min ? '>' : '<';
|
$feed = PublicTimelineService::getRankedMaxId($max, $limit);
|
||||||
$id = $min ?? $max;
|
} else if ($min) {
|
||||||
$timeline = Status::select(
|
$feed = PublicTimelineService::getRankedMinId($min, $limit);
|
||||||
'id',
|
|
||||||
'uri',
|
|
||||||
'caption',
|
|
||||||
'rendered',
|
|
||||||
'profile_id',
|
|
||||||
'type',
|
|
||||||
'in_reply_to_id',
|
|
||||||
'reblog_of_id',
|
|
||||||
'is_nsfw',
|
|
||||||
'scope',
|
|
||||||
'local',
|
|
||||||
'reply_count',
|
|
||||||
'comments_disabled',
|
|
||||||
'place_id',
|
|
||||||
'likes_count',
|
|
||||||
'reblogs_count',
|
|
||||||
'created_at',
|
|
||||||
'updated_at'
|
|
||||||
)->whereNull('uri')
|
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
|
||||||
->with('profile', 'hashtags', 'mentions')
|
|
||||||
->where('id', $dir, $id)
|
|
||||||
->whereScope('public')
|
|
||||||
->where('created_at', '>', now()->subDays(14))
|
|
||||||
->latest()
|
|
||||||
->limit($limit)
|
|
||||||
->get();
|
|
||||||
} else {
|
} else {
|
||||||
$timeline = Status::select(
|
$feed = PublicTimelineService::get(0, $limit);
|
||||||
'id',
|
|
||||||
'uri',
|
|
||||||
'caption',
|
|
||||||
'rendered',
|
|
||||||
'profile_id',
|
|
||||||
'type',
|
|
||||||
'in_reply_to_id',
|
|
||||||
'reblog_of_id',
|
|
||||||
'is_nsfw',
|
|
||||||
'scope',
|
|
||||||
'local',
|
|
||||||
'reply_count',
|
|
||||||
'comments_disabled',
|
|
||||||
'place_id',
|
|
||||||
'likes_count',
|
|
||||||
'reblogs_count',
|
|
||||||
'created_at',
|
|
||||||
'updated_at'
|
|
||||||
)->whereNull('uri')
|
|
||||||
->whereIn('type', ['photo', 'photo:album', 'video', 'video:album'])
|
|
||||||
->with('profile', 'hashtags', 'mentions')
|
|
||||||
->whereScope('public')
|
|
||||||
->where('created_at', '>', now()->subDays(14))
|
|
||||||
->latest()
|
|
||||||
->simplePaginate($limit);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$fractal = new Fractal\Resource\Collection($timeline, new StatusTransformer());
|
$res = collect($feed)
|
||||||
$res = $this->fractal->createData($fractal)->toArray();
|
->map(function($k) use($user) {
|
||||||
|
$status = StatusService::get($k);
|
||||||
|
if($user) {
|
||||||
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
||||||
|
}
|
||||||
|
return $status;
|
||||||
|
})
|
||||||
|
->toArray();
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue