Redirect to thread on thread creation
This commit is contained in:
+11
-1
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user