Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use correct hostname for URLs in response #7

Merged
merged 1 commit into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading