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

View file

@ -2,10 +2,10 @@
namespace App\Http\Requests\Status; namespace App\Http\Requests\Status;
use Illuminate\Foundation\Http\FormRequest;
use App\Media; use App\Media;
use App\Status; use App\Status;
use Closure; use Closure;
use Illuminate\Foundation\Http\FormRequest;
class StoreStatusEditRequest extends FormRequest class StoreStatusEditRequest extends FormRequest
{ {
@ -22,16 +22,17 @@ class StoreStatusEditRequest extends FormRequest
return false; return false;
} }
$types = [ $types = [
"photo", 'photo',
"photo:album", 'photo:album',
"photo:video:album", 'photo:video:album',
"reply", 'reply',
"text", 'text',
"video", 'video',
"video:album" 'video:album',
]; ];
$scopes = ['public', 'unlisted', 'private']; $scopes = ['public', 'unlisted', 'private'];
$status = Status::whereNull('reblog_of_id')->whereIn('type', $types)->whereIn('scope', $scopes)->find($this->route('id')); $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; return $status && $this->user()->profile_id === $status->profile_id;
} }
@ -50,7 +51,7 @@ class StoreStatusEditRequest extends FormRequest
'nullable', 'nullable',
'required_without:status', 'required_without:status',
'array', 'array',
'max:' . config('pixelfed.max_album_length'), 'max:'.(int) config_cache('pixelfed.max_album_length'),
function (string $attribute, mixed $value, Closure $fail) { function (string $attribute, mixed $value, Closure $fail) {
Media::whereProfileId($this->user()->profile_id) Media::whereProfileId($this->user()->profile_id)
->where(function ($query) { ->where(function ($query) {