From 55f9ce430613dcfcada5d63329ff3a7f6f61a5e8 Mon Sep 17 00:00:00 2001 From: cp-dharti-r Date: Mon, 22 Apr 2024 18:14:52 +0530 Subject: [PATCH] Fix image not found for blog --- post/index.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/post/index.go b/post/index.go index 15b5ac9b7..40b38a4e7 100644 --- a/post/index.go +++ b/post/index.go @@ -196,22 +196,25 @@ func (repository *Repository) GetById(c *gin.Context) { f.size, f.url, f.preview_url, f.provider, f.provider_metadata, f.folder_path, f.created_at, f.updated_at FROM files f JOIN files_related_morphs frm ON frm.related_id = $1 AND frm.related_type = 'api::post.post' AND frm.file_id = f.id`, post.Id) - if err != nil { + if err != nil && err != sql.ErrNoRows { log.Error("Error while fetching post images: ", err) c.AbortWithStatus(http.StatusInternalServerError) return } - var postFormats Formats + if post.Image.Format != "" { - if err := json.Unmarshal([]byte(post.Image.Format), &postFormats); err != nil { - log.Error("Error while unmarshal post image formats: ", err) - c.AbortWithStatus(http.StatusInternalServerError) - return - } + var postFormats Formats - post.Image.Format = "" - post.Image.Formats = postFormats + if err := json.Unmarshal([]byte(post.Image.Format), &postFormats); err != nil { + log.Error("Error while unmarshal post image formats: ", err) + c.AbortWithStatus(http.StatusInternalServerError) + return + } + + post.Image.Format = "" + post.Image.Formats = postFormats + } err = repository.Db.Get(&post.Author, `SELECT a.id, a.username, a.name, a.email, a.created_at, a.updated_at, a.bio FROM authors a