Skip to content

Commit 39d7ebd

Browse files
committed
fix: properly assign EndsAt
1 parent 632cef1 commit 39d7ebd

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

.idea/data_source_mapping.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pages/player/GetPlayer.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,23 @@ func (controller *Controller) ReportSongDuration(w reqRes.MyResponseWriter, r *r
148148
return
149149
}
150150

151+
var lastSong models.QueuedSong
152+
err = controller.db.
153+
Order("ends_at DESC").
154+
First(&lastSong).Error
155+
if err != nil {
156+
message := fmt.Sprintf("Failed to read last end: \n%v", err.Error())
157+
w.Error(message, http.StatusInternalServerError)
158+
return
159+
}
160+
151161
song.Duration = time.Duration(duration * float64(time.Second))
152-
song.EndsAt = song.CreatedAt.Add(song.Duration)
162+
if lastSong.EndsAt.Before(song.CreatedAt) {
163+
song.EndsAt = song.CreatedAt.Add(song.Duration)
164+
} else {
165+
song.EndsAt = lastSong.EndsAt.Add(song.Duration)
166+
}
167+
153168
controller.db.Updates(&song)
154169
} else {
155170
// duration already known, ignore

0 commit comments

Comments
 (0)