Skip to content

Commit a7f5834

Browse files
committed
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
1 parent 016c6e4 commit a7f5834

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

app/Util/ActivityPub/Helpers.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,13 @@ public static function verifyAttachments($data)
101101
'string',
102102
Rule::in($mediaTypes)
103103
],
104-
'*.url' => 'required|url|max:255',
104+
'*.url' => 'required|url',
105105
'*.mediaType' => [
106106
'required',
107107
'string',
108108
Rule::in($mimeTypes)
109109
],
110-
'*.name' => 'sometimes|nullable|string|max:255'
110+
'*.name' => 'sometimes|nullable|string'
111111
])->passes();
112112

113113
return $valid;
@@ -665,12 +665,13 @@ public static function importNoteAttachment($data, Status $status)
665665
foreach($attachments as $media) {
666666
$type = $media['mediaType'];
667667
$url = $media['url'];
668-
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
669-
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
670668
$valid = self::validateUrl($url);
671669
if(in_array($type, $allowed) == false || $valid == false) {
672670
continue;
673671
}
672+
$blurhash = isset($media['blurhash']) ? $media['blurhash'] : null;
673+
$license = isset($media['license']) ? License::nameToId($media['license']) : null;
674+
$caption = $media['name'] ? Purify::clean($media['name']) : null;
674675

675676
$media = new Media();
676677
$media->blurhash = $blurhash;
@@ -680,6 +681,7 @@ public static function importNoteAttachment($data, Status $status)
680681
$media->user_id = null;
681682
$media->media_path = $url;
682683
$media->remote_url = $url;
684+
$media->caption = $caption;
683685
if($license) {
684686
$media->license = $license;
685687
}

0 commit comments

Comments
 (0)