2018-04-15 08:36:51 +00:00
|
|
|
package upload
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-04-15 08:36:51 +00:00
|
|
|
|
|
|
|
"github.com/aerogo/aero"
|
|
|
|
"github.com/animenotifier/notify.moe/utils"
|
|
|
|
)
|
|
|
|
|
|
|
|
// AMVFile handles the video upload for AMV files.
|
2019-06-01 04:55:49 +00:00
|
|
|
func AMVFile(ctx aero.Context) error {
|
2018-04-15 08:36:51 +00:00
|
|
|
user := utils.GetUser(ctx)
|
|
|
|
amvID := ctx.Get("id")
|
|
|
|
|
|
|
|
if user == nil {
|
2018-07-07 03:42:00 +00:00
|
|
|
return ctx.Error(http.StatusUnauthorized, "Not logged in")
|
2018-04-15 08:36:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
amv, err := arn.GetAMV(amvID)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusNotFound, "AMV not found", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Retrieve file from post body
|
2019-08-28 01:07:50 +00:00
|
|
|
reader := ctx.Request().Body().Reader()
|
|
|
|
defer reader.Close()
|
2018-04-15 08:36:51 +00:00
|
|
|
|
2019-08-28 01:07:50 +00:00
|
|
|
// Set amv video file
|
|
|
|
err = amv.SetVideoReader(reader)
|
2018-04-15 08:36:51 +00:00
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return ctx.Error(http.StatusInternalServerError, "Invalid video format", err)
|
|
|
|
}
|
|
|
|
|
2019-08-28 01:07:50 +00:00
|
|
|
// Save video information
|
2018-04-15 08:36:51 +00:00
|
|
|
amv.Save()
|
|
|
|
|
|
|
|
// Write log entry
|
|
|
|
logEntry := arn.NewEditLogEntry(user.ID, "edit", "AMV", amv.ID, "File", "", "")
|
|
|
|
logEntry.Save()
|
|
|
|
|
2019-06-01 04:55:49 +00:00
|
|
|
return nil
|
2018-04-15 08:36:51 +00:00
|
|
|
}
|