Update Compose Apis, make media descriptions/alt text length limit configurable. Default length: 1000

This commit is contained in:
Daniel Supernault 2021-07-24 21:15:15 -06:00
parent 67e3f6048f
commit 072d55d1a8
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
4 changed files with 21 additions and 18 deletions

View file

@ -1048,7 +1048,7 @@ class ApiV1Controller extends Controller
}, },
'filter_name' => 'nullable|string|max:24', 'filter_name' => 'nullable|string|max:24',
'filter_class' => 'nullable|alpha_dash|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(); $user = $request->user();
@ -1140,7 +1140,7 @@ class ApiV1Controller extends Controller
abort_if(!$request->user(), 403); abort_if(!$request->user(), 403);
$this->validate($request, [ $this->validate($request, [
'description' => 'nullable|string|max:420' 'description' => 'nullable|string|max:' . config_cache('pixelfed.max_altext_length')
]); ]);
$user = $request->user(); $user = $request->user();

View file

@ -404,7 +404,7 @@ class ComposeController extends Controller
'media.*.id' => 'required|integer|min:1', 'media.*.id' => 'required|integer|min:1',
'media.*.filter_class' => 'nullable|alpha_dash|max:30', 'media.*.filter_class' => 'nullable|alpha_dash|max:30',
'media.*.license' => 'nullable|string|max:140', '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', 'cw' => 'nullable|boolean',
'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10', 'visibility' => 'required|string|in:public,private,unlisted|min:2|max:10',
'place' => 'nullable', 'place' => 'nullable',
@ -666,21 +666,20 @@ class ComposeController extends Controller
public function composeSettings(Request $request) public function composeSettings(Request $request)
{ {
$uid = $request->user()->id; $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(); $res = UserSetting::whereUserId($uid)->first();
if(!$res) { if(!$res || empty($res->compose_settings)) {
return [ return [];
'default_license' => null,
'media_descriptions' => false
];
} }
return json_decode($res->compose_settings, true) ?? [ return json_decode($res->compose_settings, true);
'default_license' => null, }));
'media_descriptions' => false
];
});
} }
} }

View file

@ -278,4 +278,6 @@ return [
| |
*/ */
'media_fast_process' => env('PF_MEDIA_FAST_PROCESS', true), 'media_fast_process' => env('PF_MEDIA_FAST_PROCESS', true),
'max_altext_length' => env('PF_MEDIA_MAX_ALTTEXT_LENGTH', 1000),
]; ];

View file

@ -536,8 +536,8 @@
<div class="media"> <div class="media">
<img :src="m.preview_url" class="mr-3" width="50px" height="50px"> <img :src="m.preview_url" class="mr-3" width="50px" height="50px">
<div class="media-body"> <div class="media-body">
<textarea class="form-control" v-model="m.alt" placeholder="Add a media description here..." maxlength="140"></textarea> <textarea class="form-control" v-model="m.alt" placeholder="Add a media description here..." :maxlength="maxAltTextLength" rows="4"></textarea>
<p class="help-text small text-right text-muted mb-0">{{m.alt ? m.alt.length : 0}}/140</p> <p class="help-text small text-right text-muted mb-0">{{m.alt ? m.alt.length : 0}}/{{maxAltTextLength}}</p>
</div> </div>
</div> </div>
<hr> <hr>
@ -904,8 +904,9 @@ export default {
default_license: null, default_license: null,
media_descriptions: false media_descriptions: false
}, },
licenseId: null, licenseId: 1,
licenseTitle: null licenseTitle: null,
maxAltTextLength: 140
} }
}, },
@ -916,6 +917,7 @@ export default {
.then(res => { .then(res => {
this.composeSettings = res.data; this.composeSettings = res.data;
this.licenseId = this.composeSettings.default_license; this.licenseId = this.composeSettings.default_license;
this.maxAltTextLength = res.data.max_altext_length;
if(this.licenseId > 10) { if(this.licenseId > 10) {
this.licenseTitle = this.availableLicenses.filter(l => { this.licenseTitle = this.availableLicenses.filter(l => {
return l.id == this.licenseId; return l.id == this.licenseId;