fix(LinksMessageView): Remove HEAD validation for image urls

This commit is contained in:
Alex Jbanca 2023-02-10 13:07:54 +02:00 committed by Alex Jbanca
parent f9f860a215
commit 03d80ea9fc
1 changed files with 3 additions and 6 deletions

View File

@ -1,4 +1,4 @@
import std/uri, std/httpclient import std/uri
include ../../common/json_utils include ../../common/json_utils
include ../../../app/core/tasks/common include ../../../app/core/tasks/common
@ -173,7 +173,6 @@ const asyncGetLinkPreviewDataTask: Task = proc(argEncoded: string) {.gcsafe, nim
let parsedWhiteListUrls = parseJson(arg.whiteListedUrls) let parsedWhiteListUrls = parseJson(arg.whiteListedUrls)
let parsedWhiteListImgExtensions = arg.whiteListedImgExtensions.split(",") let parsedWhiteListImgExtensions = arg.whiteListedImgExtensions.split(",")
let httpClient = newHttpClient()
for link in arg.links.split(" "): for link in arg.links.split(" "):
if link == "": if link == "":
@ -204,13 +203,11 @@ const asyncGetLinkPreviewDataTask: Task = proc(argEncoded: string) {.gcsafe, nim
#1. if it's an image, we use httpclient to validate the url #1. if it's an image, we use httpclient to validate the url
if isSupportedImage: if isSupportedImage:
let headResponse = httpclient.head(link) #TODO: validate image url using HEAD request
#validate image url
responseJson["success"] = %(headResponse.code() == Http200 and headResponse.contentType().startsWith("image/"))
responseJson["result"] = %*{ responseJson["result"] = %*{
"site": domain, "site": domain,
"thumbnailUrl": link, "thumbnailUrl": link,
"contentType": headResponse.contentType() "contentType": "image/" & path.split(".")[^1]
} }
previewData["links"].add(responseJson) previewData["links"].add(responseJson)
continue continue