|
140 | 140 | require_relative "app/serializers/discourse_activity_pub/ap/actor/person_serializer"
|
141 | 141 | require_relative "app/serializers/discourse_activity_pub/ap/object/note_serializer"
|
142 | 142 | require_relative "app/serializers/discourse_activity_pub/ap/object/article_serializer"
|
| 143 | + require_relative "app/serializers/discourse_activity_pub/ap/object/image_serializer" |
| 144 | + require_relative "app/serializers/discourse_activity_pub/ap/object/document_serializer" |
143 | 145 | require_relative "app/serializers/discourse_activity_pub/ap/collection_serializer"
|
144 | 146 | require_relative "app/serializers/discourse_activity_pub/ap/collection/ordered_collection_serializer"
|
145 | 147 | require_relative "app/serializers/discourse_activity_pub/about_serializer"
|
|
1185 | 1187 | )
|
1186 | 1188 | end
|
1187 | 1189 |
|
1188 |
| - if object.attachment.present? |
1189 |
| - object.attachment.each do |attachment| |
1190 |
| - # Some platforms (e.g. Mastodon) put attachment url media types on the attachment itself, |
1191 |
| - # instead of on a Link object in the url attribute. Technically this violates the specification, |
1192 |
| - # but we need to support it nevertheless. See further https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mediatype |
1193 |
| - media_type = attachment.url.media_type || attachment.media_type |
1194 |
| - name = attachment.url.name || attachment.name |
1195 |
| - |
1196 |
| - begin |
1197 |
| - DiscourseActivityPubAttachment.create( |
1198 |
| - object_id: object.stored.id, |
1199 |
| - object_type: "DiscourseActivityPubObject", |
1200 |
| - ap_type: attachment.type, |
1201 |
| - url: attachment.url.href, |
1202 |
| - name: name, |
1203 |
| - media_type: media_type, |
1204 |
| - ) |
1205 |
| - rescue ActiveRecord::RecordInvalid => error |
1206 |
| - # fail silently if an attachment does not validate |
| 1190 | + if object.json[:attachment].present? |
| 1191 | + object.json[:attachment].each do |json| |
| 1192 | + attachment = DiscourseActivityPub::AP::Object.factory(json) |
| 1193 | + if attachment |
| 1194 | + # Some platforms (e.g. Mastodon) put attachment url media types on the attachment itself, |
| 1195 | + # instead of on a Link object in the url attribute. Technically this violates the specification, |
| 1196 | + # but we need to support it nevertheless. See further https://www.w3.org/TR/activitystreams-vocabulary/#dfn-mediatype |
| 1197 | + media_type = attachment.url.media_type || attachment.media_type |
| 1198 | + name = attachment.url.name || attachment.name |
| 1199 | + |
| 1200 | + begin |
| 1201 | + DiscourseActivityPubAttachment.create( |
| 1202 | + object_id: object.stored.id, |
| 1203 | + object_type: "DiscourseActivityPubObject", |
| 1204 | + ap_type: attachment.type, |
| 1205 | + url: attachment.url.href, |
| 1206 | + name: name, |
| 1207 | + media_type: media_type, |
| 1208 | + ) |
| 1209 | + rescue ActiveRecord::RecordInvalid => error |
| 1210 | + # fail silently if an attachment does not validate |
| 1211 | + end |
1207 | 1212 | end
|
1208 | 1213 | end
|
1209 | 1214 | end
|
|
0 commit comments