Add publication and deletion
This commit is contained in:
parent
c531433d23
commit
c1af90eccf
2 changed files with 35 additions and 0 deletions
1
api.go
1
api.go
|
@ -14,6 +14,7 @@ type DispatchFunction func(*User, []string, io.ReadCloser) (interface{}, error)
|
||||||
|
|
||||||
var apiRoutes = map[string]*(map[string]struct{AuthFunction;DispatchFunction}){
|
var apiRoutes = map[string]*(map[string]struct{AuthFunction;DispatchFunction}){
|
||||||
"images": &ApiImagesRouting,
|
"images": &ApiImagesRouting,
|
||||||
|
"next": &ApiNextImagesRouting,
|
||||||
"version": &ApiVersionRouting,
|
"version": &ApiVersionRouting,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,12 @@ var ApiImagesRouting = map[string]struct{AuthFunction; DispatchFunction}{
|
||||||
"DELETE": {PrivatePage, hideImage},
|
"DELETE": {PrivatePage, hideImage},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ApiNextImagesRouting = map[string]struct{AuthFunction; DispatchFunction}{
|
||||||
|
"GET": {PrivatePage, listNextImages},
|
||||||
|
"POST": {PublicPage, addImage},
|
||||||
|
"DELETE": {PrivatePage, deleteImage},
|
||||||
|
}
|
||||||
|
|
||||||
func listImages(u *User, args []string, body io.ReadCloser) (interface{}, error) {
|
func listImages(u *User, args []string, body io.ReadCloser) (interface{}, error) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return GetPublishedImages()
|
return GetPublishedImages()
|
||||||
|
@ -21,6 +27,22 @@ func listImages(u *User, args []string, body io.ReadCloser) (interface{}, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func listNextImages(u *User, args []string, body io.ReadCloser) (interface{}, error) {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return GetNextImages()
|
||||||
|
} else if len(args) >= 2 && args[1] == "publish" {
|
||||||
|
if pict, err := GetNextImage(args[0]); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else if err := pict.Publish(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return GetNextImage(args[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func addImage(u *User, args []string, body io.ReadCloser) (interface{}, error) {
|
func addImage(u *User, args []string, body io.ReadCloser) (interface{}, error) {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
return nil, errors.New("Need an image identifier to create")
|
return nil, errors.New("Need an image identifier to create")
|
||||||
|
@ -42,3 +64,15 @@ func hideImage(u *User, args []string, body io.ReadCloser) (interface{}, error)
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func deleteImage(u *User, args []string, body io.ReadCloser) (interface{}, error) {
|
||||||
|
if len(args) < 1 {
|
||||||
|
return nil, errors.New("Need an image identifier to delete")
|
||||||
|
} else if pict, err := GetNextImage(args[0]); err != nil {
|
||||||
|
return nil, errors.New("No matching image")
|
||||||
|
} else if err := pict.Remove(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
} else {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue