Update pixelfed.max_album_length, use config_cache

pull/5005/head
Daniel Supernault 2024-03-12 01:20:24 -06:00
rodzic 665581d80c
commit fecbe1897b
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 23740873EE6F76A1
2 zmienionych plików z 36 dodań i 35 usunięć

Wyświetl plik

@ -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);

Wyświetl plik

@ -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
{ {
@ -14,24 +14,25 @@ class StoreStatusEditRequest extends FormRequest
*/ */
public function authorize(): bool public function authorize(): bool
{ {
$profile = $this->user()->profile; $profile = $this->user()->profile;
if($profile->status != null) { if ($profile->status != null) {
return false; return false;
} }
if($profile->unlisted == true && $profile->cw == true) { if ($profile->unlisted == true && $profile->cw == true) {
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;
} }
@ -47,18 +48,18 @@ class StoreStatusEditRequest extends FormRequest
'spoiler_text' => 'nullable|string|max:140', 'spoiler_text' => 'nullable|string|max:140',
'sensitive' => 'sometimes|boolean', 'sensitive' => 'sometimes|boolean',
'media_ids' => [ 'media_ids' => [
'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) {
return $query->whereNull('status_id') return $query->whereNull('status_id')
->orWhere('status_id', '=', $this->route('id')); ->orWhere('status_id', '=', $this->route('id'));
}) })
->findOrFail($value); ->findOrFail($value);
}, },
], ],
'location' => 'sometimes|nullable', 'location' => 'sometimes|nullable',
'location.id' => 'sometimes|integer|min:1|max:128769', 'location.id' => 'sometimes|integer|min:1|max:128769',