Skip to content
This repository has been archived by the owner on Jan 2, 2025. It is now read-only.

Commit

Permalink
wip(sites): get well-known info from db
Browse files Browse the repository at this point in the history
  • Loading branch information
juligasa committed Sep 15, 2023
1 parent 4a463fd commit d3c8d98
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 505 deletions.
25 changes: 24 additions & 1 deletion backend/cmd/mintter-site/sites/sites.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func (ws *Website) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
// TODO(juligasa): get GroupID and version from DB, include new keys in db meta and store that value whenever
// we update the site and the initial InitializeServer (to be done as well)

resp := &groups.PublicSiteInfo{
PeerInfo: &groups.PeerInfo{},
GroupId: "",
Expand All @@ -48,6 +49,28 @@ func (ws *Website) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
resp.PeerInfo.PeerId = n.ID().DeviceKey().PeerID().String()
resp.PeerInfo.AccountId = n.ID().Account().ID().String()

conn, release, err := ws.DB.Conn(context.Background())
if err != nil {
http.Error(w, "Failed to get db connection: "+err.Error(), http.StatusInternalServerError)
return
}
defer release()

eid, err := sitesql.GetSiteGroupID(conn)
if err != nil {
http.Error(w, "Failed to get group id from the db: "+err.Error(), http.StatusInternalServerError)
return
}
resp.GroupId = eid.KVValue

version, err := sitesql.GetSiteGroupVersion(conn)
if err != nil {
http.Error(w, "Failed to get group version from the db: "+err.Error(), http.StatusInternalServerError)
return
}
resp.GroupVersion = version.KVValue

data, err := protojson.Marshal(resp)
if err != nil {
http.Error(w, "Failed to marshal site info: "+err.Error(), http.StatusInternalServerError)
Expand All @@ -67,7 +90,7 @@ func (ws *Website) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (ws *Website) RegisterSite(ctx context.Context, hostname string) (link string, err error) {
conn, release, err := ws.DB.Conn(ctx)
if err != nil {
panic(err)
return "", err
}
defer release()
if err = func() error {
Expand Down
Loading

0 comments on commit d3c8d98

Please sign in to comment.