Skip to content

Commit

Permalink
Fix image not found for blog
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-dharti-r committed Apr 22, 2024
1 parent 1a18af5 commit 55f9ce4
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions post/index.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 55f9ce4

Please sign in to comment.