MCPcopy Index your code
hub / github.com/perkeep/perkeep / ServeHTTP

Method ServeHTTP

pkg/server/filetree.go:51–88  ·  view source on GitHub ↗
(rw http.ResponseWriter, req *http.Request)

Source from the content-addressed store, hash-verified

49}
50
51func (fth *FileTreeHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
52 ctx := req.Context()
53 if req.Method != "GET" && req.Method != "HEAD" {
54 http.Error(rw, "Invalid method", http.StatusBadRequest)
55 return
56 }
57
58 de, err := schema.NewDirectoryEntryFromBlobRef(ctx, fth.Fetcher, fth.file)
59 if err != nil {
60 http.Error(rw, "Error reading directory", 500)
61 log.Printf("Error reading directory from blobref %s: %v\n", fth.file, err)
62 return
63 }
64 dir, err := de.Directory(ctx)
65 if err != nil {
66 http.Error(rw, "Error reading directory", 500)
67 log.Printf("Error reading directory from blobref %s: %v\n", fth.file, err)
68 return
69 }
70 entries, err := dir.Readdir(ctx, -1)
71 if err != nil {
72 http.Error(rw, "Error reading directory", 500)
73 log.Printf("reading dir from blobref %s: %v\n", fth.file, err)
74 return
75 }
76
77 var ret = FileTreeResponse{
78 Children: make([]FileTreeNode, 0, len(entries)),
79 }
80 for _, v := range entries {
81 ret.Children = append(ret.Children, FileTreeNode{
82 Name: v.FileName(),
83 Type: v.CamliType(),
84 BlobRef: v.BlobRef(),
85 })
86 }
87 httputil.ReturnJSON(rw, ret)
88}

Callers 1

serveFileTreeMethod · 0.95

Calls 10

ReturnJSONFunction · 0.92
ContextMethod · 0.80
PrintfMethod · 0.80
DirectoryMethod · 0.65
ReaddirMethod · 0.65
FileNameMethod · 0.65
CamliTypeMethod · 0.65
BlobRefMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected