Resize if requested

This commit is contained in:
Deluan 2022-12-19 17:07:29 -05:00 committed by Deluan Quintão
parent 7b87386089
commit 213ceeca78
6 changed files with 163 additions and 36 deletions

View file

@ -18,15 +18,15 @@ var (
type ArtworkID struct {
Kind Kind
ID string
LastAccess time.Time
LastUpdate time.Time
}
func (id ArtworkID) String() string {
s := fmt.Sprintf("%s-%s", id.Kind.prefix, id.ID)
if id.LastAccess.Unix() < 0 {
if id.LastUpdate.Unix() < 0 {
return s + "-0"
}
return fmt.Sprintf("%s-%x", s, id.LastAccess.Unix())
return fmt.Sprintf("%s-%x", s, id.LastUpdate.Unix())
}
func ParseArtworkID(id string) (ArtworkID, error) {
@ -44,7 +44,7 @@ func ParseArtworkID(id string) (ArtworkID, error) {
return ArtworkID{
Kind: Kind{parts[0]},
ID: parts[1],
LastAccess: time.Unix(lastUpdate, 0),
LastUpdate: time.Unix(lastUpdate, 0),
}, nil
}
@ -52,7 +52,7 @@ func artworkIDFromAlbum(al Album) ArtworkID {
return ArtworkID{
Kind: KindAlbumArtwork,
ID: al.ID,
LastAccess: al.UpdatedAt,
LastUpdate: al.UpdatedAt,
}
}
@ -60,6 +60,6 @@ func artworkIDFromMediaFile(mf MediaFile) ArtworkID {
return ArtworkID{
Kind: KindMediaFileArtwork,
ID: mf.ID,
LastAccess: mf.UpdatedAt,
LastUpdate: mf.UpdatedAt,
}
}

View file

@ -14,14 +14,14 @@ var _ = Describe("ParseArtworkID()", func() {
Expect(err).ToNot(HaveOccurred())
Expect(id.Kind).To(Equal(model.KindAlbumArtwork))
Expect(id.ID).To(Equal("1234"))
Expect(id.LastAccess).To(Equal(time.Unix(255, 0)))
Expect(id.LastUpdate).To(Equal(time.Unix(255, 0)))
})
It("parses media file artwork ids", func() {
id, err := model.ParseArtworkID("mf-a6f8d2b1-ffff")
Expect(err).ToNot(HaveOccurred())
Expect(id.Kind).To(Equal(model.KindMediaFileArtwork))
Expect(id.ID).To(Equal("a6f8d2b1"))
Expect(id.LastAccess).To(Equal(time.Unix(65535, 0)))
Expect(id.LastUpdate).To(Equal(time.Unix(65535, 0)))
})
It("fails to parse malformed ids", func() {
_, err := model.ParseArtworkID("a6f8d2b1")

View file

@ -46,7 +46,7 @@ func (pls Playlist) MediaFiles() MediaFiles {
func (pls *Playlist) RemoveTracks(idxToRemove []int) {
var newTracks PlaylistTracks
for i, t := range pls.Tracks {
if slices.Index(idxToRemove, i) >= 0 {
if slices.Contains(idxToRemove, i) {
continue
}
newTracks = append(newTracks, t)