mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-10 16:44:50 +00:00
commit
2788de4688
1 changed files with 19 additions and 11 deletions
|
@ -89,6 +89,7 @@ use App\Jobs\FollowPipeline\FollowRejectPipeline;
|
||||||
class ApiV1Controller extends Controller
|
class ApiV1Controller extends Controller
|
||||||
{
|
{
|
||||||
protected $fractal;
|
protected $fractal;
|
||||||
|
const PF_API_ENTITY_KEY = "_pe";
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
|
@ -177,7 +178,7 @@ class ApiV1Controller extends Controller
|
||||||
abort_if(!$user, 403);
|
abort_if(!$user, 403);
|
||||||
abort_if($user->status != null, 403);
|
abort_if($user->status != null, 403);
|
||||||
|
|
||||||
$res = AccountService::getMastodon($user->profile_id);
|
$res = $request->has(self::PF_API_ENTITY_KEY) ? AccountService::get($user->profile_id) : AccountService::getMastodon($user->profile_id);
|
||||||
|
|
||||||
$res['source'] = [
|
$res['source'] = [
|
||||||
'privacy' => $res['locked'] ? 'private' : 'public',
|
'privacy' => $res['locked'] ? 'private' : 'public',
|
||||||
|
@ -199,7 +200,7 @@ class ApiV1Controller extends Controller
|
||||||
*/
|
*/
|
||||||
public function accountById(Request $request, $id)
|
public function accountById(Request $request, $id)
|
||||||
{
|
{
|
||||||
$res = AccountService::getMastodon($id, true);
|
$res = $request->has(self::PF_API_ENTITY_KEY) ? AccountService::get($id, true) : AccountService::getMastodon($id, true);
|
||||||
if(!$res) {
|
if(!$res) {
|
||||||
return response()->json(['error' => 'Record not found'], 404);
|
return response()->json(['error' => 'Record not found'], 404);
|
||||||
}
|
}
|
||||||
|
@ -554,7 +555,8 @@ class ApiV1Controller extends Controller
|
||||||
'limit' => 'nullable|integer|min:1|max:100'
|
'limit' => 'nullable|integer|min:1|max:100'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$profile = AccountService::getMastodon($id, true);
|
$napi = $request->has(self::PF_API_ENTITY_KEY);
|
||||||
|
$profile = $napi ? AccountService::get($id, true) : AccountService::getMastodon($id, true);
|
||||||
|
|
||||||
if(!$profile || !isset($profile['id']) || !$user) {
|
if(!$profile || !isset($profile['id']) || !$user) {
|
||||||
return response('', 404);
|
return response('', 404);
|
||||||
|
@ -604,8 +606,11 @@ class ApiV1Controller extends Controller
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->orderByDesc('id')
|
->orderByDesc('id')
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use($user) {
|
->map(function($s) use($user, $napi, $profile) {
|
||||||
$status = StatusService::getMastodon($s->id, false);
|
$status = $napi ? StatusService::get($s->id, false) : StatusService::getMastodon($s->id, false);
|
||||||
|
if($profile) {
|
||||||
|
$status['account'] = $profile;
|
||||||
|
}
|
||||||
|
|
||||||
if($user && $status) {
|
if($user && $status) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $s->id);
|
||||||
|
@ -1034,6 +1039,7 @@ class ApiV1Controller extends Controller
|
||||||
->get()
|
->get()
|
||||||
->map(function($like) {
|
->map(function($like) {
|
||||||
$status = StatusService::getMastodon($like['status_id'], false);
|
$status = StatusService::getMastodon($like['status_id'], false);
|
||||||
|
$status['favourited'] = true;
|
||||||
$status['like_id'] = $like->id;
|
$status['like_id'] = $like->id;
|
||||||
$status['liked_at'] = str_replace('+00:00', 'Z', $like->created_at->format(DATE_RFC3339_EXTENDED));
|
$status['liked_at'] = str_replace('+00:00', 'Z', $like->created_at->format(DATE_RFC3339_EXTENDED));
|
||||||
return $status;
|
return $status;
|
||||||
|
@ -1902,6 +1908,7 @@ class ApiV1Controller extends Controller
|
||||||
'limit' => 'nullable|integer|max:100'
|
'limit' => 'nullable|integer|max:100'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$napi = $request->has(self::PF_API_ENTITY_KEY);
|
||||||
$page = $request->input('page');
|
$page = $request->input('page');
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
|
@ -1931,7 +1938,7 @@ class ApiV1Controller extends Controller
|
||||||
->take(($limit * 2))
|
->take(($limit * 2))
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use($pid) {
|
->map(function($s) use($pid) {
|
||||||
$status = StatusService::getMastodon($s['id'], false);
|
$status = $napi ? StatusService::get($s['id'], false) : StatusService::getMastodon($s['id'], false);
|
||||||
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
|
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -1961,8 +1968,8 @@ class ApiV1Controller extends Controller
|
||||||
->latest()
|
->latest()
|
||||||
->take(($limit * 2))
|
->take(($limit * 2))
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use($pid) {
|
->map(function($s) use($pid, $napi) {
|
||||||
$status = StatusService::getMastodon($s['id'], false);
|
$status = $napi ? StatusService::get($s['id'], false) : StatusService::getMastodon($s['id'], false);
|
||||||
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
|
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2024,6 +2031,7 @@ class ApiV1Controller extends Controller
|
||||||
'local' => 'sometimes'
|
'local' => 'sometimes'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
$napi = $request->has(self::PF_API_ENTITY_KEY);
|
||||||
$min = $request->input('min_id');
|
$min = $request->input('min_id');
|
||||||
$max = $request->input('max_id');
|
$max = $request->input('max_id');
|
||||||
$limit = $request->input('limit') ?? 20;
|
$limit = $request->input('limit') ?? 20;
|
||||||
|
@ -2075,8 +2083,8 @@ class ApiV1Controller extends Controller
|
||||||
return $max != $k;
|
return $max != $k;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
->map(function($k) use($user) {
|
->map(function($k) use($user, $napi) {
|
||||||
$status = StatusService::getMastodon($k);
|
$status = $napi ? StatusService::get($k) : StatusService::getMastodon($k);
|
||||||
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
|
if(!$status || !isset($status['account']) || !isset($status['account']['id'])) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2207,7 +2215,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
$res = StatusService::getMastodon($id, false);
|
$res = $request->has(self::PF_API_ENTITY_KEY) ? StatusService::get($id, false) : StatusService::getMastodon($id, false);
|
||||||
if(!$res || !isset($res['visibility'])) {
|
if(!$res || !isset($res['visibility'])) {
|
||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue