package main import ( "bytes" "git.gitorious.org/go-pkg/epubgo.git" "github.com/gorilla/mux" "github.com/nfnt/resize" "image" "image/jpeg" "io" "io/ioutil" "labix.org/v2/mgo" "labix.org/v2/mgo/bson" "log" "net/http" "regexp" "strings" ) func coverHandler(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) id := bson.ObjectIdHex(vars["id"]) books, _, err := db.GetBooks(bson.M{"_id": id}) if err != nil || len(books) == 0 { http.NotFound(w, r) return } book := books[0] if !book.Active { sess := GetSession(r) if sess.User == "" { http.NotFound(w, r) return } } fs := db.GetFS(FS_IMGS) var f *mgo.GridFile if vars["size"] == "small" { f, err = fs.OpenId(book.CoverSmall) } else { f, err = fs.OpenId(book.Cover) } if err != nil { log.Println("Error while opening image:", err) http.NotFound(w, r) return } defer f.Close() headers := w.Header() headers["Content-Type"] = []string{"image/jpeg"} io.Copy(w, f) } func GetCover(e *epubgo.Epub, title string) (bson.ObjectId, bson.ObjectId) { imgId, smallId := searchCommonCoverNames(e, title) if imgId != "" { return imgId, smallId } /* search for img on the text */ exp, _ := regexp.Compile("