@@ -20,18 +20,29 @@ struct AttachmentParser {
2020 4. "description" - description
2121 5. "https..." - (optional) full image url
2222 */
23- static func parseArticleAttachment( from array: [ [ Any ] ] ) -> [ Attachment ] {
24- return array. map { fields in
23+ static func parseArticleAttachment( from array: [ [ Any ] ] ) throws -> [ Attachment ] {
24+ return try array. map { fields in
25+ guard let id = fields [ safe: 0 ] as? Int ,
26+ let url = fields [ safe: 1 ] as? String ,
27+ let width = fields [ safe: 2 ] as? Int ,
28+ let height = fields [ safe: 3 ] as? Int ,
29+ let description = fields [ 4 ] as? String else {
30+ throw ParsingError . failedToCastFields
31+ }
32+
33+ let fullUrl = fields [ safe: 5 ] as? String
34+
2535 return Attachment (
26- id: fields [ 0 ] as! Int ,
36+ id: id ,
2737 type: . image,
2838 name: " " ,
2939 size: 0 ,
3040 metadata: . init(
31- width: fields [ 2 ] as! Int ,
32- height: fields [ 3 ] as! Int ,
33- url: URL ( string: fields [ 1 ] as! String ) !,
34- fullUrl: URL ( string: fields [ 5 ] as! String )
41+ width: width,
42+ height: height,
43+ url: URL ( string: url) !,
44+ fullUrl: URL ( string: fullUrl ?? " " ) ,
45+ description: description
3546 ) ,
3647 downloadCount: nil
3748 )
0 commit comments