0.2.64 update
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
)
|
||||
@@ -22,6 +23,7 @@ type heroAdminPolicy struct {
|
||||
PrimeSubtitle string `json:"primeSubtitle"`
|
||||
Placements map[string]heroAdminPlacement `json:"placements"`
|
||||
Schedules []store.HeroSchedule `json:"schedules"`
|
||||
TimeZone string `json:"timeZone"`
|
||||
}
|
||||
|
||||
type heroAdminPlacement struct {
|
||||
@@ -67,6 +69,7 @@ func (s *Server) heroAdminPolicy(ctx context.Context) heroAdminPolicy {
|
||||
Placements: make(map[string]heroAdminPlacement, len(policy.Placements)),
|
||||
Items: []heroAdminItem{},
|
||||
Schedules: policy.Schedules,
|
||||
TimeZone: heroScheduleTimeZone(s.cfg.RadarrLocation),
|
||||
}
|
||||
for _, id := range allIDs {
|
||||
if item, ok := byID[id]; ok {
|
||||
@@ -87,6 +90,13 @@ func (s *Server) heroAdminPolicy(ctx context.Context) heroAdminPolicy {
|
||||
return out
|
||||
}
|
||||
|
||||
func heroScheduleTimeZone(location *time.Location) string {
|
||||
if location == nil {
|
||||
location = time.Local
|
||||
}
|
||||
return location.String()
|
||||
}
|
||||
|
||||
func (s *Server) handleAdminHeroSearch(w http.ResponseWriter, r *http.Request) {
|
||||
items, err := s.store.SearchLibrary(r.Context(), r.URL.Query().Get("q"), 20)
|
||||
if err != nil {
|
||||
@@ -165,6 +175,26 @@ func (s *Server) handleAdminHeroPolicy(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
for _, schedule := range request.Schedules {
|
||||
frequency := strings.ToLower(strings.TrimSpace(schedule.Frequency))
|
||||
if frequency != "" && frequency != "once" && frequency != "daily" && frequency != "weekly" {
|
||||
writeError(w, http.StatusBadRequest, "hero schedule frequency must be once, daily or weekly")
|
||||
return
|
||||
}
|
||||
if frequency == "daily" || frequency == "weekly" {
|
||||
start, startErr := time.Parse("15:04", strings.TrimSpace(schedule.StartTime))
|
||||
end, endErr := time.Parse("15:04", strings.TrimSpace(schedule.EndTime))
|
||||
if startErr != nil || endErr != nil || start.Equal(end) {
|
||||
writeError(w, http.StatusBadRequest, "repeating hero schedules need different start and end times")
|
||||
return
|
||||
}
|
||||
if frequency == "weekly" && len(schedule.Weekdays) == 0 {
|
||||
writeError(w, http.StatusBadRequest, "weekly hero schedules need at least one day")
|
||||
return
|
||||
}
|
||||
} else if !schedule.EndAt.After(schedule.StartAt) {
|
||||
writeError(w, http.StatusBadRequest, "one-time hero schedules need an end after their start")
|
||||
return
|
||||
}
|
||||
item, ok := valid[strings.TrimSpace(schedule.ItemID)]
|
||||
if !ok {
|
||||
writeError(w, http.StatusBadRequest, "every scheduled hero must be a playable library film or series")
|
||||
|
||||
Reference in New Issue
Block a user