helper function to get images

swagger
Akhil Gupta 4 years ago
parent 665edb0171
commit 087e15210e

@ -65,7 +65,7 @@
<img
onerror="onImageError(this)"
class="u-full-width"
{{if .LocalImage }} src="/{{ .LocalImage }}" {{ else }} src="{{ .Image }}" {{end}}
src="/podcastitems/{{.ID}}/image"
alt="{{ .Title }}"
lazy="lazy"
/>

@ -4,6 +4,7 @@ import (
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/akhilrex/podgrab/model"
@ -191,6 +192,26 @@ func GetPodcastItemById(c *gin.Context) {
}
}
func GetPodcastItemImageById(c *gin.Context) {
var searchByIdQuery SearchByIdQuery
if c.ShouldBindUri(&searchByIdQuery) == nil {
var podcast db.PodcastItem
err := db.GetPodcastItemById(searchByIdQuery.Id, &podcast)
if err == nil {
if _, err = os.Stat(podcast.LocalImage); os.IsNotExist(err) {
c.Redirect(301, podcast.Image)
} else {
c.Redirect(302, fmt.Sprintf("/%s", podcast.LocalImage))
}
}
} else {
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
}
}
func MarkPodcastItemAsUnplayed(c *gin.Context) {
var searchByIdQuery SearchByIdQuery

@ -115,6 +115,7 @@ func main() {
router.GET("/podcastitems", controllers.GetAllPodcastItems)
router.GET("/podcastitems/:id", controllers.GetPodcastItemById)
router.GET("/podcastitems/:id/image", controllers.GetPodcastItemImageById)
router.GET("/podcastitems/:id/markUnplayed", controllers.MarkPodcastItemAsUnplayed)
router.GET("/podcastitems/:id/markPlayed", controllers.MarkPodcastItemAsPlayed)
router.GET("/podcastitems/:id/bookmark", controllers.BookmarkPodcastItem)

Loading…
Cancel
Save