diff options
author | 2023-06-17 17:49:11 +0200 | |
---|---|---|
committer | 2023-06-17 16:49:11 +0100 | |
commit | d8e16a226a570a7d262bdeb067273ce35b03cc7c (patch) | |
tree | 94a09ebe5501c01159efb8aa3e74d70da8db2f87 /internal/typeutils/util.go | |
parent | [bugfix] Accept non-multipart forms for account updates (#1896) (diff) | |
download | gotosocial-d8e16a226a570a7d262bdeb067273ce35b03cc7c.tar.xz |
[chore/bugfix] Refactor `ap/extract.go` functions, return URIs more reliably (#1897)
Diffstat (limited to 'internal/typeutils/util.go')
-rw-r--r-- | internal/typeutils/util.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/internal/typeutils/util.go b/internal/typeutils/util.go index bd6c33ee1..0100200dc 100644 --- a/internal/typeutils/util.go +++ b/internal/typeutils/util.go @@ -19,9 +19,11 @@ package typeutils import ( "context" + "errors" "fmt" "net/url" + "github.com/superseriousbusiness/gotosocial/internal/ap" "github.com/superseriousbusiness/gotosocial/internal/gtsmodel" "github.com/superseriousbusiness/gotosocial/internal/regexes" ) @@ -82,3 +84,19 @@ func misskeyReportInlineURLs(content string) []*url.URL { } return urls } + +// getURI is a shortcut/util function for extracting +// the JSONLDId URI of an Activity or Object. +func getURI(withID ap.WithJSONLDId) (*url.URL, string, error) { + idProp := withID.GetJSONLDId() + if idProp == nil { + return nil, "", errors.New("id prop was nil") + } + + if !idProp.IsIRI() { + return nil, "", errors.New("id prop was not an IRI") + } + + id := idProp.Get() + return id, id.String(), nil +} |