From a589c58ed85eece34a8e3938219bd0264238b2a8 Mon Sep 17 00:00:00 2001 From: FChannel <=> Date: Tue, 26 Jan 2021 13:05:12 -0800 Subject: fixed noko --- main.go | 47 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 44 insertions(+), 3 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 605314e..5eab686 100644 --- a/main.go +++ b/main.go @@ -331,7 +331,7 @@ func main() { we.Close() req, err := http.NewRequest("POST", r.FormValue("sendTo"), &b) - + CheckError(err, "error with post form req") req.Header.Set("Content-Type", we.FormDataContentType()) @@ -348,11 +348,12 @@ func main() { body, _ := ioutil.ReadAll(resp.Body) var obj ObjectBase + obj = ParseOptions(r, obj) for _, e := range obj.Option { if(e == "noko" || e == "nokosage"){ - http.Redirect(w, r, TP + "" + Domain + "/" + r.FormValue("boardName") + "/" + string(body) , http.StatusMovedPermanently) - break + http.Redirect(w, r, Domain + "/" + r.FormValue("boardName") + "/" + shortURL(r.FormValue("sendTo"), string(body)) , http.StatusMovedPermanently) + return } } @@ -1898,3 +1899,43 @@ func GetActorCollectionReq(r *http.Request, collection string) Collection { return nCollection } + +func shortURL(actorName string, url string) string { + + re := regexp.MustCompile(`outbox`) + + actor := re.ReplaceAllString(actorName, "") + + re = regexp.MustCompile(`\w+$`) + temp := re.ReplaceAllString(url, "") + + if(temp == actor){ + short := StripTransferProtocol(url) + + re := regexp.MustCompile(`\w+$`) + + id := re.FindString(short); + + return id; + }else{ + short := StripTransferProtocol(url) + + re := regexp.MustCompile(`\w+$`) + + id := re.FindString(short); + + re = regexp.MustCompile(`.+/.+/`) + + actorurl := re.FindString(short) + + re = regexp.MustCompile(`/.+/`) + + actorname := re.FindString(actorurl) + + actorname = strings.Replace(actorname, "/", "", -1) + + id = "f" + actorname + "-" + id + + return id; + } +} -- cgit v1.2.3