mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-22 06:21:27 +00:00
Update ApiV1Controller, add mastoapi strict mode
This commit is contained in:
parent
1f70e248ff
commit
46485426ea
4 changed files with 59 additions and 32 deletions
|
@ -64,7 +64,6 @@ use App\Services\{
|
||||||
NotificationService,
|
NotificationService,
|
||||||
MediaPathService,
|
MediaPathService,
|
||||||
PublicTimelineService,
|
PublicTimelineService,
|
||||||
ProfileService,
|
|
||||||
RelationshipService,
|
RelationshipService,
|
||||||
SearchApiV2Service,
|
SearchApiV2Service,
|
||||||
StatusService,
|
StatusService,
|
||||||
|
@ -142,7 +141,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$id = $request->user()->profile_id;
|
$id = $request->user()->profile_id;
|
||||||
|
|
||||||
$res = ProfileService::get($id);
|
$res = AccountService::getMastodon($id);
|
||||||
|
|
||||||
$res['source'] = [
|
$res['source'] = [
|
||||||
'privacy' => $res['locked'] ? 'private' : 'public',
|
'privacy' => $res['locked'] ? 'private' : 'public',
|
||||||
|
@ -164,10 +163,10 @@ class ApiV1Controller extends Controller
|
||||||
*/
|
*/
|
||||||
public function accountById(Request $request, $id)
|
public function accountById(Request $request, $id)
|
||||||
{
|
{
|
||||||
$profile = Profile::whereNull('status')->findOrFail($id);
|
$res = AccountService::getMastodon($id, true);
|
||||||
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
|
if(!$res) {
|
||||||
$res = $this->fractal->createData($resource)->toArray();
|
return response()->json(['error' => 'Record not found'], 404);
|
||||||
|
}
|
||||||
return response()->json($res);
|
return response()->json($res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -394,7 +393,7 @@ class ApiV1Controller extends Controller
|
||||||
MediaSyncLicensePipeline::dispatch($user->id, $request->input('license'));
|
MediaSyncLicensePipeline::dispatch($user->id, $request->input('license'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$res = AccountService::get($user->profile_id);
|
$res = AccountService::getMastodon($user->profile_id);
|
||||||
$res['bio'] = strip_tags($res['note']);
|
$res['bio'] = strip_tags($res['note']);
|
||||||
$res = array_merge($res, $other);
|
$res = array_merge($res, $other);
|
||||||
|
|
||||||
|
@ -508,7 +507,7 @@ class ApiV1Controller extends Controller
|
||||||
'limit' => 'nullable|integer|min:1|max:80'
|
'limit' => 'nullable|integer|min:1|max:80'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$profile = AccountService::get($id);
|
$profile = AccountService::getMastodon($id);
|
||||||
abort_if(!$profile, 404);
|
abort_if(!$profile, 404);
|
||||||
|
|
||||||
$limit = $request->limit ?? 20;
|
$limit = $request->limit ?? 20;
|
||||||
|
@ -534,17 +533,12 @@ class ApiV1Controller extends Controller
|
||||||
if($pid == $profile['id']) {
|
if($pid == $profile['id']) {
|
||||||
$visibility = ['public', 'unlisted', 'private'];
|
$visibility = ['public', 'unlisted', 'private'];
|
||||||
} else if($profile['locked']) {
|
} else if($profile['locked']) {
|
||||||
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
$following = FollowerService::follows($pid, $profile['id']);
|
||||||
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
abort_unless($following, 403);
|
||||||
return $following->push($pid)->toArray();
|
$visibility = ['public', 'unlisted', 'private'];
|
||||||
});
|
|
||||||
$visibility = true == in_array($profile['id'], $following) ? ['public', 'unlisted', 'private'] : [];
|
|
||||||
} else {
|
} else {
|
||||||
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
|
$following = FollowerService::follows($pid, $profile['id']);
|
||||||
$following = Follower::whereProfileId($pid)->pluck('following_id');
|
$visibility = $following ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
|
||||||
return $following->push($pid)->toArray();
|
|
||||||
});
|
|
||||||
$visibility = true == in_array($profile['id'], $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$dir = $min_id ? '>' : '<';
|
$dir = $min_id ? '>' : '<';
|
||||||
|
@ -560,7 +554,7 @@ class ApiV1Controller extends Controller
|
||||||
->get()
|
->get()
|
||||||
->map(function($s) use($user) {
|
->map(function($s) use($user) {
|
||||||
try {
|
try {
|
||||||
$status = StatusService::get($s->id, false);
|
$status = StatusService::getMastodon($s->id, false);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
$status = false;
|
$status = false;
|
||||||
}
|
}
|
||||||
|
@ -968,7 +962,7 @@ class ApiV1Controller extends Controller
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get()
|
->get()
|
||||||
->map(function($like) {
|
->map(function($like) {
|
||||||
$status = StatusService::get($like['status_id'], false);
|
$status = StatusService::getMastodon($like['status_id'], false);
|
||||||
$status['like_id'] = $like->id;
|
$status['like_id'] = $like->id;
|
||||||
$status['liked_at'] = $like->created_at->format('c');
|
$status['liked_at'] = $like->created_at->format('c');
|
||||||
return $status;
|
return $status;
|
||||||
|
@ -1731,7 +1725,7 @@ class ApiV1Controller extends Controller
|
||||||
'id' => $dm->id,
|
'id' => $dm->id,
|
||||||
'unread' => false,
|
'unread' => false,
|
||||||
'accounts' => [
|
'accounts' => [
|
||||||
AccountService::get($from)
|
AccountService::getMastodon($from)
|
||||||
],
|
],
|
||||||
'last_status' => StatusService::getDirectMessage($dm->status_id)
|
'last_status' => StatusService::getDirectMessage($dm->status_id)
|
||||||
];
|
];
|
||||||
|
@ -1784,7 +1778,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$res = collect($feed)
|
$res = collect($feed)
|
||||||
->map(function($k) use($user) {
|
->map(function($k) use($user) {
|
||||||
$status = StatusService::get($k);
|
$status = StatusService::getMastodon($k);
|
||||||
if($user) {
|
if($user) {
|
||||||
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
|
||||||
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
|
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
|
||||||
|
@ -1811,7 +1805,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$user = $request->user();
|
$user = $request->user();
|
||||||
|
|
||||||
$res = StatusService::get($id, false);
|
$res = StatusService::getMastodon($id, false);
|
||||||
if(!$res || !isset($res['visibility'])) {
|
if(!$res || !isset($res['visibility'])) {
|
||||||
abort(404);
|
abort(404);
|
||||||
}
|
}
|
||||||
|
@ -2000,7 +1994,7 @@ class ApiV1Controller extends Controller
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->get()
|
->get()
|
||||||
->map(function($like) {
|
->map(function($like) {
|
||||||
$account = AccountService::get($like->profile_id);
|
$account = AccountService::getMastodon($like->profile_id);
|
||||||
$account['follows'] = isset($like->created_at);
|
$account['follows'] = isset($like->created_at);
|
||||||
return $account;
|
return $account;
|
||||||
})
|
})
|
||||||
|
@ -2314,10 +2308,10 @@ class ApiV1Controller extends Controller
|
||||||
->limit($limit)
|
->limit($limit)
|
||||||
->pluck('status_id')
|
->pluck('status_id')
|
||||||
->filter(function($i) {
|
->filter(function($i) {
|
||||||
return StatusService::get($i);
|
return StatusService::getMastodon($i);
|
||||||
})
|
})
|
||||||
->map(function ($i) {
|
->map(function ($i) {
|
||||||
return StatusService::get($i);
|
return StatusService::getMastodon($i);
|
||||||
})
|
})
|
||||||
->filter()
|
->filter()
|
||||||
->values()
|
->values()
|
||||||
|
@ -2367,7 +2361,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$res = [];
|
$res = [];
|
||||||
foreach($bookmarks as $id) {
|
foreach($bookmarks as $id) {
|
||||||
$res[] = \App\Services\StatusService::get($id);
|
$res[] = \App\Services\StatusService::getMastodon($id);
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
@ -2470,7 +2464,7 @@ class ApiV1Controller extends Controller
|
||||||
$filters = UserFilterService::filters($pid);
|
$filters = UserFilterService::filters($pid);
|
||||||
$forYou = DiscoverService::getForYou();
|
$forYou = DiscoverService::getForYou();
|
||||||
$posts = $forYou->take(50)->map(function($post) {
|
$posts = $forYou->take(50)->map(function($post) {
|
||||||
return StatusService::get($post);
|
return StatusService::getMastodon($post);
|
||||||
})
|
})
|
||||||
->filter(function($post) use($filters) {
|
->filter(function($post) use($filters) {
|
||||||
return $post &&
|
return $post &&
|
||||||
|
@ -2500,7 +2494,7 @@ class ApiV1Controller extends Controller
|
||||||
|
|
||||||
$limit = $request->input('limit', 3);
|
$limit = $request->input('limit', 3);
|
||||||
$pid = $request->user()->profile_id;
|
$pid = $request->user()->profile_id;
|
||||||
$status = StatusService::get($id);
|
$status = StatusService::getMastodon($id);
|
||||||
|
|
||||||
abort_if(!$status || !in_array($status['visibility'], ['public', 'unlisted']), 404);
|
abort_if(!$status || !in_array($status['visibility'], ['public', 'unlisted']), 404);
|
||||||
|
|
||||||
|
@ -2533,7 +2527,7 @@ class ApiV1Controller extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
$data = $ids->map(function($post) use($pid) {
|
$data = $ids->map(function($post) use($pid) {
|
||||||
$status = StatusService::get($post->id);
|
$status = StatusService::getMastodon($post->id);
|
||||||
|
|
||||||
if(!$status || !isset($status['id'])) {
|
if(!$status || !isset($status['id'])) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -2591,7 +2585,7 @@ class ApiV1Controller extends Controller
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
$ids = $ids->map(function($profile) {
|
$ids = $ids->map(function($profile) {
|
||||||
return AccountService::get($profile->id);
|
return AccountService::getMastodon($profile->id);
|
||||||
})
|
})
|
||||||
->filter(function($profile) use($pid) {
|
->filter(function($profile) use($pid) {
|
||||||
return $profile &&
|
return $profile &&
|
||||||
|
|
|
@ -40,6 +40,10 @@ class AccountService
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config('exp.emc') == false) {
|
||||||
|
return $account;
|
||||||
|
}
|
||||||
|
|
||||||
unset(
|
unset(
|
||||||
$account['header_bg'],
|
$account['header_bg'],
|
||||||
$account['is_admin'],
|
$account['is_admin'],
|
||||||
|
|
|
@ -46,6 +46,11 @@ class StatusService
|
||||||
if(!$status) {
|
if(!$status) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(config('exp.emc') == false) {
|
||||||
|
return $status;
|
||||||
|
}
|
||||||
|
|
||||||
$status['replies_count'] = $status['reply_count'];
|
$status['replies_count'] = $status['reply_count'];
|
||||||
unset(
|
unset(
|
||||||
$status['_v'],
|
$status['_v'],
|
||||||
|
|
|
@ -1,13 +1,37 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
return [
|
/*
|
||||||
|
* Experimental configuration options
|
||||||
|
*
|
||||||
|
* (Use at your own risk)
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
// Hidden like counts (deprecated)
|
||||||
'lc' => env('EXP_LC', false),
|
'lc' => env('EXP_LC', false),
|
||||||
|
|
||||||
|
// Recommendations (deprecated)
|
||||||
'rec' => false,
|
'rec' => false,
|
||||||
|
|
||||||
|
// Loops feature (deprecated)
|
||||||
'loops' => false,
|
'loops' => false,
|
||||||
|
|
||||||
|
// Text only posts (alpha)
|
||||||
'top' => env('EXP_TOP', false),
|
'top' => env('EXP_TOP', false),
|
||||||
|
|
||||||
|
// Poll statuses (alpha)
|
||||||
'polls' => env('EXP_POLLS', false),
|
'polls' => env('EXP_POLLS', false),
|
||||||
|
|
||||||
|
// Cached public timeline for larger instances (beta)
|
||||||
'cached_public_timeline' => env('EXP_CPT', false),
|
'cached_public_timeline' => env('EXP_CPT', false),
|
||||||
|
|
||||||
|
// Groups (unreleased)
|
||||||
'gps' => env('EXP_GPS', false),
|
'gps' => env('EXP_GPS', false),
|
||||||
|
|
||||||
|
// Single page application (beta)
|
||||||
'spa' => true,
|
'spa' => true,
|
||||||
|
|
||||||
|
// Enforce Mastoapi Compatibility (alpha)
|
||||||
|
// Note: this may break 3rd party apps who use non-mastodon compliant fields
|
||||||
|
'emc' => env('EXP_EMC', false),
|
||||||
];
|
];
|
||||||
|
|
Loading…
Reference in a new issue