Move stuff, keep working on authenticated fetch
All checks were successful
/ docker (push) Successful in 4m5s
All checks were successful
/ docker (push) Successful in 4m5s
This commit is contained in:
parent
f8b3a6ff06
commit
e3a97170a9
11 changed files with 81 additions and 39 deletions
|
@ -1,4 +1,4 @@
|
|||
package types
|
||||
package activitypub
|
||||
|
||||
var BaseLdContext = []any{
|
||||
"https://www.w3.org/ns/activitystreams",
|
|
@ -4,13 +4,12 @@ import (
|
|||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"git.mstar.dev/mstar/goutils/other"
|
||||
"git.mstar.dev/mstar/goutils/sliceutils"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
apshared "git.mstar.dev/mstar/linstrom/activitypub/shared"
|
||||
"git.mstar.dev/mstar/linstrom/config"
|
||||
"git.mstar.dev/mstar/linstrom/storage-new/dbgen"
|
||||
webshared "git.mstar.dev/mstar/linstrom/web/shared"
|
||||
|
@ -47,18 +46,18 @@ func ImportRemoteAccount(targetName string) (string, error) {
|
|||
RestrictedFollow *bool `json:"manuallyApprovesFollowers"`
|
||||
}
|
||||
// Get the target user's link first
|
||||
webfinger, err := apshared.GetAccountWebfinger(targetName)
|
||||
webfinger, err := GetAccountWebfinger(targetName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", other.Error("activitypub", "webfinger request failed", err)
|
||||
}
|
||||
selfLinks := sliceutils.Filter(webfinger.Links, func(t apshared.LinkData) bool {
|
||||
selfLinks := sliceutils.Filter(webfinger.Links, func(t LinkData) bool {
|
||||
return t.Relation == "self"
|
||||
})
|
||||
if len(selfLinks) == 0 {
|
||||
return "", errors.New("No self link")
|
||||
}
|
||||
APLink := selfLinks[0]
|
||||
req, err := http.NewRequest("GET", *APLink.Href, nil)
|
||||
req, err := webshared.NewRequest("GET", *APLink.Href, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -86,12 +85,16 @@ func ImportRemoteAccount(targetName string) (string, error) {
|
|||
return "", err
|
||||
}
|
||||
defer response.Body.Close()
|
||||
body, _ := io.ReadAll(response.Body)
|
||||
log.Debug().
|
||||
Int("status", response.StatusCode).
|
||||
Bytes("body", body).
|
||||
Any("headers", response.Header).
|
||||
Msg("Response information")
|
||||
if response.StatusCode != 200 {
|
||||
return "", errors.New("Bad status")
|
||||
}
|
||||
var data InboundUser
|
||||
body, _ := io.ReadAll(response.Body)
|
||||
log.Info().Bytes("body", body).Msg("Body from request")
|
||||
err = json.Unmarshal(body, &data)
|
||||
if err != nil {
|
||||
return "", err
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package apshared
|
||||
package activitypub
|
||||
|
||||
import "strings"
|
||||
|
|
@ -1,10 +1,9 @@
|
|||
package apshared
|
||||
package activitypub
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
|
||||
webshared "git.mstar.dev/mstar/linstrom/web/shared"
|
||||
)
|
||||
|
@ -44,7 +43,7 @@ func GetAccountWebfinger(fullHandle string) (*WebfingerData, error) {
|
|||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
webfingerRequest, err := http.NewRequest(
|
||||
webfingerRequest, err := webshared.NewRequest(
|
||||
// Webfinger requests are GET
|
||||
"GET",
|
||||
// The webfinger url is located at <domain>/.well-known/webfinger
|
Loading…
Add table
Add a link
Reference in a new issue