forked from tangled.org/core
this repo has no description

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
··· 375 if !rp.config.Core.Dev { 376 protocol = "https" 377 } 378 resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/tree/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, treePath)) 379 if err != nil { 380 log.Println("failed to reach knotserver", err) 381 return 382 } 383 ··· 525 resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/blob/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, filePath)) 526 if err != nil { 527 log.Println("failed to reach knotserver", err) 528 return 529 } 530
··· 375 if !rp.config.Core.Dev { 376 protocol = "https" 377 } 378 + 379 + // if the tree path has a trailing slash, let's strip it 380 + // so we don't 404 381 + treePath = strings.TrimSuffix(treePath, "/") 382 + 383 resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/tree/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, treePath)) 384 if err != nil { 385 log.Println("failed to reach knotserver", err) 386 + return 387 + } 388 + 389 + // uhhh so knotserver returns a 500 if the entry isn't found in 390 + // the requested tree path, so let's stick to not-OK here. 391 + // we can fix this once we build out the xrpc apis for these operations. 392 + if resp.StatusCode != http.StatusOK { 393 + rp.pages.Error404(w) 394 return 395 } 396 ··· 538 resp, err := http.Get(fmt.Sprintf("%s://%s/%s/%s/blob/%s/%s", protocol, f.Knot, f.OwnerDid(), f.Repo.Name, ref, filePath)) 539 if err != nil { 540 log.Println("failed to reach knotserver", err) 541 + return 542 + } 543 + 544 + if resp.StatusCode == http.StatusNotFound { 545 + rp.pages.Error404(w) 546 return 547 } 548