aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFChannel <>2022-06-14 16:43:11 -0700
committerFChannel <>2022-06-19 12:53:29 -0700
commita4621a1d4ee2c307dded842d5866ac9de76a40b4 (patch)
tree1667d5692213e5b3d11a0852793c0b4c4e021335
parent7306338e7f23d652b6b0bfecddcee408a4227169 (diff)
set retry on fail POST req. might be pointless though
since other parts require requests that cannont be delayed
-rw-r--r--activitypub/activity.go163
-rw-r--r--main.go2
-rw-r--r--views/partials/bottom.html2
-rw-r--r--views/partials/top.html4
4 files changed, 88 insertions, 83 deletions
diff --git a/activitypub/activity.go b/activitypub/activity.go
index 71f2d5c..ef25b5d 100644
--- a/activitypub/activity.go
+++ b/activitypub/activity.go
@@ -51,7 +51,7 @@ func (activity Activity) AddFollowersTo() (Activity, error) {
bFollowers, err := reqActivity.GetCollection()
if err != nil {
- return activity, util.MakeError(err, "AddFollowersTo")
+ continue
}
// get followers of activity actor followers
@@ -336,36 +336,6 @@ func (activity Activity) SetActorFollowing() (Activity, error) {
return activity, nil
}
-func (activity Activity) MakeFollowingReq() (bool, error) {
- actor, err := GetActor(activity.Object.Id)
-
- if err != nil {
- return false, util.MakeError(err, "MakeFollowingReq")
- }
-
- req, err := http.NewRequest("POST", actor.Inbox, nil)
-
- if err != nil {
- return false, util.MakeError(err, "MakeFollowingReq")
- }
-
- resp, err := util.RouteProxy(req)
-
- if err != nil {
- return false, util.MakeError(err, "MakeFollowingReq")
- }
-
- defer resp.Body.Close()
-
- body, _ := ioutil.ReadAll(resp.Body)
-
- var respActivity Activity
-
- err = json.Unmarshal(body, &respActivity)
-
- return respActivity.Type == "Accept", util.MakeError(err, "MakeFollowingReq")
-}
-
func (activity Activity) MakeRequestInbox() error {
j, _ := json.MarshalIndent(activity, "", "\t")
@@ -381,35 +351,50 @@ func (activity Activity) MakeRequestInbox() error {
_, instance := GetActorAndInstance(actor.Id)
if actor.Inbox != "" {
- req, err := http.NewRequest("POST", actor.Inbox, bytes.NewBuffer(j))
+ go func(actor Actor, activity Activity) error {
+ var status int
+ var try int
+
+ for try != 5 && status != 200 {
+ time.Sleep(time.Duration(try) * time.Minute)
+
+ req, err := http.NewRequest("POST", actor.Inbox, bytes.NewBuffer(j))
+
+ if err != nil {
+ return util.MakeError(err, "MakeRequest")
+ }
- if err != nil {
- return util.MakeError(err, "MakeRequest")
- }
+ date := time.Now().UTC().Format(time.RFC1123)
+ path := strings.Replace(actor.Inbox, instance, "", 1)
+ re := regexp.MustCompile("https?://(www.)?")
+ path = re.ReplaceAllString(path, "")
+ sig := fmt.Sprintf("(request-target): %s %s\nhost: %s\ndate: %s", "post", path, instance, date)
+ encSig, err := activity.Actor.ActivitySign(sig)
- date := time.Now().UTC().Format(time.RFC1123)
- path := strings.Replace(actor.Inbox, instance, "", 1)
- re := regexp.MustCompile("https?://(www.)?")
- path = re.ReplaceAllString(path, "")
- sig := fmt.Sprintf("(request-target): %s %s\nhost: %s\ndate: %s", "post", path, instance, date)
- encSig, err := activity.Actor.ActivitySign(sig)
+ if err != nil {
+ return util.MakeError(err, "MakeRequest")
+ }
- if err != nil {
- return util.MakeError(err, "MakeRequest")
- }
+ signature := fmt.Sprintf("keyId=\"%s\",headers=\"(request-target) host date\",signature=\"%s\"", activity.Actor.PublicKey.Id, encSig)
- signature := fmt.Sprintf("keyId=\"%s\",headers=\"(request-target) host date\",signature=\"%s\"", activity.Actor.PublicKey.Id, encSig)
+ req.Header.Set("Content-Type", config.ActivityStreams)
+ req.Header.Set("Date", date)
+ req.Header.Set("Signature", signature)
+ req.Host = instance
- req.Header.Set("Content-Type", config.ActivityStreams)
- req.Header.Set("Date", date)
- req.Header.Set("Signature", signature)
- req.Host = instance
+ resp, err := util.RouteProxy(req)
- _, err = util.RouteProxy(req)
+ if err != nil {
+ return util.MakeError(err, "MakeRequest")
+ }
- if err != nil {
- return util.MakeError(err, "MakeRequest")
- }
+ status = resp.StatusCode
+ try += 1
+ }
+
+ return nil
+
+ }(actor, activity)
}
}
}
@@ -425,38 +410,58 @@ func (activity Activity) MakeRequestOutbox() error {
return util.MakeError(errors.New("invalid outbox"), "MakeRequestOutbox")
}
- req, err := http.NewRequest("POST", activity.Actor.Outbox, bytes.NewBuffer(j))
- if err != nil {
- return util.MakeError(err, "MakeRequestOutbox")
- }
+ go func(actor Actor, activity Activity) error {
+ var status int
+ var try int
- re := regexp.MustCompile("https?://(www.)?")
+ for try != 5 && status != 200 {
+ time.Sleep(time.Duration(try) * time.Minute)
- var instance string
- if activity.Actor.Id == config.Domain {
- instance = re.ReplaceAllString(config.Domain, "")
- } else {
- _, instance = GetActorAndInstance(activity.Actor.Id)
- }
+ req, err := http.NewRequest("POST", activity.Actor.Outbox, bytes.NewBuffer(j))
+
+ if err != nil {
+ return util.MakeError(err, "MakeRequestOutbox")
+ }
- date := time.Now().UTC().Format(time.RFC1123)
- path := strings.Replace(activity.Actor.Outbox, instance, "", 1)
- path = re.ReplaceAllString(path, "")
- sig := fmt.Sprintf("(request-target): %s %s\nhost: %s\ndate: %s", "post", path, instance, date)
- encSig, err := activity.Actor.ActivitySign(sig)
+ re := regexp.MustCompile("https?://(www.)?")
- if err != nil {
- return util.MakeError(err, "MakeRequestOutbox")
- }
+ var instance string
+ if activity.Actor.Id == config.Domain {
+ instance = re.ReplaceAllString(config.Domain, "")
+ } else {
+ _, instance = GetActorAndInstance(activity.Actor.Id)
+ }
- signature := fmt.Sprintf("keyId=\"%s\",headers=\"(request-target) host date\",signature=\"%s\"", activity.Actor.PublicKey.Id, encSig)
+ date := time.Now().UTC().Format(time.RFC1123)
+ path := strings.Replace(activity.Actor.Outbox, instance, "", 1)
+ path = re.ReplaceAllString(path, "")
+ sig := fmt.Sprintf("(request-target): %s %s\nhost: %s\ndate: %s", "post", path, instance, date)
+ encSig, err := activity.Actor.ActivitySign(sig)
+
+ if err != nil {
+ return util.MakeError(err, "MakeRequestOutbox")
+ }
+
+ signature := fmt.Sprintf("keyId=\"%s\",headers=\"(request-target) host date\",signature=\"%s\"", activity.Actor.PublicKey.Id, encSig)
+
+ req.Header.Set("Content-Type", config.ActivityStreams)
+ req.Header.Set("Date", date)
+ req.Header.Set("Signature", signature)
+ req.Host = instance
+
+ resp, err := util.RouteProxy(req)
+
+ if err != nil {
+ return util.MakeError(err, "MakeRequest")
+ }
+
+ status = resp.StatusCode
+ try += 1
+ }
- req.Header.Set("Content-Type", config.ActivityStreams)
- req.Header.Set("Date", date)
- req.Header.Set("Signature", signature)
- req.Host = instance
+ return nil
- _, err = util.RouteProxy(req)
+ }(*activity.Actor, activity)
- return util.MakeError(err, "MakeRequestOutbox")
+ return util.MakeError(nil, "MakeRequestOutbox")
}
diff --git a/main.go b/main.go
index b1ab2e9..98fb5d7 100644
--- a/main.go
+++ b/main.go
@@ -93,6 +93,7 @@ func main() {
app.Get("/api/media", routes.Media)
// Board actor routes
+ app.Post("/post", routes.ActorPost)
app.Get("/:actor/catalog", routes.ActorCatalog)
app.Post("/:actor/inbox", routes.ActorInbox)
app.All("/:actor/outbox", routes.ActorOutbox)
@@ -100,7 +101,6 @@ func main() {
app.All("/:actor/followers", routes.ActorFollowers)
app.Get("/:actor/archive", routes.ActorArchive)
app.Get("/:actor", routes.ActorOutboxGet)
- app.Post("/:actor", routes.ActorPost)
app.Get("/:actor/:post", routes.ActorPostGet)
db.PrintAdminAuth()
diff --git a/views/partials/bottom.html b/views/partials/bottom.html
index f995cf2..35e8c4a 100644
--- a/views/partials/bottom.html
+++ b/views/partials/bottom.html
@@ -3,7 +3,7 @@
<span id="reply-header-text">...</span>
<div id="reply-close" style="display: inline-block; float: right;"><a href="javascript:closeReply()">[X]</a></div>
</div>
- <form onsubmit="sessionStorage.setItem('element-closed-reply', true)" id="reply-post" action="/{{ .Board.Name }}" method="post" enctype="multipart/form-data">
+ <form onsubmit="sessionStorage.setItem('element-closed-reply', true)" id="reply-post" action="/post" method="post" enctype="multipart/form-data">
<input id="reply-name" name="name" type="text" placeholder="Name" maxlength="100">
<input id="reply-options" name="options" type="text" placeholder="Options" maxlength="100">
<textarea id="reply-comment" name="comment" maxlength="2000" oninput="sessionStorage.setItem('element-reply-comment', document.getElementById('reply-comment').value)"></textarea>
diff --git a/views/partials/top.html b/views/partials/top.html
index dddb206..73da840 100644
--- a/views/partials/top.html
+++ b/views/partials/top.html
@@ -9,7 +9,7 @@
<h3 id="newpostbtn" state="0" style="display: none; margin-bottom:100px;">[<a href="javascript:startNewPost()">Start a New Thread</a>]</h3>
{{ end }} <!-- end if inreplyto-->
<div id="newpost">
- <form onsubmit="sessionStorage.setItem('element-closed-reply', true)" id="new-post" action="/{{ .Board.Name }}" method="post" enctype="multipart/form-data">
+ <form onsubmit="sessionStorage.setItem('element-closed-reply', true)" id="new-post" action="/post" method="post" enctype="multipart/form-data">
<table id="postForm">
<tr>
<tr>
@@ -66,7 +66,7 @@
{{ end }} <!-- end if inreplyto-->
{{ $len := len .Posts }}
<div id="newpost">
- <form onsubmit="sessionStorage.setItem('element-closed-reply', true)" id="new-post" action="/{{ .Board.Name }}" method="post" enctype="multipart/form-data">
+ <form onsubmit="sessionStorage.setItem('element-closed-reply', true)" id="new-post" action="/post" method="post" enctype="multipart/form-data">
<table id="postForm">
<tr>
<tr>