MCPcopy
hub / github.com/perkeep/perkeep / handleResource

Method handleResource

app/scanningcabinet/handler.go:415–457  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

413}
414
415func (h *handler) handleResource(w http.ResponseWriter, r *http.Request) {
416 m := resourcePattern.FindStringSubmatch(r.URL.Path)
417 if m == nil {
418 http.Error(w, "invalid resource URL", http.StatusBadRequest)
419 return
420 }
421 scanRef, ok := blob.Parse(m[1])
422 if !ok {
423 http.Error(w, fmt.Sprintf("invalid resource blobref: %q", m[1]), http.StatusBadRequest)
424 return
425 }
426
427 mediaObject, err := h.fetchScan(scanRef)
428 if err != nil {
429 if err == os.ErrNotExist {
430 http.Error(w, fmt.Sprintf("%v not found", scanRef), http.StatusNotFound)
431 return
432 }
433 httputil.ServeError(w, r, fmt.Errorf("resource %v not found: %v", scanRef, err))
434 return
435 }
436
437 // TODO(mpl): cache and thumbmeta
438 ih := &camliserver.ImageHandler{
439 Fetcher: h.cl,
440 MaxWidth: search.MaxImageSize,
441 MaxHeight: search.MaxImageSize,
442 Square: false,
443 // TODO(mpl): make the image pkg default to the below when ResizeSem is nil
444 ResizeSem: syncutil.NewSem(constants.DefaultMaxResizeMem),
445 }
446
447 if resizeParam := r.FormValue("resize"); resizeParam != "" {
448 resized, err := strconv.Atoi(resizeParam)
449 if err != nil {
450 httputil.ServeError(w, r, fmt.Errorf("bogus resize param %q: %v", resizeParam, err))
451 return
452 }
453 ih.MaxWidth = resized
454 ih.MaxHeight = resized
455 }
456 ih.ServeHTTP(w, r, mediaObject.contentRef)
457}
458
459func (h *handler) handleMakedoc(w http.ResponseWriter, r *http.Request) {
460 ctx := r.Context()

Callers

nothing calls this directly

Calls 5

fetchScanMethod · 0.95
ServeHTTPMethod · 0.95
ParseFunction · 0.92
ServeErrorFunction · 0.92
ErrorMethod · 0.45

Tested by

no test coverage detected