Update PixelfedDirectoryController, fix boolean cast bug

This commit is contained in:
Daniel Supernault 2024-03-11 23:43:23 -06:00
parent 8a0c456edc
commit f08aab2231
No known key found for this signature in database
GPG Key ID: 23740873EE6F76A1
1 changed files with 41 additions and 40 deletions

View File

@ -2,12 +2,12 @@
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\ConfigCache;
use Storage;
use App\Services\AccountService;
use App\Services\StatusService;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Storage;
class PixelfedDirectoryController extends Controller
{
@ -26,6 +26,7 @@ class PixelfedDirectoryController extends Controller
}
$res = $this->buildListing();
return response()->json($res, 200, [], JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
@ -67,7 +68,7 @@ class PixelfedDirectoryController extends Controller
'display_name' => $post['account']['display_name'],
'username' => $post['account']['username'],
'media' => $post['media_attachments'][0]['url'],
'url' => $post['url']
'url' => $post['url'],
];
})
->values();
@ -98,14 +99,14 @@ class PixelfedDirectoryController extends Controller
$res['feature_config'] = [
'media_types' => Str::of(config_cache('pixelfed.media_types'))->explode(','),
'image_quality' => config_cache('pixelfed.image_quality'),
'optimize_image' => config_cache('pixelfed.optimize_image'),
'optimize_image' => (bool) config_cache('pixelfed.optimize_image'),
'max_photo_size' => config_cache('pixelfed.max_photo_size'),
'max_caption_length' => config_cache('pixelfed.max_caption_length'),
'max_altext_length' => config_cache('pixelfed.max_altext_length'),
'enforce_account_limit' => config_cache('pixelfed.enforce_account_limit'),
'enforce_account_limit' => (bool) config_cache('pixelfed.enforce_account_limit'),
'max_account_size' => config_cache('pixelfed.max_account_size'),
'max_album_length' => config_cache('pixelfed.max_album_length'),
'account_deletion' => config_cache('pixelfed.account_deletion'),
'account_deletion' => (bool) config_cache('pixelfed.account_deletion'),
];
$res['is_eligible'] = $this->validVal($res, 'admin') &&
@ -119,20 +120,21 @@ class PixelfedDirectoryController extends Controller
$res['testimonials'] = collect(json_decode(config_cache('pixelfed.directory.testimonials'), true))
->map(function ($testimonial) {
$profile = AccountService::get($testimonial['profile_id']);
return [
'profile' => [
'username' => $profile['username'],
'display_name' => $profile['display_name'],
'avatar' => $profile['avatar'],
'created_at' => $profile['created_at']
'created_at' => $profile['created_at'],
],
'body' => $testimonial['body']
'body' => $testimonial['body'],
];
});
}
$res['features_enabled'] = [
'stories' => (bool) config_cache('instance.stories.enabled')
'stories' => (bool) config_cache('instance.stories.enabled'),
];
$res['stats'] = [
@ -164,5 +166,4 @@ class PixelfedDirectoryController extends Controller
return $res[$val];
}
}