MCPcopy
hub / github.com/perkeep/perkeep / serveThumbnail

Method serveThumbnail

pkg/server/ui.go:547–586  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

545}
546
547func (ui *UIHandler) serveThumbnail(rw http.ResponseWriter, req *http.Request) {
548 if ui.root.Storage == nil {
549 http.Error(rw, "No BlobRoot configured", 500)
550 return
551 }
552
553 suffix := httputil.PathSuffix(req)
554 m := thumbnailPattern.FindStringSubmatch(suffix)
555 if m == nil {
556 httputil.ErrorRouting(rw, req)
557 return
558 }
559
560 query := req.URL.Query()
561 width, _ := strconv.Atoi(query.Get("mw"))
562 height, _ := strconv.Atoi(query.Get("mh"))
563 blobref, ok := blob.Parse(m[1])
564 if !ok {
565 http.Error(rw, "Invalid blobref", http.StatusBadRequest)
566 return
567 }
568
569 if width == 0 {
570 width = search.MaxImageSize
571 }
572 if height == 0 {
573 height = search.MaxImageSize
574 }
575
576 th := &ImageHandler{
577 Fetcher: ui.root.Storage,
578 Cache: ui.Cache,
579 MaxWidth: width,
580 MaxHeight: height,
581 ThumbMeta: ui.thumbMeta,
582 ResizeSem: ui.resizeSem,
583 Search: ui.search,
584 }
585 th.ServeHTTP(rw, req, blobref)
586}
587
588func (ui *UIHandler) serveFileTree(rw http.ResponseWriter, req *http.Request) {
589 if ui.root.Storage == nil {

Callers 1

ServeHTTPMethod · 0.95

Calls 7

ServeHTTPMethod · 0.95
PathSuffixFunction · 0.92
ErrorRoutingFunction · 0.92
ParseFunction · 0.92
QueryMethod · 0.65
GetMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected