forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview/repo: serve appropriate 404s for non-existent files/dirs

Signed-off-by: Anirudh Oppiliappan <anirudh@tangled.sh>

anirudh.fi f4b2c850 a7d7a96a

verified
Changed files
+18
appview
repo
+18
appview/repo/repo.go
···
if !rp.config.Core.Dev {
protocol = "https"
}
+
+
// if the tree path has a trailing slash, let's strip it
+
// so we don't 404
+
treePath = strings.TrimSuffix(treePath, "/")
+
resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/tree/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, treePath))
if err != nil {
log.Println("failed to reach knotserver", err)
+
return
+
}
+
+
// uhhh so knotserver returns a 500 if the entry isn't found in
+
// the requested tree path, so let's stick to not-OK here.
+
// we can fix this once we build out the xrpc apis for these operations.
+
if resp.StatusCode != http.StatusOK {
+
rp.pages.Error404(w)
return
}
···
resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/blob/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, filePath))
if err != nil {
log.Println("failed to reach knotserver", err)
+
return
+
}
+
+
if resp.StatusCode == http.StatusNotFound {
+
rp.pages.Error404(w)
return
}