feat: add episode titles api endpoint
This commit is contained in:
@@ -40,12 +40,46 @@ func (h *PlaybackHandler) Register(r *gin.Engine) {
|
|||||||
r.GET("/anime/:id/watch", h.HandleWatchPage)
|
r.GET("/anime/:id/watch", h.HandleWatchPage)
|
||||||
r.POST("/api/watch-progress", h.HandleSaveProgress)
|
r.POST("/api/watch-progress", h.HandleSaveProgress)
|
||||||
r.POST("/api/watch-complete", h.HandleWatchComplete)
|
r.POST("/api/watch-complete", h.HandleWatchComplete)
|
||||||
|
r.GET("/api/watch/episodes/:animeId/titles", h.HandleEpisodeTitles)
|
||||||
r.GET("/api/watch/episode/:animeId/:episode", h.HandleEpisodeData)
|
r.GET("/api/watch/episode/:animeId/:episode", h.HandleEpisodeData)
|
||||||
r.POST("/api/watch/segments", h.HandleUpsertSkipSegment)
|
r.POST("/api/watch/segments", h.HandleUpsertSkipSegment)
|
||||||
r.GET("/watch/proxy/stream", h.HandleProxyStream)
|
r.GET("/watch/proxy/stream", h.HandleProxyStream)
|
||||||
r.GET("/watch/proxy/subtitle", h.HandleProxySubtitle)
|
r.GET("/watch/proxy/subtitle", h.HandleProxySubtitle)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (h *PlaybackHandler) HandleEpisodeTitles(c *gin.Context) {
|
||||||
|
animeID, err := strconv.Atoi(c.Param("animeId"))
|
||||||
|
if err != nil || animeID <= 0 {
|
||||||
|
server.RespondHTMLOrJSONError(c, http.StatusBadRequest, "invalid anime id")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
enricher, ok := h.svc.(domain.PlaybackEpisodeTitleService)
|
||||||
|
if !ok {
|
||||||
|
server.RespondHTMLOrJSONError(c, http.StatusServiceUnavailable, "episode titles are unavailable")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
episodes, err := enricher.EnrichEpisodeTitles(c.Request.Context(), animeID)
|
||||||
|
if err != nil {
|
||||||
|
server.RespondError(
|
||||||
|
c,
|
||||||
|
http.StatusBadGateway,
|
||||||
|
"watch_episode_titles_failed",
|
||||||
|
"playback",
|
||||||
|
"episode titles are unavailable",
|
||||||
|
map[string]any{"anime_id": animeID},
|
||||||
|
err,
|
||||||
|
)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
titles := make([]gin.H, 0, len(episodes))
|
||||||
|
for _, episode := range episodes {
|
||||||
|
titles = append(titles, gin.H{"number": episode.Number, "title": episode.Title})
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, titles)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *PlaybackHandler) HandleWatchPage(c *gin.Context) {
|
func (h *PlaybackHandler) HandleWatchPage(c *gin.Context) {
|
||||||
id, err := strconv.Atoi(c.Param("id"))
|
id, err := strconv.Atoi(c.Param("id"))
|
||||||
if err != nil || id <= 0 {
|
if err != nil || id <= 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user