Skip to content

Commit

Permalink
Use correct hostname for URLs in response
Browse files Browse the repository at this point in the history
Add host parameter to NewUser and ConvertUserToApub functions
  • Loading branch information
lazyguru committed Nov 27, 2023
1 parent 3379554 commit f66b4cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
10 changes: 3 additions & 7 deletions internal/activitypub/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ package activitypub

import (
"fmt"
"os"
"participating-online/sublinks-federation/internal/lemmy"
"time"
)

var host, _ = os.LookupEnv("HOSTNAME")
var domain, _ = os.LookupEnv("CSB_BASE_PREVIEW_HOST")
var Hostname string = fmt.Sprintf("%s-8080.%s", host, domain)

type PublicKey struct {
Keyid string `json:"id"`
Owner string `json:"owner"`
Expand Down Expand Up @@ -38,7 +33,7 @@ type User struct {
Endpoints Endpoints `json:"endpoints"`
}

func NewUser(name string, matrixUserId string, bio string, publickey string) User {
func NewUser(name string, matrixUserId string, bio string, publickey string, Hostname string) User {
user := User{}
user.Context = GetContext()
user.Id = fmt.Sprintf("https://%s/users/%s", Hostname, name)
Expand All @@ -59,11 +54,12 @@ func NewUser(name string, matrixUserId string, bio string, publickey string) Use
return user
}

func ConvertUserToApub(u *lemmy.UserResponse) User {
func ConvertUserToApub(u *lemmy.UserResponse, host string) User {
return NewUser(
u.PersonView.Person.Name,
u.PersonView.Person.MatrixUserId,
u.PersonView.Person.Bio,
"", //TODO: Public key goes here
host,
)
}
2 changes: 1 addition & 1 deletion internal/http/routes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func getUserInfoHandler(w http.ResponseWriter, r *http.Request) {
return
}

userLd := activitypub.ConvertUserToApub(user)
userLd := activitypub.ConvertUserToApub(user, r.Host)
w.WriteHeader(http.StatusOK)
w.Header().Add("content-type", "application/activity+json")
content, _ := json.MarshalIndent(userLd, "", " ")
Expand Down

0 comments on commit f66b4cd

Please sign in to comment.