aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client.go23
-rw-r--r--db/database.go6
-rw-r--r--main.go24
3 files changed, 18 insertions, 35 deletions
diff --git a/client.go b/client.go
index d4462d7..dfce517 100644
--- a/client.go
+++ b/client.go
@@ -169,35 +169,20 @@ func ParseLinkComments(board activitypub.Actor, op string, content string, threa
}
}
- //replace link with quote format
- replyID, isReply, err := db.IsReplyToOP(op, parsedLink)
- if err != nil {
- return "", err
- }
-
- if isReply {
+ if replyID, isReply, err := db.IsReplyToOP(op, parsedLink); err == nil || !isReply {
id := util.ShortURL(board.Outbox, replyID)
content = strings.Replace(content, match[i][0], "<a class=\"reply\" title=\""+quoteTitle+"\" href=\"/"+board.Name+"/"+util.ShortURL(board.Outbox, op)+"#"+id+"\">&gt;&gt;"+id+""+isOP+"</a>", -1)
-
} else {
//this is a cross post
parsedOP, err := db.GetReplyOP(parsedLink)
- if err != nil {
- return "", err
- }
-
- actor, err := webfinger.FingerActor(parsedLink)
- if err != nil {
- return "", err
- }
-
- if parsedOP != "" {
+ if err == nil {
link = parsedOP + "#" + util.ShortURL(parsedOP, parsedLink)
}
- if actor.Id != "" {
+ actor, err := webfinger.FingerActor(parsedLink)
+ if err == nil && actor.Id != "" {
content = strings.Replace(content, match[i][0], "<a class=\"reply\" title=\""+quoteTitle+"\" href=\""+link+"\">&gt;&gt;"+util.ShortURL(board.Outbox, parsedLink)+isOP+" →</a>", -1)
}
}
diff --git a/db/database.go b/db/database.go
index 8845f24..0b44404 100644
--- a/db/database.go
+++ b/db/database.go
@@ -2371,11 +2371,7 @@ func IsReplyToOP(op string, link string) (string, bool, error) {
return id, false, err
}
- if id != "" {
- return id, true, nil
- }
-
- return "", false, nil
+ return id, id != "", nil
}
func GetReplyOP(link string) (string, error) {
diff --git a/main.go b/main.go
index 02beaf4..2f8131d 100644
--- a/main.go
+++ b/main.go
@@ -116,9 +116,6 @@ func main() {
Views: template,
})
- app.Static("/public", "./public")
- app.Static("/static", "./views")
-
/*
Main actor
*/
@@ -135,7 +132,7 @@ func main() {
Board actor
*/
- app.Get("/:actor", routes.ActorIndex) //OutboxGet)
+ app.Get("/:actor", routes.OutboxGet)
app.Get("/:actor/:post", routes.ActorPostGet)
app.Get("/post", routes.ActorPost)
@@ -234,12 +231,19 @@ func main() {
})
app.Get("/api/media", func(c *fiber.Ctx) error {
- return c.SendString("api media")
+ if c.Query("hash") != "" {
+ return RouteImages(c, c.Query("hash"))
+ }
+
+ return c.SendStatus(404)
})
// 404 handler
app.Use(routes.NotFound)
+ app.Static("/public", "./public")
+ app.Static("/static", "./views")
+
fmt.Println("Mod key: " + config.Key)
PrintAdminAuth()
@@ -979,7 +983,7 @@ func AddInstanceToIndexDB(actor string) error {
return nil
}
-func RouteImages(w http.ResponseWriter, media string) error {
+func RouteImages(ctx *fiber.Ctx, media string) error {
req, err := http.NewRequest("GET", MediaHashs[media], nil)
if err != nil {
return err
@@ -1001,19 +1005,17 @@ func RouteImages(w http.ResponseWriter, media string) error {
return err
}
- _, err = w.Write(fileBytes)
- return err
+ return ctx.Send(fileBytes)
}
body, _ := ioutil.ReadAll(resp.Body)
for name, values := range resp.Header {
for _, value := range values {
- w.Header().Set(name, value)
+ ctx.Append(name, value)
}
}
- _, err = w.Write(body)
- return err
+ return ctx.Send(body)
}
func TemplateFunctions(engine *html.Engine) {