Update AP Helpers, fix media validation bug that would reject media with alttext/name longer than 255 chars and store remote alt text if set

This commit is contained in:
Daniel Supernault 2023-01-31 03:37:32 -07:00
parent 016c6e4144
commit a7f583497c
No known key found for this signature in database
GPG Key ID: 0DEF1C662C9033F7
1 changed files with 6 additions and 4 deletions

View File

@ -101,13 +101,13 @@ class Helpers {
'string',
Rule::in($mediaTypes)
],
'*.url' => 'required|url|max:255',
'*.url' => 'required|url',
'*.mediaType' => [
'required',
'string',
Rule::in($mimeTypes)
],
'*.name' => 'sometimes|nullable|string|max:255'
'*.name' => 'sometimes|nullable|string'
])->passes();
return $valid;
@ -665,12 +665,13 @@ class Helpers {
foreach($attachments as $media) {
$type = $media['mediaType'];
$url = $media['url'];
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
$valid = self::validateUrl($url);
if(in_array($type, $allowed) == false || $valid == false) {
continue;
}
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
$caption = $media['name'] ? Purify::clean($media['name']) : null;
$media = new Media();
$media->blurhash = $blurhash;
@ -680,6 +681,7 @@ class Helpers {
$media->user_id = null;
$media->media_path = $url;
$media->remote_url = $url;
$media->caption = $caption;
if($license) {
$media->license = $license;
}