aboutsummaryrefslogtreecommitdiff
path: root/garage.go
diff options
context:
space:
mode:
Diffstat (limited to 'garage.go')
-rw-r--r--garage.go45
1 files changed, 36 insertions, 9 deletions
diff --git a/garage.go b/garage.go
index 8c8633f..d3d4d38 100644
--- a/garage.go
+++ b/garage.go
@@ -160,6 +160,16 @@ func grgGetBucket(bid string) (*garage.BucketInfo, error) {
}
+func grgDeleteBucket(bid string) error {
+ client, ctx := gadmin()
+
+ _, err := client.BucketApi.DeleteBucket(ctx, bid).Execute()
+ if err != nil {
+ log.Println(err)
+ }
+ return err
+}
+
// --- Start page rendering functions
func handleWebsiteConfigure(w http.ResponseWriter, r *http.Request) {
@@ -193,8 +203,8 @@ func handleWebsiteList(w http.ResponseWriter, r *http.Request) {
}
type WebsiteNewTpl struct {
- ctrl *WebsiteController
- err error
+ Ctrl *WebsiteController
+ Err error
}
func handleWebsiteNew(w http.ResponseWriter, r *http.Request) {
@@ -209,10 +219,7 @@ func handleWebsiteNew(w http.ResponseWriter, r *http.Request) {
return
}
- tpl := &WebsiteNewTpl{
- ctrl: ctrl,
- err: nil,
- }
+ tpl := &WebsiteNewTpl{ctrl, nil}
tWebsiteNew := getTemplate("garage_website_new.html")
if r.Method == "POST" {
@@ -225,23 +232,27 @@ func handleWebsiteNew(w http.ResponseWriter, r *http.Request) {
view, err := ctrl.Create(bucket)
if err != nil {
- tpl.err = err
+ tpl.Err = err
tWebsiteNew.Execute(w, tpl)
+ return
}
http.Redirect(w, r, "/website/inspect/"+view.Name.Pretty, http.StatusFound)
return
}
- tWebsiteNew.Execute(w, nil)
+ tWebsiteNew.Execute(w, tpl)
}
type WebsiteInspectTpl struct {
Ctrl *WebsiteController
View *WebsiteView
+ Err error
}
func handleWebsiteInspect(w http.ResponseWriter, r *http.Request) {
+ var processErr error
+
user := RequireUserHtml(w, r)
if user == nil {
return
@@ -254,6 +265,22 @@ func handleWebsiteInspect(w http.ResponseWriter, r *http.Request) {
}
bucketName := mux.Vars(r)["bucket"]
+
+ if r.Method == "POST" {
+ r.ParseForm()
+ action := strings.Join(r.Form["action"],"")
+ switch action {
+ case "increase_quota":
+ _, processErr = ctrl.Patch(bucketName, &WebsitePatch { size: &user.Quota.WebsiteSizeBursted })
+ case "delete_bucket":
+ processErr = ctrl.Delete(bucketName)
+ http.Redirect(w, r, "/website", http.StatusFound)
+ return
+ default:
+ processErr = fmt.Errorf("Unknown action")
+ }
+
+ }
view, err := ctrl.Inspect(bucketName)
if err != nil {
@@ -261,7 +288,7 @@ func handleWebsiteInspect(w http.ResponseWriter, r *http.Request) {
return
}
- tpl := &WebsiteInspectTpl{ ctrl, view }
+ tpl := &WebsiteInspectTpl{ ctrl, view, processErr }
tWebsiteInspect := getTemplate("garage_website_inspect.html")
tWebsiteInspect.Execute(w, &tpl)