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_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();

View File

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

View File

@ -278,4 +278,6 @@ return [
|
*/
'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">
<img :src="m.preview_url" class="mr-3" width="50px" height="50px">
<div class="media-body">
<textarea class="form-control" v-model="m.alt" placeholder="Add a media description here..." maxlength="140"></textarea>
<p class="help-text small text-right text-muted mb-0">{{m.alt ? m.alt.length : 0}}/140</p>
<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}}/{{maxAltTextLength}}</p>
</div>
</div>
<hr>
@ -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;