|
|
@ -103,6 +103,7 @@ enum GiphyFormat {
|
|
|
|
guard rendition.name.hasSuffix("_still") else {
|
|
|
|
guard rendition.name.hasSuffix("_still") else {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Accept renditions without a valid file size.
|
|
|
|
guard rendition.width >= kMinDimension &&
|
|
|
|
guard rendition.width >= kMinDimension &&
|
|
|
|
rendition.height >= kMinDimension &&
|
|
|
|
rendition.height >= kMinDimension &&
|
|
|
|
rendition.fileSize <= kMaxFileSize
|
|
|
|
rendition.fileSize <= kMaxFileSize
|
|
|
@ -123,6 +124,7 @@ enum GiphyFormat {
|
|
|
|
rendition.width <= kMaxDimension &&
|
|
|
|
rendition.width <= kMaxDimension &&
|
|
|
|
rendition.height >= kMinDimension &&
|
|
|
|
rendition.height >= kMinDimension &&
|
|
|
|
rendition.height <= kMaxDimension &&
|
|
|
|
rendition.height <= kMaxDimension &&
|
|
|
|
|
|
|
|
rendition.fileSize > 0 &&
|
|
|
|
rendition.fileSize <= kMaxFileSize
|
|
|
|
rendition.fileSize <= kMaxFileSize
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
continue
|
|
|
|
continue
|
|
|
@ -317,11 +319,10 @@ enum GiphyFormat {
|
|
|
|
guard let height = parsePositiveUInt(dict:renditionDict, key:"height", typeName:"rendition") else {
|
|
|
|
guard let height = parsePositiveUInt(dict:renditionDict, key:"height", typeName:"rendition") else {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard let fileSize = parsePositiveUInt(dict:renditionDict, key:"size", typeName:"rendition") else {
|
|
|
|
// Be lenient when parsing file sizes - we don't require them for stills.
|
|
|
|
return nil
|
|
|
|
let fileSize = parseLenientUInt(dict:renditionDict, key:"size")
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let urlString = renditionDict["url"] as? String else {
|
|
|
|
guard let urlString = renditionDict["url"] as? String else {
|
|
|
|
Logger.debug("\(GifManager.TAG) Rendition missing url.")
|
|
|
|
// Logger.debug("\(GifManager.TAG) Rendition missing url.")
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard urlString.characters.count > 0 else {
|
|
|
|
guard urlString.characters.count > 0 else {
|
|
|
@ -377,15 +378,15 @@ enum GiphyFormat {
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
private func parsePositiveUInt(dict: [String:Any], key: String, typeName: String) -> UInt? {
|
|
|
|
private func parsePositiveUInt(dict: [String:Any], key: String, typeName: String) -> UInt? {
|
|
|
|
guard let value = dict[key] else {
|
|
|
|
guard let value = dict[key] else {
|
|
|
|
// Logger.verbose("\(GifManager.TAG) \(typeName) missing \(key).")
|
|
|
|
// Logger.verbose("\(GifManager.TAG) \(typeName) missing \(key).")
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard let stringValue = value as? String else {
|
|
|
|
guard let stringValue = value as? String else {
|
|
|
|
// Logger.verbose("\(GifManager.TAG) \(typeName) has invalid \(key): \(value).")
|
|
|
|
// Logger.verbose("\(GifManager.TAG) \(typeName) has invalid \(key): \(value).")
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard let parsedValue = UInt(stringValue) else {
|
|
|
|
guard let parsedValue = UInt(stringValue) else {
|
|
|
|
// Logger.verbose("\(GifManager.TAG) \(typeName) has invalid \(key): \(stringValue).")
|
|
|
|
// Logger.verbose("\(GifManager.TAG) \(typeName) has invalid \(key): \(stringValue).")
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
guard parsedValue > 0 else {
|
|
|
|
guard parsedValue > 0 else {
|
|
|
@ -394,4 +395,19 @@ enum GiphyFormat {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return parsedValue
|
|
|
|
return parsedValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private func parseLenientUInt(dict: [String:Any], key: String) -> UInt {
|
|
|
|
|
|
|
|
let defaultValue = UInt(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
guard let value = dict[key] else {
|
|
|
|
|
|
|
|
return defaultValue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let stringValue = value as? String else {
|
|
|
|
|
|
|
|
return defaultValue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
guard let parsedValue = UInt(stringValue) else {
|
|
|
|
|
|
|
|
return defaultValue
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return parsedValue
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|