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
+1
View File
@@ -37,6 +37,7 @@ templ Board(board database.Board, isAdmin bool) {
<option value="large">Large</option>
</select>
<input style="margin-left: 10px;" oninput="applyCatalogSearch()" id="catalogSearch" placeholder="Search"/>
<a style="margin-left: 10px;" _="on click trigger refreshPosts on body" class="link-button">[Refresh]</a>
</div>
<hr/>
<div