Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Link post with non-accessible image results in 500 error #66

Closed
Codycody31 opened this issue Apr 22, 2024 · 1 comment
Closed

Comments

@Codycody31
Copy link
Contributor

Initial post reporting this: https://discuit.net/DiscuitMeta/post/_FbRPTSe
Site link: https://www.mobilephonemuseum.com/
Image link: https://mpm-next.code8.link/logo.png (this image returns a 503 from apache, not an image)
Message on server when attempting to use URL: 500 Internal server error: Unsupported image format

Seems the image the site uses for its ogImage is not a format discuit supports. Or more like the image it is trying to use doesn't exist

discuit/core/post.go

Lines 688 to 730 in f6fc5b6

func getLinkPostImage(u *url.URL) []byte {
fullURL := u.String()
res, err := httputil.Get(fullURL)
if err != nil {
return nil
}
defer res.Body.Close()
imageURL, err := httputil.ExtractOpenGraphImage(res.Body)
if err != nil {
// TODO: Log this error.
}
if imageURL == "" {
// Since og:image not found, see if the link itself is an image.
probablyAnImage := slices.Contains([]string{"image/jpeg", "image/png", "image/webp"}, res.Header.Get("Content-Type"))
if !probablyAnImage {
exts := []string{".jpg", ".jpeg", ".png", ".webp"}
for _, v := range exts {
if strings.HasSuffix(u.Path, v) {
probablyAnImage = true
break
}
}
}
if probablyAnImage {
imageURL = fullURL
}
}
if imageURL != "" {
res, err := httputil.Get(imageURL)
if err != nil {
return nil
}
defer res.Body.Close()
image, err := io.ReadAll(res.Body)
if err != nil {
return nil
}
return image
}
return nil
}

previnder added a commit that referenced this issue May 27, 2024
Hence, the post is created with or without an og:image tag.
@previnder
Copy link
Member

previnder commented May 27, 2024

Fixed in dffb310.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants