Update pixelfed.max_album_length, use config_cache

This commit is contained in:
Daniel Supernault 2024-03-12 01:20:24 -06:00
parent 665581d80c
commit fecbe1897b
No known key found for this signature in database
GPG key ID: 23740873EE6F76A1
2 changed files with 36 additions and 35 deletions

View file

@ -1665,7 +1665,7 @@ class ApiV1Controller extends Controller
'statuses' => [
'characters_reserved_per_url' => 23,
'max_characters' => (int) config_cache('pixelfed.max_caption_length'),
'max_media_attachments' => (int) config('pixelfed.max_album_length'),
'max_media_attachments' => (int) config_cache('pixelfed.max_album_length'),
],
],
];
@ -3308,9 +3308,9 @@ class ApiV1Controller extends Controller
abort_unless($request->user()->tokenCan('write'), 403);
$this->validate($request, [
'status' => 'nullable|string|max:' . config_cache('pixelfed.max_caption_length'),
'status' => 'nullable|string|max:'.(int) config_cache('pixelfed.max_caption_length'),
'in_reply_to_id' => 'nullable',
'media_ids' => 'sometimes|array|max:'.config_cache('pixelfed.max_album_length'),
'media_ids' => 'sometimes|array|max:'.(int) config_cache('pixelfed.max_album_length'),
'sensitive' => 'nullable',
'visibility' => 'string|in:private,unlisted,public',
'spoiler_text' => 'sometimes|max:140',
@ -3436,7 +3436,7 @@ class ApiV1Controller extends Controller
$mimes = [];
foreach ($ids as $k => $v) {
if ($k + 1 > config_cache('pixelfed.max_album_length')) {
if ($k + 1 > (int) config_cache('pixelfed.max_album_length')) {
continue;
}
$m = Media::whereUserId($user->id)->whereNull('status_id')->findOrFail($v);

View file

@ -2,10 +2,10 @@
namespace App\Http\Requests\Status;
use Illuminate\Foundation\Http\FormRequest;
use App\Media;
use App\Status;
use Closure;
use Illuminate\Foundation\Http\FormRequest;
class StoreStatusEditRequest extends FormRequest
{
@ -15,23 +15,24 @@ class StoreStatusEditRequest extends FormRequest
public function authorize(): bool
{
$profile = $this->user()->profile;
if($profile->status != null) {
if ($profile->status != null) {
return false;
}
if($profile->unlisted == true && $profile->cw == true) {
if ($profile->unlisted == true && $profile->cw == true) {
return false;
}
$types = [
"photo",
"photo:album",
"photo:video:album",
"reply",
"text",
"video",
"video:album"
'photo',
'photo:album',
'photo:video:album',
'reply',
'text',
'video',
'video:album',
];
$scopes = ['public', 'unlisted', 'private'];
$status = Status::whereNull('reblog_of_id')->whereIn('type', $types)->whereIn('scope', $scopes)->find($this->route('id'));
return $status && $this->user()->profile_id === $status->profile_id;
}
@ -50,10 +51,10 @@ class StoreStatusEditRequest extends FormRequest
'nullable',
'required_without:status',
'array',
'max:' . config('pixelfed.max_album_length'),
'max:'.(int) config_cache('pixelfed.max_album_length'),
function (string $attribute, mixed $value, Closure $fail) {
Media::whereProfileId($this->user()->profile_id)
->where(function($query) {
->where(function ($query) {
return $query->whereNull('status_id')
->orWhere('status_id', '=', $this->route('id'));
})