grasp: pass request context to repoExists().
This commit is contained in:
@@ -148,8 +148,8 @@ func (gs *GraspServer) getRepositoryPath(pubkey nostr.PubKey, repoName string) s
|
|||||||
}
|
}
|
||||||
|
|
||||||
// repoExists checks if a repository has an announcement event (kind 30617)
|
// repoExists checks if a repository has an announcement event (kind 30617)
|
||||||
func (gs *GraspServer) repoExists(pubkey nostr.PubKey, repoName string) bool {
|
func (gs *GraspServer) repoExists(ctx context.Context, pubkey nostr.PubKey, repoName string) bool {
|
||||||
for range gs.Relay.QueryStored(context.Background(), nostr.Filter{
|
for range gs.Relay.QueryStored(ctx, nostr.Filter{
|
||||||
Kinds: []nostr.Kind{nostr.KindRepositoryAnnouncement},
|
Kinds: []nostr.Kind{nostr.KindRepositoryAnnouncement},
|
||||||
Authors: []nostr.PubKey{pubkey},
|
Authors: []nostr.PubKey{pubkey},
|
||||||
Tags: nostr.TagMap{"d": []string{repoName}},
|
Tags: nostr.TagMap{"d": []string{repoName}},
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ func (gs *GraspServer) handleInfoRefs(
|
|||||||
pubkey nostr.PubKey,
|
pubkey nostr.PubKey,
|
||||||
repoName string,
|
repoName string,
|
||||||
) {
|
) {
|
||||||
if !gs.repoExists(pubkey, repoName) {
|
if !gs.repoExists(r.Context(), pubkey, repoName) {
|
||||||
w.Header().Set("content-type", "text/plain; charset=UTF-8")
|
w.Header().Set("content-type", "text/plain; charset=UTF-8")
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
fmt.Fprintf(w, "repository announcement event not found during info-refs\n")
|
fmt.Fprintf(w, "repository announcement event not found during info-refs\n")
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func (gs *GraspServer) handleGitUploadPack(
|
|||||||
repoPath := gs.getRepositoryPath(pubkey, repoName)
|
repoPath := gs.getRepositoryPath(pubkey, repoName)
|
||||||
|
|
||||||
// for upload-pack (pull), check if repository exists
|
// for upload-pack (pull), check if repository exists
|
||||||
if !gs.repoExists(pubkey, repoName) {
|
if !gs.repoExists(r.Context(), pubkey, repoName) {
|
||||||
w.Header().Set("content-type", "text/plain; charset=UTF-8")
|
w.Header().Set("content-type", "text/plain; charset=UTF-8")
|
||||||
w.WriteHeader(404)
|
w.WriteHeader(404)
|
||||||
fmt.Fprintf(w, "repository announcement event not found during upload-pack\n")
|
fmt.Fprintf(w, "repository announcement event not found during upload-pack\n")
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ func New(rl *khatru.Relay, repositoryDir string) *GraspServer {
|
|||||||
mux.HandleFunc("GET /{npub}/{repo}", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("GET /{npub}/{repo}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
gs.handleGitRequest(w, r, base, func(w http.ResponseWriter, r *http.Request, pubkey nostr.PubKey, repoName string) {
|
gs.handleGitRequest(w, r, base, func(w http.ResponseWriter, r *http.Request, pubkey nostr.PubKey, repoName string) {
|
||||||
if r.URL.RawQuery == "" {
|
if r.URL.RawQuery == "" {
|
||||||
if gs.repoExists(pubkey, repoName) {
|
if gs.repoExists(r.Context(), pubkey, repoName) {
|
||||||
gs.serveRepoPage(w, r, r.PathValue("npub"), repoName)
|
gs.serveRepoPage(w, r, r.PathValue("npub"), repoName)
|
||||||
} else {
|
} else {
|
||||||
http.NotFound(w, r)
|
http.NotFound(w, r)
|
||||||
|
|||||||
Reference in New Issue
Block a user