mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-20 09:14:16 +00:00
implement HandleGetLatestCommit
This commit is contained in:
@@ -135,6 +135,12 @@ const (
|
||||
// Response: {"did": "...", "active": true, "rev": "..."}
|
||||
SyncGetRepoStatus = "/xrpc/com.atproto.sync.getRepoStatus"
|
||||
|
||||
// SyncGetLatestCommit gets the current commit CID and revision for a repository.
|
||||
// Method: GET
|
||||
// Query: did={did}
|
||||
// Response: {"cid": "...", "rev": "..."}
|
||||
SyncGetLatestCommit = "/xrpc/com.atproto.sync.getLatestCommit"
|
||||
|
||||
// SyncGetHostStatus gets the hosting/crawl status for a hostname on a relay.
|
||||
// Method: GET
|
||||
// Query: hostname={hostname}
|
||||
|
||||
@@ -169,6 +169,7 @@ func (h *XRPCHandler) RegisterHandlers(r chi.Router) {
|
||||
r.Get(atproto.SyncGetRecord, h.HandleSyncGetRecord)
|
||||
r.Get(atproto.SyncGetRepo, h.HandleGetRepo)
|
||||
r.Get(atproto.SyncGetRepoStatus, h.HandleGetRepoStatus)
|
||||
r.Get(atproto.SyncGetLatestCommit, h.HandleGetLatestCommit)
|
||||
r.Get(atproto.SyncSubscribeRepos, h.HandleSubscribeRepos)
|
||||
|
||||
// DID document and handle resolution
|
||||
@@ -1294,6 +1295,38 @@ func (h *XRPCHandler) HandleGetRepoStatus(w http.ResponseWriter, r *http.Request
|
||||
})
|
||||
}
|
||||
|
||||
// HandleGetLatestCommit returns the current commit CID and revision for a repository.
|
||||
// Spec: https://docs.bsky.app/docs/api/com-atproto-sync-get-latest-commit
|
||||
func (h *XRPCHandler) HandleGetLatestCommit(w http.ResponseWriter, r *http.Request) {
|
||||
did := r.URL.Query().Get("did")
|
||||
if did == "" {
|
||||
http.Error(w, "missing required parameter: did", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if did != h.pds.DID() {
|
||||
http.Error(w, "RepoNotFound", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
head, err := h.pds.repomgr.GetRepoRoot(r.Context(), h.pds.uid)
|
||||
if err != nil {
|
||||
http.Error(w, "RepoNotFound", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
rev, err := h.pds.repomgr.GetRepoRev(r.Context(), h.pds.uid)
|
||||
if err != nil || rev == "" {
|
||||
http.Error(w, "RepoNotFound", http.StatusNotFound)
|
||||
return
|
||||
}
|
||||
|
||||
render.JSON(w, r, map[string]any{
|
||||
"cid": head.String(),
|
||||
"rev": rev,
|
||||
})
|
||||
}
|
||||
|
||||
// HandleDIDDocument returns the DID document
|
||||
func (h *XRPCHandler) HandleDIDDocument(w http.ResponseWriter, r *http.Request) {
|
||||
doc, err := h.pds.GenerateDIDDocument(h.pds.PublicURL)
|
||||
|
||||
Reference in New Issue
Block a user