Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a8df9b800 | ||
|
|
4d41677a7a | ||
|
|
f6707f32ea | ||
|
|
f286ddb713 | ||
|
|
52f92a2d92 | ||
|
|
9ef186bf73 | ||
|
|
91ebade091 | ||
|
|
e4cf634040 | ||
|
|
25d52df9a3 | ||
|
|
e9abfc34c1 | ||
|
|
d73d983f32 | ||
|
|
84d7479954 | ||
|
|
b6521cded2 | ||
|
|
180136e6db | ||
|
|
a0c5600cc3 | ||
|
|
dd08b71215 | ||
|
|
6caf274300 |
@@ -4,14 +4,20 @@ package activitystreams
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/writeas/web-core/id"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Namespace = "https://www.w3.org/ns/activitystreams"
|
Namespace = "https://www.w3.org/ns/activitystreams"
|
||||||
toPublic = "https://www.w3.org/ns/activitystreams#Public"
|
ToPublic = "https://www.w3.org/ns/activitystreams#Public"
|
||||||
)
|
)
|
||||||
|
|
||||||
var Extensions = map[string]string{}
|
var (
|
||||||
|
Extensions = map[string]string{}
|
||||||
|
|
||||||
|
apMonetizationContext = "https://webmonetization.org/ns.jsonld"
|
||||||
|
)
|
||||||
|
|
||||||
// Activity describes actions that have either already occurred, are in the
|
// Activity describes actions that have either already occurred, are in the
|
||||||
// process of occurring, or may occur in the future.
|
// process of occurring, or may occur in the future.
|
||||||
@@ -75,6 +81,40 @@ func NewUpdateActivity(o *Object) *Activity {
|
|||||||
return &a
|
return &a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ActorActivity describes an action whose object is a full actor (Person),
|
||||||
|
// such as an Update to a profile's name, summary, or icon. It parallels
|
||||||
|
// Activity, which instead carries a content *Object.
|
||||||
|
type ActorActivity struct {
|
||||||
|
BaseObject
|
||||||
|
Actor string `json:"actor"`
|
||||||
|
Updated *time.Time `json:"updated,omitempty"`
|
||||||
|
To []string `json:"to,omitempty"`
|
||||||
|
CC []string `json:"cc,omitempty"`
|
||||||
|
Object *Person `json:"object"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUpdateActorActivity builds an Update activity whose object is the given
|
||||||
|
// actor (Person), used to federate profile changes such as the actor's name,
|
||||||
|
// summary, or icon. It addresses the public namespace and CCs the actor's
|
||||||
|
// followers collection. The activity gets a unique ID derived from the actor's
|
||||||
|
// IRI so remote instances don't dedupe repeated updates against one another.
|
||||||
|
func NewUpdateActorActivity(p *Person) *ActorActivity {
|
||||||
|
a := ActorActivity{
|
||||||
|
BaseObject: BaseObject{
|
||||||
|
Context: []interface{}{
|
||||||
|
Namespace,
|
||||||
|
},
|
||||||
|
ID: p.ID + "#update-" + id.GenerateFriendlyRandomString(20),
|
||||||
|
Type: "Update",
|
||||||
|
},
|
||||||
|
Actor: p.ID,
|
||||||
|
To: []string{ToPublic},
|
||||||
|
CC: []string{p.Followers},
|
||||||
|
Object: p,
|
||||||
|
}
|
||||||
|
return &a
|
||||||
|
}
|
||||||
|
|
||||||
// NewDeleteActivity builds a basic Delete activity that includes the given
|
// NewDeleteActivity builds a basic Delete activity that includes the given
|
||||||
// Object and the Object's AttributedTo property as the Actor.
|
// Object and the Object's AttributedTo property as the Actor.
|
||||||
func NewDeleteActivity(o *Object) *Activity {
|
func NewDeleteActivity(o *Object) *Activity {
|
||||||
@@ -136,7 +176,7 @@ type Object struct {
|
|||||||
Endpoints *Endpoints `json:"endpoints,omitempty"`
|
Endpoints *Endpoints `json:"endpoints,omitempty"`
|
||||||
|
|
||||||
// Extensions
|
// Extensions
|
||||||
// NOTE: add extensions here
|
Monetization string `json:"monetization,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNoteObject creates a basic Note object that includes the public
|
// NewNoteObject creates a basic Note object that includes the public
|
||||||
@@ -145,9 +185,12 @@ func NewNoteObject() *Object {
|
|||||||
o := Object{
|
o := Object{
|
||||||
BaseObject: BaseObject{
|
BaseObject: BaseObject{
|
||||||
Type: "Note",
|
Type: "Note",
|
||||||
|
Context: []interface{}{
|
||||||
|
Namespace,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
To: []string{
|
To: []string{
|
||||||
toPublic,
|
ToPublic,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return &o
|
return &o
|
||||||
@@ -159,9 +202,12 @@ func NewArticleObject() *Object {
|
|||||||
o := Object{
|
o := Object{
|
||||||
BaseObject: BaseObject{
|
BaseObject: BaseObject{
|
||||||
Type: "Article",
|
Type: "Article",
|
||||||
|
Context: []interface{}{
|
||||||
|
Namespace,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
To: []string{
|
To: []string{
|
||||||
toPublic,
|
ToPublic,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return &o
|
return &o
|
||||||
@@ -172,7 +218,15 @@ func NewPersonObject() *Object {
|
|||||||
o := Object{
|
o := Object{
|
||||||
BaseObject: BaseObject{
|
BaseObject: BaseObject{
|
||||||
Type: "Person",
|
Type: "Person",
|
||||||
|
Context: []interface{}{
|
||||||
|
Namespace,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
return &o
|
return &o
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (o *Object) AddWebMonetization(wallet string) {
|
||||||
|
o.Context = append(o.Context, apMonetizationContext)
|
||||||
|
o.Monetization = wallet
|
||||||
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ type (
|
|||||||
type OrderedCollection struct {
|
type OrderedCollection struct {
|
||||||
BaseObject
|
BaseObject
|
||||||
TotalItems int `json:"totalItems"`
|
TotalItems int `json:"totalItems"`
|
||||||
First string `json:"first"`
|
First string `json:"first,omitempty"`
|
||||||
Last string `json:"last,omitempty"`
|
Last string `json:"last,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,9 +43,13 @@ func NewOrderedCollection(accountRoot, collType string, items int) *OrderedColle
|
|||||||
ID: accountRoot + "/" + collType,
|
ID: accountRoot + "/" + collType,
|
||||||
Type: "OrderedCollection",
|
Type: "OrderedCollection",
|
||||||
},
|
},
|
||||||
First: accountRoot + "/" + collType + "?page=1",
|
|
||||||
TotalItems: items,
|
TotalItems: items,
|
||||||
}
|
}
|
||||||
|
if items > 0 {
|
||||||
|
// Next page should only be indicated if there are potentially items on it. NOTE: with no knowledge of items-
|
||||||
|
// per-page, this still may need to be altered by the func caller.
|
||||||
|
oc.First = accountRoot + "/" + collType + "?page=1"
|
||||||
|
}
|
||||||
return &oc
|
return &oc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ type Person struct {
|
|||||||
Summary string `json:"summary"`
|
Summary string `json:"summary"`
|
||||||
PublicKey PublicKey `json:"publicKey"`
|
PublicKey PublicKey `json:"publicKey"`
|
||||||
Endpoints Endpoints `json:"endpoints"`
|
Endpoints Endpoints `json:"endpoints"`
|
||||||
|
|
||||||
|
// Extensions
|
||||||
|
Monetization string `json:"monetization,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPerson(accountRoot string) *Person {
|
func NewPerson(accountRoot string) *Person {
|
||||||
@@ -49,3 +52,8 @@ func (p *Person) SetPrivKey(k []byte) {
|
|||||||
func (p *Person) GetPrivKey() []byte {
|
func (p *Person) GetPrivKey() []byte {
|
||||||
return p.PublicKey.privateKey
|
return p.PublicKey.privateKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *Person) AddWebMonetization(wallet string) {
|
||||||
|
p.Context = append(p.Context, apMonetizationContext)
|
||||||
|
p.Monetization = wallet
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
module github.com/writeas/web-core
|
module github.com/writeas/web-core
|
||||||
|
|
||||||
go 1.10
|
go 1.25.0
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/gofrs/uuid v3.3.0+incompatible
|
github.com/gofrs/uuid v3.3.0+incompatible
|
||||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec
|
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec
|
||||||
github.com/microcosm-cc/bluemonday v1.0.23
|
github.com/microcosm-cc/bluemonday v1.0.23
|
||||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
|
|
||||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
|
||||||
github.com/writeas/go-strip-markdown/v2 v2.1.1
|
github.com/writeas/go-strip-markdown/v2 v2.1.1
|
||||||
github.com/writeas/impart v1.1.1
|
github.com/writeas/impart v1.1.1
|
||||||
github.com/writeas/openssl-go v1.0.0
|
github.com/writeas/openssl-go v1.0.0
|
||||||
github.com/writeas/saturday v1.7.1
|
github.com/writeas/saturday v1.7.1
|
||||||
github.com/writeas/slug v1.2.0
|
github.com/writeas/slug v1.2.0
|
||||||
golang.org/x/crypto v0.35.0
|
golang.org/x/crypto v0.52.0
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
)
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/aymerick/douceur v0.2.0 // indirect
|
||||||
|
github.com/gorilla/css v1.0.0 // indirect
|
||||||
|
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
|
||||||
|
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||||
|
golang.org/x/net v0.55.0 // indirect
|
||||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
|
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,14 +2,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
|
|||||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||||
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
|
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
|
||||||
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||||
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
|
||||||
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
||||||
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
||||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
|
||||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
|
||||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
|
||||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec h1:ZXWuspqypleMuJy4bzYEqlMhJnGAYpLrWe5p7W3CdvI=
|
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec h1:ZXWuspqypleMuJy4bzYEqlMhJnGAYpLrWe5p7W3CdvI=
|
||||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g=
|
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g=
|
||||||
github.com/microcosm-cc/bluemonday v1.0.23 h1:SMZe2IGa0NuHvnVNAZ+6B38gsTbi5e4sViiWJyDDqFY=
|
github.com/microcosm-cc/bluemonday v1.0.23 h1:SMZe2IGa0NuHvnVNAZ+6B38gsTbi5e4sViiWJyDDqFY=
|
||||||
@@ -28,76 +22,9 @@ github.com/writeas/saturday v1.7.1 h1:lYo1EH6CYyrFObQoA9RNWHVlpZA5iYL5Opxo7PYAnZ
|
|||||||
github.com/writeas/saturday v1.7.1/go.mod h1:ETE1EK6ogxptJpAgUbcJD0prAtX48bSloie80+tvnzQ=
|
github.com/writeas/saturday v1.7.1/go.mod h1:ETE1EK6ogxptJpAgUbcJD0prAtX48bSloie80+tvnzQ=
|
||||||
github.com/writeas/slug v1.2.0 h1:EMQ+cwLiOcA6EtFwUgyw3Ge18x9uflUnOnR6bp/J+/g=
|
github.com/writeas/slug v1.2.0 h1:EMQ+cwLiOcA6EtFwUgyw3Ge18x9uflUnOnR6bp/J+/g=
|
||||||
github.com/writeas/slug v1.2.0/go.mod h1:RE8shOqQP3YhsfsQe0L3RnuejfQ4Mk+JjY5YJQFubfQ=
|
github.com/writeas/slug v1.2.0/go.mod h1:RE8shOqQP3YhsfsQe0L3RnuejfQ4Mk+JjY5YJQFubfQ=
|
||||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
golang.org/x/crypto v0.52.0 h1:RMs7fP2rXdep0CftQlK8Uf+kibLm7qkCcradZWYz988=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.52.0/go.mod h1:1QgfPxDqh0T2M/elOJtp9RvuR95kVjir0e6/BvEmGbc=
|
||||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
golang.org/x/net v0.55.0 h1:bcvxaJn3e1U6InsFWt1JUq1aSjnRxLzT2rtD2KfkDF8=
|
||||||
golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc=
|
golang.org/x/net v0.55.0/go.mod h1:L5U2KuzuOe1lY7Z+aWVIKK6qEeJXnXV9yzGA+WCHJww=
|
||||||
golang.org/x/crypto v0.19.0/go.mod h1:Iy9bg/ha4yyC70EfRS8jz+B6ybOBKMaSxLj6P6oBDfU=
|
|
||||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
|
||||||
golang.org/x/crypto v0.35.0 h1:b15kiHdrGCHrP6LvwaQ3c03kgNhhiMgvlhxHQhmg2Xs=
|
|
||||||
golang.org/x/crypto v0.35.0/go.mod h1:dy7dXNW32cAb/6/PRuTNsix8T+vJAqvuIy5Bli/x0YQ=
|
|
||||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
|
||||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
|
||||||
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
|
||||||
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
|
||||||
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
|
|
||||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
|
||||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
|
||||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
|
||||||
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
|
|
||||||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
|
|
||||||
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
|
|
||||||
golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44=
|
|
||||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
|
||||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
|
||||||
golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y=
|
|
||||||
golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
|
|
||||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
|
||||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
|
||||||
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
|
||||||
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2/go.mod h1:TeRTkGYfJXctD9OcfyVLyj2J3IxLnKwHJR8f4D8a3YE=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
|
||||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
|
||||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
|
||||||
golang.org/x/term v0.6.0/go.mod h1:m6U89DPEgQRMq3DNkDClhWw02AUbt2daBVO4cn4Hv9U=
|
|
||||||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
|
|
||||||
golang.org/x/term v0.12.0/go.mod h1:owVbMEjm3cBLCHdkQu9b1opXd4ETQWc3BhuQGKgXgvU=
|
|
||||||
golang.org/x/term v0.17.0/go.mod h1:lLRBjIVuehSbZlaOtGMbcMncT+aqLLLmKrsjNrUguwk=
|
|
||||||
golang.org/x/term v0.20.0/go.mod h1:8UkIAJTvZgivsXaD6/pH6U9ecQzZ45awqEOzuCvwpFY=
|
|
||||||
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
|
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|
||||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
|
||||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
|
||||||
golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
|
||||||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
|
|
||||||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
|
||||||
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
|
||||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
|
||||||
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
|
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
|
||||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
|
||||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
|
||||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
|
||||||
golang.org/x/tools v0.13.0/go.mod h1:HvlwmtVNQAhOuCjW7xxvovg8wbNq7LwfXh/k7wXUl58=
|
|
||||||
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk=
|
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
|
||||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
|
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
|
||||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
|
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package text
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/kylemcc/twitter-text-go/extract"
|
||||||
|
"net/url"
|
||||||
|
"regexp"
|
||||||
|
)
|
||||||
|
|
||||||
|
var imageURLRegex = regexp.MustCompile(`(?i)[^ ]+\.(gif|png|jpg|jpeg|image)$`)
|
||||||
|
|
||||||
|
func ExtractImages(content string) []string {
|
||||||
|
matches := extract.ExtractUrls(content)
|
||||||
|
urls := map[string]bool{}
|
||||||
|
for i := range matches {
|
||||||
|
uRaw := matches[i].Text
|
||||||
|
// Parse the extracted text so we can examine the path
|
||||||
|
u, err := url.Parse(uRaw)
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Ensure the path looks like it leads to an image file
|
||||||
|
if !imageURLRegex.MatchString(u.Path) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
urls[uRaw] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
resURLs := make([]string, 0)
|
||||||
|
for k := range urls {
|
||||||
|
resURLs = append(resURLs, k)
|
||||||
|
}
|
||||||
|
return resURLs
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user