aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--main.go82
-rw-r--r--static/faq.html2
2 files changed, 59 insertions, 25 deletions
diff --git a/main.go b/main.go
index 601394f..60f537f 100644
--- a/main.go
+++ b/main.go
@@ -49,6 +49,8 @@ var activitystreams = "application/ld+json; profile=\"https://www.w3.org/ns/acti
var MediaHashs = make(map[string]string)
+var ActorCache = make(map[string]Actor)
+
func main() {
CreatedNeededDirectories()
@@ -1197,7 +1199,13 @@ func main() {
return
}
- if !IsActorLocal(db, TP + "" + actorDomain[1] + "/" + actorDomain[0]) {
+ if actorDomain[0] == "main" {
+ actorDomain[0] = ""
+ } else {
+ actorDomain[0] = "/" + actorDomain[0]
+ }
+
+ if !IsActorLocal(db, TP + "" + actorDomain[1] + "" + actorDomain[0]) {
w.WriteHeader(http.StatusBadRequest)
w.Write([]byte("actor not local"))
return
@@ -1209,7 +1217,7 @@ func main() {
finger.Subject = "acct:" + actorDomain[0] + "@" + actorDomain[1]
link.Rel = "self"
link.Type = "application/activity+json"
- link.Href = TP + "" + actorDomain[1] + "/" + actorDomain[0]
+ link.Href = TP + "" + actorDomain[1] + "" + actorDomain[0]
finger.Links = append(finger.Links, link)
@@ -1721,26 +1729,34 @@ func GetActor(id string) Actor {
return respActor
}
- req, err := http.NewRequest("GET", id, nil)
+ actor, instance := GetActorInstance(id)
- CheckError(err, "error with getting actor req")
+ if ActorCache[actor + "@" + instance].Id != "" {
+ respActor = ActorCache[actor + "@" + instance]
+ } else {
+ req, err := http.NewRequest("GET", id, nil)
- req.Header.Set("Accept", activitystreams)
+ CheckError(err, "error with getting actor req")
- resp, err := RouteProxy(req)
+ req.Header.Set("Accept", activitystreams)
- if err != nil {
- fmt.Println("error with getting actor resp " + id)
- return respActor
- }
+ resp, err := RouteProxy(req)
- defer resp.Body.Close()
+ if err != nil {
+ fmt.Println("error with getting actor resp " + id)
+ return respActor
+ }
- body, _ := ioutil.ReadAll(resp.Body)
+ defer resp.Body.Close()
+
+ body, _ := ioutil.ReadAll(resp.Body)
- err = json.Unmarshal(body, &respActor)
+ err = json.Unmarshal(body, &respActor)
- CheckError(err, "error getting actor from body")
+ CheckError(err, "error getting actor from body")
+
+ ActorCache[actor + "@" + instance] = respActor
+ }
return respActor
}
@@ -2489,21 +2505,30 @@ func CreatedNeededDirectories() {
//looks for actor with pattern of board@instance
func FingerActor(path string) Actor{
+ var nActor Actor
+
actor, instance := GetActorInstance(path)
- r := FingerRequest(actor, instance)
+ if actor == "" && instance == "" {
+ return nActor
+ }
- var nActor Actor
+ if ActorCache[actor + "@" + instance].Id != "" {
+ nActor = ActorCache[actor + "@" + instance]
+ } else {
+ r := FingerRequest(actor, instance)
+ if r != nil && r.StatusCode == 200 {
+ defer r.Body.Close()
+
+ body, _ := ioutil.ReadAll(r.Body)
- if r != nil && r.StatusCode == 200 {
- defer r.Body.Close()
-
- body, _ := ioutil.ReadAll(r.Body)
+ err := json.Unmarshal(body, &nActor)
- err := json.Unmarshal(body, &nActor)
+ CheckError(err, "error getting fingerrequet resp from json body")
- CheckError(err, "error getting fingerrequet resp from json body")
- }
+ ActorCache[actor + "@" + instance] = nActor
+ }
+ }
return nActor
}
@@ -2561,7 +2586,16 @@ func GetActorInstance(path string) (string, string) {
}
}
- re = regexp.MustCompile(`(https?:\\)?(www)?([\w\d-_.:]+)\/([\w\d-_.]+)(\/([\w\d-_.]+))?`)
+ re = regexp.MustCompile(`(https?://)(www)?([\w\d-_.:]+)(/|\s+|\r|\r\n)?$`)
+ mainActor := re.MatchString(path)
+ if(mainActor) {
+ match := re.FindStringSubmatch(path)
+ if(len(match) > 2) {
+ return "main", match[3]
+ }
+ }
+
+ re = regexp.MustCompile(`(https?://)?(www)?([\w\d-_.:]+)\/([\w\d-_.]+)(\/([\w\d-_.]+))?`)
httpFormat := re.MatchString(path)
if(httpFormat) {
diff --git a/static/faq.html b/static/faq.html
index 9baf8ca..6f60d62 100644
--- a/static/faq.html
+++ b/static/faq.html
@@ -56,7 +56,7 @@
<p>Soon&trade;.</p>
<h4 id="version">What version is this FChannel instance?</h4>
- <p>v0.0.11-dev</p>
+ <p>v0.0.12-dev</p>
</div>
<div style="width: 500px; margin:0 auto; margin-top: 50px; text-align: center;">
<a href="/">[Home]</a><a href="/static/rules.html">[Rules]</a><a href="/static/faq.html">[FAQ]</a>