Beispiel #1
0
func getDrop(params martini.Params, db *database.Database, r render.Render) {
	d, err := db.GetDrop(params["url"])
	if err != nil {
		r.JSON(500, map[string]interface{}{"error": err.Error()})
	} else {
		r.JSON(200, map[string]interface{}{"drop": d})
	}
}
Beispiel #2
0
func deleteDrop(params martini.Params, db *database.Database, r render.Render) {
	url := params["url"]
	err := db.DeleteDrop(url)
	if err != nil {
		r.JSON(500, map[string]interface{}{"error": err.Error()})
	} else {
		r.JSON(200, map[string]interface{}{"ok": url})
	}
}
Beispiel #3
0
func listDrops(db *database.Database, r render.Render) {
	// when there's none it returns a null?
	drops, err := json.Marshal(db.ListDrops())
	fmt.Println(drops)
	if err != nil {
		r.JSON(500, map[string]interface{}{"error": err})
	} else {
		r.JSON(200, map[string]interface{}{"drops": string(drops)})
	}
}
Beispiel #4
0
func addDrop(drop database.FormDrop, db *database.Database, r render.Render, req *http.Request) {
	err := req.ParseMultipartForm(100000)
	if err != nil {
		r.JSON(500, map[string]interface{}{"error": "Couldn't parse mutlipart form"})
		return
	}

	files := req.MultipartForm.File["filezors"]
	for i, _ := range files {
		drop, err := db.AddDrop(files[i])
		if err != nil {
			r.JSON(500, map[string]interface{}{"error": err.Error()})
			return
		}
		r.JSON(200, map[string]interface{}{"id": drop.ID, "filename": drop.Filename, "url": drop.ShortURL})
		return
	}
}