1
0
Fork 0
forked from mirror/pixelfed

Update ApiV1Controller, add mastoapi strict mode

This commit is contained in:
Daniel Supernault 2022-01-05 21:36:02 -07:00
parent 1f70e248ff
commit 46485426ea
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
4 changed files with 59 additions and 32 deletions

View file

@ -64,7 +64,6 @@ use App\Services\{
NotificationService,
MediaPathService,
PublicTimelineService,
ProfileService,
RelationshipService,
SearchApiV2Service,
StatusService,
@ -142,7 +141,7 @@ class ApiV1Controller extends Controller
$id = $request->user()->profile_id;
$res = ProfileService::get($id);
$res = AccountService::getMastodon($id);
$res['source'] = [
'privacy' => $res['locked'] ? 'private' : 'public',
@ -164,10 +163,10 @@ class ApiV1Controller extends Controller
*/
public function accountById(Request $request, $id)
{
$profile = Profile::whereNull('status')->findOrFail($id);
$resource = new Fractal\Resource\Item($profile, new AccountTransformer());
$res = $this->fractal->createData($resource)->toArray();
$res = AccountService::getMastodon($id, true);
if(!$res) {
return response()->json(['error' => 'Record not found'], 404);
}
return response()->json($res);
}
@ -394,7 +393,7 @@ class ApiV1Controller extends Controller
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 = array_merge($res, $other);
@ -508,7 +507,7 @@ class ApiV1Controller extends Controller
'limit' => 'nullable|integer|min:1|max:80'
]);
$profile = AccountService::get($id);
$profile = AccountService::getMastodon($id);
abort_if(!$profile, 404);
$limit = $request->limit ?? 20;
@ -534,17 +533,12 @@ class ApiV1Controller extends Controller
if($pid == $profile['id']) {
$visibility = ['public', 'unlisted', 'private'];
} else if($profile['locked']) {
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
$following = Follower::whereProfileId($pid)->pluck('following_id');
return $following->push($pid)->toArray();
});
$visibility = true == in_array($profile['id'], $following) ? ['public', 'unlisted', 'private'] : [];
$following = FollowerService::follows($pid, $profile['id']);
abort_unless($following, 403);
$visibility = ['public', 'unlisted', 'private'];
} else {
$following = Cache::remember('profile:following:'.$pid, now()->addMinutes(1440), function() use($pid) {
$following = Follower::whereProfileId($pid)->pluck('following_id');
return $following->push($pid)->toArray();
});
$visibility = true == in_array($profile['id'], $following) ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
$following = FollowerService::follows($pid, $profile['id']);
$visibility = $following ? ['public', 'unlisted', 'private'] : ['public', 'unlisted'];
}
$dir = $min_id ? '>' : '<';
@ -560,7 +554,7 @@ class ApiV1Controller extends Controller
->get()
->map(function($s) use($user) {
try {
$status = StatusService::get($s->id, false);
$status = StatusService::getMastodon($s->id, false);
} catch (\Exception $e) {
$status = false;
}
@ -968,7 +962,7 @@ class ApiV1Controller extends Controller
->limit($limit)
->get()
->map(function($like) {
$status = StatusService::get($like['status_id'], false);
$status = StatusService::getMastodon($like['status_id'], false);
$status['like_id'] = $like->id;
$status['liked_at'] = $like->created_at->format('c');
return $status;
@ -1731,7 +1725,7 @@ class ApiV1Controller extends Controller
'id' => $dm->id,
'unread' => false,
'accounts' => [
AccountService::get($from)
AccountService::getMastodon($from)
],
'last_status' => StatusService::getDirectMessage($dm->status_id)
];
@ -1784,7 +1778,7 @@ class ApiV1Controller extends Controller
$res = collect($feed)
->map(function($k) use($user) {
$status = StatusService::get($k);
$status = StatusService::getMastodon($k);
if($user) {
$status['favourited'] = (bool) LikeService::liked($user->profile_id, $k);
$status['relationship'] = RelationshipService::get($user->profile_id, $status['account']['id']);
@ -1811,7 +1805,7 @@ class ApiV1Controller extends Controller
$user = $request->user();
$res = StatusService::get($id, false);
$res = StatusService::getMastodon($id, false);
if(!$res || !isset($res['visibility'])) {
abort(404);
}
@ -2000,7 +1994,7 @@ class ApiV1Controller extends Controller
->limit($limit)
->get()
->map(function($like) {
$account = AccountService::get($like->profile_id);
$account = AccountService::getMastodon($like->profile_id);
$account['follows'] = isset($like->created_at);
return $account;
})
@ -2314,10 +2308,10 @@ class ApiV1Controller extends Controller
->limit($limit)
->pluck('status_id')
->filter(function($i) {
return StatusService::get($i);
return StatusService::getMastodon($i);
})
->map(function ($i) {
return StatusService::get($i);
return StatusService::getMastodon($i);
})
->filter()
->values()
@ -2367,7 +2361,7 @@ class ApiV1Controller extends Controller
$res = [];
foreach($bookmarks as $id) {
$res[] = \App\Services\StatusService::get($id);
$res[] = \App\Services\StatusService::getMastodon($id);
}
return $res;
}
@ -2470,7 +2464,7 @@ class ApiV1Controller extends Controller
$filters = UserFilterService::filters($pid);
$forYou = DiscoverService::getForYou();
$posts = $forYou->take(50)->map(function($post) {
return StatusService::get($post);
return StatusService::getMastodon($post);
})
->filter(function($post) use($filters) {
return $post &&
@ -2500,7 +2494,7 @@ class ApiV1Controller extends Controller
$limit = $request->input('limit', 3);
$pid = $request->user()->profile_id;
$status = StatusService::get($id);
$status = StatusService::getMastodon($id);
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) {
$status = StatusService::get($post->id);
$status = StatusService::getMastodon($post->id);
if(!$status || !isset($status['id'])) {
return false;
@ -2591,7 +2585,7 @@ class ApiV1Controller extends Controller
->get();
$ids = $ids->map(function($profile) {
return AccountService::get($profile->id);
return AccountService::getMastodon($profile->id);
})
->filter(function($profile) use($pid) {
return $profile &&

View file

@ -40,6 +40,10 @@ class AccountService
return null;
}
if(config('exp.emc') == false) {
return $account;
}
unset(
$account['header_bg'],
$account['is_admin'],

View file

@ -46,6 +46,11 @@ class StatusService
if(!$status) {
return null;
}
if(config('exp.emc') == false) {
return $status;
}
$status['replies_count'] = $status['reply_count'];
unset(
$status['_v'],

View file

@ -1,13 +1,37 @@
<?php
return [
/*
* Experimental configuration options
*
* (Use at your own risk)
*/
return [
// Hidden like counts (deprecated)
'lc' => env('EXP_LC', false),
// Recommendations (deprecated)
'rec' => false,
// Loops feature (deprecated)
'loops' => false,
// Text only posts (alpha)
'top' => env('EXP_TOP', false),
// Poll statuses (alpha)
'polls' => env('EXP_POLLS', false),
// Cached public timeline for larger instances (beta)
'cached_public_timeline' => env('EXP_CPT', false),
// Groups (unreleased)
'gps' => env('EXP_GPS', false),
// Single page application (beta)
'spa' => true,
// Enforce Mastoapi Compatibility (alpha)
// Note: this may break 3rd party apps who use non-mastodon compliant fields
'emc' => env('EXP_EMC', false),
];