API Cleanup
This commit is contained in:
parent
bd293de4be
commit
c5cb497722
@ -72,7 +72,7 @@ func Get(ctx *aero.Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Soundtracks
|
// Soundtracks
|
||||||
tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
return !track.IsDraft && len(track.Media) > 0 && arn.Contains(track.Tags, "anime:"+anime.ID)
|
return !track.IsDraft && len(track.Media) > 0 && arn.Contains(track.Tags, "anime:"+anime.ID)
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -80,10 +80,6 @@ func Get(ctx *aero.Context) string {
|
|||||||
return tracks[i].Title < tracks[j].Title
|
return tracks[i].Title < tracks[j].Title
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ctx.Error(http.StatusNotFound, "Error fetching soundtracks", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open Graph
|
// Open Graph
|
||||||
description := anime.Summary
|
description := anime.Summary
|
||||||
|
|
||||||
|
@ -19,13 +19,9 @@ func Tracks(ctx *aero.Context) string {
|
|||||||
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
return ctx.Error(http.StatusNotFound, "Anime not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
return !track.IsDraft && len(track.Media) > 0 && arn.Contains(track.Tags, "anime:"+anime.ID)
|
return !track.IsDraft && len(track.Media) > 0 && arn.Contains(track.Tags, "anime:"+anime.ID)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ctx.Error(http.StatusNotFound, "Error fetching soundtracks", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return ctx.HTML(components.AnimeTracks(anime, tracks))
|
return ctx.HTML(components.AnimeTracks(anime, tracks))
|
||||||
}
|
}
|
||||||
|
31
pages/companies/companies.go
Normal file
31
pages/companies/companies.go
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
package companies
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/aerogo/aero"
|
||||||
|
"github.com/animenotifier/arn"
|
||||||
|
"github.com/animenotifier/notify.moe/components"
|
||||||
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
|
)
|
||||||
|
|
||||||
|
const maxEntries = 12
|
||||||
|
|
||||||
|
// Get renders the companies page.
|
||||||
|
func Get(ctx *aero.Context) string {
|
||||||
|
user := utils.GetUser(ctx)
|
||||||
|
|
||||||
|
companies := arn.FilterCompanies(func(company *arn.Company) bool {
|
||||||
|
return !company.IsDraft
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Error(http.StatusInternalServerError, "Error fetching companies", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(companies) > maxEntries {
|
||||||
|
companies = companies[:maxEntries]
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.HTML(components.Companies(companies, user))
|
||||||
|
}
|
0
pages/companies/companies.pixy
Normal file
0
pages/companies/companies.pixy
Normal file
@ -72,15 +72,10 @@ func Get(ctx *aero.Context) string {
|
|||||||
upcomingEpisodes = upcomingEpisodes[:maxScheduleItems]
|
upcomingEpisodes = upcomingEpisodes[:maxScheduleItems]
|
||||||
}
|
}
|
||||||
}, func() {
|
}, func() {
|
||||||
var err error
|
soundTracks = arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
soundTracks, err = arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
|
||||||
return !track.IsDraft && len(track.Media) > 0
|
return !track.IsDraft && len(track.Media) > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
arn.SortSoundTracksLatestFirst(soundTracks)
|
arn.SortSoundTracksLatestFirst(soundTracks)
|
||||||
|
|
||||||
if len(soundTracks) > maxSoundTracks {
|
if len(soundTracks) > maxSoundTracks {
|
||||||
|
@ -19,14 +19,10 @@ func GetSoundTracksByUser(ctx *aero.Context) string {
|
|||||||
return ctx.Error(http.StatusNotFound, "User not found", err)
|
return ctx.Error(http.StatusNotFound, "User not found", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
return !track.IsDraft && len(track.Media) > 0 && track.CreatedBy == viewUser.ID
|
return !track.IsDraft && len(track.Media) > 0 && track.CreatedBy == viewUser.ID
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
arn.SortSoundTracksLatestFirst(tracks)
|
arn.SortSoundTracksLatestFirst(tracks)
|
||||||
|
|
||||||
return ctx.HTML(components.TrackList(tracks, viewUser, user, ctx.URI()))
|
return ctx.HTML(components.TrackList(tracks, viewUser, user, ctx.URI()))
|
||||||
|
@ -16,14 +16,10 @@ const maxTracks = 12
|
|||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
|
|
||||||
tracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
tracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
return !track.IsDraft && len(track.Media) > 0
|
return !track.IsDraft && len(track.Media) > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
arn.SortSoundTracksLatestFirst(tracks)
|
arn.SortSoundTracksLatestFirst(tracks)
|
||||||
|
|
||||||
if len(tracks) > maxTracks {
|
if len(tracks) > maxTracks {
|
||||||
@ -42,14 +38,10 @@ func From(ctx *aero.Context) string {
|
|||||||
return ctx.Error(http.StatusBadRequest, "Invalid start index", err)
|
return ctx.Error(http.StatusBadRequest, "Invalid start index", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
allTracks, err := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
allTracks := arn.FilterSoundTracks(func(track *arn.SoundTrack) bool {
|
||||||
return !track.IsDraft && len(track.Media) > 0
|
return !track.IsDraft && len(track.Media) > 0
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
return ctx.Error(http.StatusInternalServerError, "Error fetching soundtracks", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if index < 0 || index >= len(allTracks) {
|
if index < 0 || index >= len(allTracks) {
|
||||||
return ctx.Error(http.StatusBadRequest, "Invalid start index (maximum is "+strconv.Itoa(len(allTracks))+")", nil)
|
return ctx.Error(http.StatusBadRequest, "Invalid start index (maximum is "+strconv.Itoa(len(allTracks))+")", nil)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user