Redirect to thread on thread creation

This commit is contained in:
Dominic Ferrando
2025-04-23 22:24:42 -04:00
parent a08a9a69d2
commit eb770416d0
3 changed files with 24 additions and 13 deletions
+11 -1
View File
@@ -239,13 +239,23 @@ func main() {
return
}
if err := database.PutThread(db, slug, subject, body, savedMediaPath, savedThumbPath, util.HashIp(ip)); err != nil {
threadId, err := database.PutThread(db, slug, subject, body, savedMediaPath, savedThumbPath, util.HashIp(ip))
if err != nil {
http.Error(w, "Failed to create thread", http.StatusInternalServerError)
log.Printf("PutThread: %v", err)
return
}
util.BeginCooldown(ip, util.ThreadCooldowns, util.THREAD_COOLDOWN)
// Check if it's an HTMX request
redirectUrl := fmt.Sprintf("/%s/threads/%d", slug, threadId)
if r.Header.Get("HX-Request") == "true" {
w.Header().Set("HX-Redirect", redirectUrl)
w.WriteHeader(http.StatusOK)
} else {
http.Redirect(w, r, redirectUrl, http.StatusSeeOther)
}
})
// CREATE POST