Optimize classify_url function

Changelog-Fixed: Optimized classify_url function
Signed-off-by: Terry Yiu <git@tyiu.xyz>
This commit is contained in:
2025-05-06 10:58:10 -04:00
parent c9696dd9c8
commit eb889a7591

View File

@@ -206,18 +206,17 @@ func url_str(_ url: URL) -> CompatibleText {
}
func classify_url(_ url: URL) -> UrlType {
let str = url.lastPathComponent.lowercased()
let fileExtension = url.lastPathComponent.lowercased().components(separatedBy: ".").last
if str.hasSuffix(".png") || str.hasSuffix(".jpg") || str.hasSuffix(".jpeg") || str.hasSuffix(".gif") || str.hasSuffix(".webp") {
switch fileExtension {
case "png", "jpg", "jpeg", "gif", "webp":
return .media(.image(url))
}
if str.hasSuffix(".mp4") || str.hasSuffix(".mov") || str.hasSuffix(".m3u8") {
case "mp4", "mov", "m3u8":
return .media(.video(url))
}
default:
return .link(url)
}
}
func attributed_string_attach_icon(_ astr: inout AttributedString, img: UIImage) {
let attachment = NSTextAttachment()