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