forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.go
31 lines (28 loc) · 791 Bytes
/
upload.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package actions
import (
"net/http"
"github.com/gobuffalo/buffalo"
"github.com/gomods/athens/pkg/payloads"
"github.com/gomods/athens/pkg/storage"
"github.com/pkg/errors"
)
func uploadHandler(store storage.Saver) func(c buffalo.Context) error {
return func(c buffalo.Context) error {
mod, err := getModule(c)
if err != nil {
return errors.WithStack(err)
}
version := c.Param("version")
payload := new(payloads.Upload)
if c.Bind(payload); err != nil {
return errors.WithStack(err)
}
saveErr := store.Save(mod, version, payload.Module, payload.Zip)
if storage.IsVersionAlreadyExistsErr(saveErr) {
return c.Error(http.StatusConflict, saveErr)
} else if err != nil {
return errors.WithStack(err)
}
return c.Render(http.StatusOK, proxy.JSON(nil))
}
}