diff --git a/app/Http/Controllers/Api/ApiV1Controller.php b/app/Http/Controllers/Api/ApiV1Controller.php index 5c9f95442..801f96f9c 100644 --- a/app/Http/Controllers/Api/ApiV1Controller.php +++ b/app/Http/Controllers/Api/ApiV1Controller.php @@ -1048,7 +1048,7 @@ class ApiV1Controller extends Controller }, 'filter_name' => 'nullable|string|max:24', 'filter_class' => 'nullable|alpha_dash|max:24', - 'description' => 'nullable|string|max:420' + 'description' => 'nullable|string|max:' . config_cache('pixelfed.max_altext_length') ]); $user = $request->user(); @@ -1140,7 +1140,7 @@ class ApiV1Controller extends Controller abort_if(!$request->user(), 403); $this->validate($request, [ - 'description' => 'nullable|string|max:420' + 'description' => 'nullable|string|max:' . config_cache('pixelfed.max_altext_length') ]); $user = $request->user(); diff --git a/app/Http/Controllers/ComposeController.php b/app/Http/Controllers/ComposeController.php index 56e137441..50e8bf5fa 100644 --- a/app/Http/Controllers/ComposeController.php +++ b/app/Http/Controllers/ComposeController.php @@ -404,7 +404,7 @@ class ComposeController extends Controller 'media.*.id' => 'required|integer|min:1', 'media.*.filter_class' => 'nullable|alpha_dash|max:30', 'media.*.license' => 'nullable|string|max:140', - 'media.*.alt' => 'nullable|string|max:140', + 'media.*.alt' => 'nullable|string|max:'.config_cache('pixelfed.max_altext_length'), 'cw' => 'nullable|boolean', 'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10', 'place' => 'nullable', @@ -666,21 +666,20 @@ class ComposeController extends Controller public function composeSettings(Request $request) { $uid = $request->user()->id; + $default = [ + 'default_license' => 1, + 'media_descriptions' => false, + 'max_altext_length' => config_cache('pixelfed.max_altext_length') + ]; - return Cache::remember('profile:compose:settings:' . $uid, now()->addHours(12), function() use($uid) { + return array_merge($default, Cache::remember('profile:compose:settings:' . $uid, now()->addHours(12), function() use($uid) { $res = UserSetting::whereUserId($uid)->first(); - if(!$res) { - return [ - 'default_license' => null, - 'media_descriptions' => false - ]; + if(!$res || empty($res->compose_settings)) { + return []; } - return json_decode($res->compose_settings, true) ?? [ - 'default_license' => null, - 'media_descriptions' => false - ]; - }); + return json_decode($res->compose_settings, true); + })); } } diff --git a/config/pixelfed.php b/config/pixelfed.php index 0fd26b334..e3cfe2495 100644 --- a/config/pixelfed.php +++ b/config/pixelfed.php @@ -278,4 +278,6 @@ return [ | */ 'media_fast_process' => env('PF_MEDIA_FAST_PROCESS', true), + + 'max_altext_length' => env('PF_MEDIA_MAX_ALTTEXT_LENGTH', 1000), ]; diff --git a/resources/assets/js/components/ComposeModal.vue b/resources/assets/js/components/ComposeModal.vue index 893bacf92..0171d236c 100644 --- a/resources/assets/js/components/ComposeModal.vue +++ b/resources/assets/js/components/ComposeModal.vue @@ -536,8 +536,8 @@
- -

{{m.alt ? m.alt.length : 0}}/140

+ +

{{m.alt ? m.alt.length : 0}}/{{maxAltTextLength}}


@@ -904,8 +904,9 @@ export default { default_license: null, media_descriptions: false }, - licenseId: null, - licenseTitle: null + licenseId: 1, + licenseTitle: null, + maxAltTextLength: 140 } }, @@ -916,6 +917,7 @@ export default { .then(res => { this.composeSettings = res.data; this.licenseId = this.composeSettings.default_license; + this.maxAltTextLength = res.data.max_altext_length; if(this.licenseId > 10) { this.licenseTitle = this.availableLicenses.filter(l => { return l.id == this.licenseId;