func downloadTranslationHandler(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { panic(&core.Error{http.StatusMethodNotAllowed, ""}) } // parses query parameters params, err := url.ParseQuery(r.URL.RawQuery) if err != nil { panic(&core.Error{http.StatusBadRequest, ""}) } // TODO supports other query params blobKey := params.Get("blobKey") translations, err := loadTranslations(appengine.NewContext(r), false) if err != nil { panic(&core.Error{http.StatusInternalServerError, err.Error()}) } for _, t := range translations { if (string)(t.BlobKey) == blobKey { blobstore.Send(w, appengine.BlobKey(blobKey)) return } } panic(&core.Error{http.StatusNotFound, ""}) }
func get(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { http.Redirect(w, r, WEBSITE, http.StatusFound) return } parts := strings.Split(r.URL.Path, "/") if len(parts) == 3 { if key := parts[1]; key != "" { blobKey := appengine.BlobKey(key) bi, err := blobstore.Stat(appengine.NewContext(r), blobKey) if err == nil { w.Header().Add("X-Content-Type-Options", "nosniff") if !imageTypes.MatchString(bi.ContentType) { w.Header().Add("Content-Type", "application/octet-stream") w.Header().Add( "Content-Disposition", fmt.Sprintf("attachment; filename=\"%s\"", parts[2]), ) } w.Header().Add( "Cache-Control", fmt.Sprintf("public,max-age=%d", EXPIRATION_TIME), ) blobstore.Send(w, blobKey) return } } } http.Error(w, "404 Not Found", http.StatusNotFound) }
func handleImages(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" || r.URL.Path != "/images" { serve404(w) return } name := r.FormValue("Name") if r.Method != "GET" || r.URL.Path != "/images" || "" == name { serve404(w) return } c := appengine.NewContext(r) key := datastore.NewKey(c, "Image", name, 0, nil) img := Image{} err := datastore.Get(c, key, &img) if nil != err && datastore.ErrNoSuchEntity != err { serveError(c, w, err) return } if datastore.ErrNoSuchEntity == err { serve404(w) return } blobstore.Send(w, img.BlobKey) return }
// Get a file that is part of a visualization func getVisualizationFile(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) vars := mux.Vars(r) // Get visualization object key, err := datastore.DecodeKey(vars["key"]) if err != nil { common.Serve404(w) return } var e model.Visualization err = datastore.Get(c, key, &e) if err != nil { if err == datastore.ErrNoSuchEntity { common.Serve404(w) return } common.ServeError(c, w, err) return } // Find blob key filename := vars["filename"] for i := range e.Files { if e.Files[i].Filename == filename { blobstore.Send(w, appengine.BlobKey(e.Files[i].BlobKey)) return } } common.Serve404(w) }
//Download serves the broadcast from blobstore. func Download(c util.Context) (err error) { p, err := getPresentation(c) if err != nil { return } blobstore.Send(c.W, p.BlobKey) return }
func (d *gcsDriver) Serve(w http.ResponseWriter, id string, rng driver.Range) (bool, error) { if rng.IsValid() { w.Header().Set("X-AppEngine-BlobRange", rng.String()) } key, err := blobstore.BlobKeyForFile(d.c, d.path(id)) if err != nil { return false, err } blobstore.Send(w, key) return true, nil }
// downloadHandler serves the zip file generated by zipHandler. func downloadHandler(c appengine.Context, w http.ResponseWriter, r *http.Request) *appError { k, o, err := getOverlay(r) if err != nil { return appErrorf(err, "overlay not found") } if o.Zip == "" || o.Zip == zipSentinel { return appErrorf(nil, "overlay's zip not generated yet") } attachment := fmt.Sprintf(`attachment;filename="%s.zip"`, k.Encode()) w.Header().Add("Content-Disposition", attachment) blobstore.Send(w, o.Zip) return nil }
// Serves several package related urls that package.el expects. // // First are readmes, which are served from // /packages/<package-name>-readme.txt. // // Second are package contents, which exist for all uploaded versions // of a packages. They are servered from // /packages/<package-name>-<package-version>.el func packages(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) w.Header().Set("Content-Type", "text/plain") file := r.URL.Path[strings.LastIndex(r.URL.Path, "/")+1:] if readmeRE.MatchString(file) { name := file[:strings.LastIndex(file, "-")] var p Package err := datastore.Get(c, packageKey(c, name), &p) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } details, err := decodeDetails(&p.Details) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } if len(details.Readme) == 0 { fmt.Fprintf(w, "%v", p.Description) } else { // These \r's will show up as "^M" in the emacs buffer. // We don't want that, although hopefully package.el will // eventually fix this. fmt.Fprintf(w, "%v", strings.Replace(details.Readme, "\r", "", -1)) } } else { parts := nameVersionRE.FindStringSubmatch(file) if len(parts) < 3 { http.Error(w, "Invalid package name", http.StatusInternalServerError) return } name := parts[1][:len(parts[1])-1] version := parts[2] q := datastore.NewQuery("Contents").Filter("Version=", version). Ancestor(packageKey(c, name)) for cursor := q.Run(c); ; { var contents Contents _, err := cursor.Next(&contents) if err == datastore.Done { break } if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) return } blobstore.Send(w, appengine.BlobKey(contents.BlobKey)) } } }
// 画像のダウンロード func handleDownloadImage(w http.ResponseWriter, r *http.Request) { if r.Method != "GET" { http.Error(w, "リクエストエラー", http.StatusBadRequest) return } c := appengine.NewContext(r) g := goon.FromContext(c) key := r.FormValue("key") ibi := ImageBlobInfo{ BlobKey: key, } g.Get(&ibi) blobstore.Send(w, appengine.BlobKey(ibi.BlobKey)) }
func handleRoot(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) datastoreKey := r.URL.Path[1:] if len(datastoreKey) > 0 { var img Image key, err := datastore.DecodeKey(datastoreKey) if err == nil { if err = datastore.Get(c, key, &img); err == nil { blobstore.Send(w, img.BlobKey) return } } } fmt.Fprint(w, "Hello World!") }
// Get a file that is part of a module func getModuleFile(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) vars := mux.Vars(r) // Get module object accKey, _, err := model.GetAccountByDevname(c, vars["devname"]) if err != nil { common.ServeError(c, w, err) return } if accKey == nil { common.Serve404(w) return } key := datastore.NewKey(c, "module", vars["name"], 0, accKey) var e model.Module err = datastore.Get(c, key, &e) if err != nil { if err == datastore.ErrNoSuchEntity { common.Serve404(w) return } common.ServeError(c, w, err) return } // Find blob key filename := vars["filename"] for i := range e.Files { if e.Files[i].Filename == filename { blobstore.Send(w, appengine.BlobKey(e.Files[i].BlobKey)) return } } common.Serve404(w) }
func jobOutputHandler(w http.ResponseWriter, r *http.Request) { path := r.URL.Path jobID := path[12:] c := appengine.NewContext(r) state := &job.State{ID: jobID} if err := datastore.Get(c, state.GetKey(c), state); err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } if state.OutputData == "" { http.Error(w, "No processing output", http.StatusBadRequest) } blobKey, err := blobstore.BlobKeyForFile(c, state.OutputData) if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } w.Header().Set("Cache-Control", "public,max-age:60000") blobstore.Send(w, blobKey) }
func handleServeImgById(w http.ResponseWriter, r *http.Request) { if r.FormValue("id") != "none" { c := appengine.NewContext(r) oft, _ := model.GetOferta(c, r.FormValue("id")) if oft.BlobKey != "none" { var imgprops image.ServingURLOptions imgprops.Secure = true imgprops.Size = 400 imgprops.Crop = false if url, err := image.ServingURL(c, oft.BlobKey, &imgprops); err != nil { c.Infof("Cannot construct ServingURL : %v", r.FormValue("id")) blobstore.Send(w, oft.BlobKey) } else { http.Redirect(w, r, url.String(), http.StatusFound) } } else { w.WriteHeader(http.StatusNotFound) //w.Header().Set("Content-Type", "text/plain; charset=utf-8") //io.WriteString(w, "404 - Not Found") } } return }
func store(w http.ResponseWriter, r *http.Request) { c := appengine.NewContext(r) c.Debugf("20") blobstore.Send(w, appengine.BlobKey(r.FormValue("blobKey"))) }
func blob(resp http.ResponseWriter, req *http.Request) { _, id := path.Split(req.URL.Path) blobstore.Send(resp, appengine.BlobKey(id)) }
// Takes a blobstore key and serves the file with the appropriate headers func BlobstoreFileServer(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) blobKey := vars["blobKey"] blobstore.Send(w, appengine.BlobKey(blobKey)) }
func serveHandler(w http.ResponseWriter, r *http.Request) { blobstore.Send(w, appengine.BlobKey(r.URL.Query()["key"][0])) }
func serveFull(c appengine.Context, w http.ResponseWriter, r *http.Request) { blobstore.Send(w, appengine.BlobKey(r.FormValue("blobkey"))) }
func handleServe(w http.ResponseWriter, r *http.Request) { if err := users.CheckPerm(w, r, users.OP_VIEW); err != nil { return } blobstore.Send(w, appengine.BlobKey(r.FormValue("blobKey"))) }
func handleServeImgByIdOrBlob(w http.ResponseWriter, r *http.Request) { if r.FormValue("id") != "none" { c := appengine.NewContext(r) var imgprops image.ServingURLOptions imgprops.Secure = true imgprops.Size = 400 imgprops.Crop = false if model.ValidID.MatchString(r.FormValue("id")) { /* Cuando es un Id normal */ //c.Infof("Blob : %v", r.FormValue("id")) //now := time.Now().Add(time.Duration(model.GMTADJ)*time.Second) var timetolive = 900 //seconds var b []byte var d detalle if item, err := memcache.Get(c, "d_"+r.FormValue("id")); err == memcache.ErrCacheMiss { oferta, _ := model.GetOferta(c, r.FormValue("id")) if oferta.BlobKey != "none" { //if now.After(oferta.FechaHoraPub) { d.IdEmp = oferta.IdEmp d.IdOft = oferta.IdOft d.IdCat = oferta.IdCat d.Oferta = oferta.Oferta d.Empresa = oferta.Empresa d.Descripcion = oferta.Descripcion d.Enlinea = oferta.Enlinea d.Url = oferta.Url d.BlobKey = oferta.BlobKey //} b, _ = json.Marshal(d) item := &memcache.Item{ Key: "d_" + r.FormValue("id"), Value: b, Expiration: time.Duration(timetolive) * time.Second, } if err := memcache.Add(c, item); err == memcache.ErrNotStored { c.Errorf("Memcache.Add d_idoft : %v", err) } } else { w.WriteHeader(http.StatusNotFound) return } } else { //c.Infof("memcache retrieve d_idoft : %v", r.FormValue("id")) if err := json.Unmarshal(item.Value, &d); err != nil { c.Errorf("Unmarshaling ShortLogo item: %v", err) http.Error(w, err.Error(), http.StatusInternalServerError) w.WriteHeader(http.StatusNotFound) return } } blobstore.Send(w, d.BlobKey) /* if url, err := image.ServingURL(c, d.BlobKey, &imgprops); err != nil { c.Errorf("Cannot construct ServingURL : %v", r.FormValue("id")) blobstore.Send(w, d.BlobKey) } else { http.Redirect(w, r, url.String(), http.StatusFound) } */ } else { /* Cuando es un BlobKey */ //c.Infof("Blob : %v", r.FormValue("id")) blobstore.Send(w, appengine.BlobKey(r.FormValue("id"))) /* if url, err := image.ServingURL(c, appengine.BlobKey(r.FormValue("id")), &imgprops); err != nil { c.Infof("Cannot construct ServingURL : %v", r.FormValue("id")) blobstore.Send(w, appengine.BlobKey(r.FormValue("id"))) } else { http.Redirect(w, r, url.String(), http.StatusFound) } */ } } }
func blob(w http.ResponseWriter, r *http.Request) { elements := strings.Split(r.URL.Path, "/") blobKey := appengine.BlobKey(elements[len(elements)-1]) blobstore.Send(w, blobKey) }
func showAttachment(w http.ResponseWriter, r *http.Request) { args := r.URL.Query() rawKey := args.Get("key") blobstore.Send(w, appengine.BlobKey(rawKey)) }
func nutShowHandler(c appengine.Context, w http.ResponseWriter, r *http.Request) { d := make(ContentData) getNut := r.Header.Get("Accept") == "application/zip" vendor := r.URL.Query().Get(":vendor") name := r.URL.Query().Get(":name") ver := r.URL.Query().Get(":version") if vendor == "" || !nutp.VendorRegexp.MatchString(vendor) || name == "" || (ver != "" && !nutp.VersionRegexp.MatchString(ver)) { err := fmt.Errorf("Invalid vendor %q, name %q or version %q.", vendor, name, ver) ServeJSONError(w, http.StatusBadRequest, err, d) return } current := new(gonuts.Version) var err error q := datastore.NewQuery("Version").Filter("Vendor=", vendor).Filter("Name=", name) if ver == "" { _, err = q.Order("-VersionNum").Limit(1).Run(c).Next(current) } else { key := gonuts.VersionKey(c, vendor, name, ver) err = datastore.Get(c, key, current) } gonuts.LogError(c, err) var title string if current.BlobKey != "" { // send nut file and exit if getNut { current.Downloads++ key := gonuts.VersionKey(c, current.Vendor, current.Name, current.Version) _, err := datastore.Put(c, key, current) gonuts.LogError(c, err) blobstore.Send(w, current.BlobKey) return } // find all versions var all []gonuts.Version _, err = q.Order("-CreatedAt").GetAll(c, &all) gonuts.LogError(c, err) // prepare data for template cm := make(map[string]interface{}) cm["Vendor"] = current.Vendor cm["Name"] = current.Name cm["Version"] = current.Version cm["Doc"] = current.Doc cm["Homepage"] = current.Homepage d["Current"] = cm d["All"] = all title = fmt.Sprintf("%s/%s %s", current.Vendor, current.Name, current.Version) } else { w.WriteHeader(http.StatusNotFound) if getNut { return } title = fmt.Sprintf("Nut %s/%s version %s not found", vendor, name, ver) } var content bytes.Buffer gonuts.PanicIfErr(Base.ExecuteTemplate(&content, "nut.html", d)) bd := BaseData{ Tabtitle: title, Title: title, Content: template.HTML(content.String()), } gonuts.PanicIfErr(Base.Execute(w, &bd)) }
//for serving images, using the blobkey we stored in the datastore func serve(w http.ResponseWriter, r *http.Request) { blobstore.Send(w, appengine.BlobKey(r.FormValue("blobKey"))) }
// Handles the serving of Uploads func handleServe(w http.ResponseWriter, r *http.Request) { trimPath := strings.Trim(r.URL.Path, "/download/") key := strings.Split(trimPath, "/") blobstore.Send(w, appengine.BlobKey(key[0])) }
func fileGet(w http.ResponseWriter, r *http.Request, file string) { blobstore.Send(w, appengine.BlobKey(file)) }
func Serve(rw http.ResponseWriter, req *http.Request, params martini.Params) { blobstore.Send(rw, appengine.BlobKey(params["id"])) return }
func (fileStore *blobstoreFileStore) WriteFile(w http.ResponseWriter, key string) { blobstore.Send(w, appengine.BlobKey(key)) }