2018-10-31 05:24:12 +09:00
|
|
|
package soundtrack
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 18:32:43 +09:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-10-31 05:24:12 +09:00
|
|
|
)
|
|
|
|
|
|
|
|
// Download tries to refresh the soundtrack file.
|
2019-06-01 13:55:49 +09:00
|
|
|
func Download(ctx aero.Context) error {
|
2018-10-31 05:24:12 +09:00
|
|
|
id := ctx.Get("id")
|
2019-11-17 16:59:34 +09:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2018-10-31 05:24:12 +09:00
|
|
|
|
|
|
|
if user == nil || (user.Role != "editor" && user.Role != "admin") {
|
|
|
|
return ctx.Error(http.StatusUnauthorized, "Not logged in or not auhorized to edit this soundtrack")
|
|
|
|
}
|
|
|
|
|
|
|
|
track, err := arn.GetSoundTrack(id)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "Track not found", err)
|
|
|
|
}
|
|
|
|
|
2019-06-05 15:45:54 +09:00
|
|
|
return track.Download()
|
2018-10-31 05:24:12 +09:00
|
|
|
}
|