forked from
tangled.org/core
fork
Configure Feed
Select the types of activity you want to include in your feed.
this repo has no description
fork
Configure Feed
Select the types of activity you want to include in your feed.
1package state
2
3import (
4 "fmt"
5 "io"
6 "net/http"
7
8 "github.com/bluesky-social/indigo/atproto/identity"
9 "github.com/go-chi/chi/v5"
10)
11
12func (s *State) InfoRefs(w http.ResponseWriter, r *http.Request) {
13 user := r.Context().Value("resolvedId").(identity.Identity)
14 knot := r.Context().Value("knot").(string)
15 repo := chi.URLParam(r, "repo")
16
17 scheme := "https"
18 if s.config.Dev {
19 scheme = "http"
20 }
21 targetURL := fmt.Sprintf("%s://%s/%s/%s/info/refs?%s", scheme, knot, user.DID, repo, r.URL.RawQuery)
22 resp, err := http.Get(targetURL)
23 if err != nil {
24 http.Error(w, err.Error(), http.StatusInternalServerError)
25 return
26 }
27 defer resp.Body.Close()
28
29 // Copy response headers
30 for k, v := range resp.Header {
31 w.Header()[k] = v
32 }
33
34 // Set response status code
35 w.WriteHeader(resp.StatusCode)
36
37 // Copy response body
38 if _, err := io.Copy(w, resp.Body); err != nil {
39 http.Error(w, err.Error(), http.StatusInternalServerError)
40 return
41 }
42
43}
44
45func (s *State) UploadPack(w http.ResponseWriter, r *http.Request) {
46 user, ok := r.Context().Value("resolvedId").(identity.Identity)
47 if !ok {
48 http.Error(w, "failed to resolve user", http.StatusInternalServerError)
49 return
50 }
51 knot := r.Context().Value("knot").(string)
52 repo := chi.URLParam(r, "repo")
53
54 scheme := "https"
55 if s.config.Dev {
56 scheme = "http"
57 }
58 targetURL := fmt.Sprintf("%s://%s/%s/%s/git-upload-pack?%s", scheme, knot, user.DID, repo, r.URL.RawQuery)
59 client := &http.Client{}
60
61 // Create new request
62 proxyReq, err := http.NewRequest(r.Method, targetURL, r.Body)
63 if err != nil {
64 http.Error(w, err.Error(), http.StatusInternalServerError)
65 return
66 }
67
68 // Copy original headers
69 proxyReq.Header = r.Header
70
71 // Execute request
72 resp, err := client.Do(proxyReq)
73 if err != nil {
74 http.Error(w, err.Error(), http.StatusInternalServerError)
75 return
76 }
77 defer resp.Body.Close()
78
79 // Copy response headers
80 for k, v := range resp.Header {
81 w.Header()[k] = v
82 }
83
84 // Set response status code
85 w.WriteHeader(resp.StatusCode)
86
87 // Copy response body
88 if _, err := io.Copy(w, resp.Body); err != nil {
89 http.Error(w, err.Error(), http.StatusInternalServerError)
90 return
91 }
92}