예제 #1
0
파일: pics.go 프로젝트: rwcarlsen/cas
func Handler(nc *blobserv.Client, w http.ResponseWriter, r *http.Request) {
	defer util.DeferWrite(w)
	c = nc

	tmpl := template.Must(template.ParseFiles(appserv.Static("pics/index.tmpl")))

	if picIndex == nil {
		loadPicIndex()
	}
	updateIndex()

	pth := strings.Trim(r.URL.Path, "/")
	if pth == "pics" {
		links := picLinks(picIndex.Newest(10))
		err := tmpl.Execute(w, links)
		util.Check(err)
	} else if strings.HasPrefix(pth, "pics/ref/") {
		ref := path.Base(pth)
		ref = ref[:len(ref)-len(path.Ext(ref))]

		fblob, err := c.ObjectTip(ref)
		util.Check(err)

		m, data, err := c.ReconstituteFile(fblob.Ref())
		util.Check(err)

		ext := path.Ext(m.Name)
		w.Header().Set("Content-Type", mime.TypeByExtension(ext))
		w.Write(data)
	} else {
		err := util.LoadStatic(appserv.Static(pth), w)
		util.Check(err)
	}
}
예제 #2
0
파일: fupload.go 프로젝트: rwcarlsen/cas
func Handler(c *blobserv.Client, w http.ResponseWriter, r *http.Request) {
	defer util.DeferWrite(w)

	pth := strings.Trim(r.URL.Path, "/")
	if pth == "fupload" {
		err := util.LoadStatic(appserv.Static("fupload/index.html"), w)
		util.Check(err)
	} else if pth == "fupload/putfiles" {
		putfiles(c, w, r)
	} else {
		err := util.LoadStatic(appserv.Static(pth), w)
		util.Check(err)
	}
}
예제 #3
0
파일: recent.go 프로젝트: rwcarlsen/cas
func Handler(c *blobserv.Client, w http.ResponseWriter, r *http.Request) {
	defer util.DeferWrite(w)

	tmpl := template.Must(template.ParseFiles(appserv.Static("recent/index.tmpl")))

	pth := strings.Trim(r.URL.Path, "/")
	if pth == "recent" {
		data := stripBlobs(c)
		err := tmpl.Execute(w, data)
		util.Check(err)
	} else {
		err := util.LoadStatic(appserv.Static(pth), w)
		util.Check(err)
	}
}
예제 #4
0
파일: notedrop.go 프로젝트: rwcarlsen/cas
func putnote(c *blobserv.Client, w http.ResponseWriter, req *http.Request) {
	defer util.DeferWrite(w)

	body, err := ioutil.ReadAll(req.Body)
	util.Check(err)

	var note map[string]interface{}
	err = json.Unmarshal(body, &note)
	util.Check(err)

	note[blob.Type] = myType

	b, err := blob.Marshal(note)
	util.Check(err)

	err = c.PutBlob(b)
	util.Check(err)

	w.Write(b.Content())
}