mirror of
https://github.com/Eggbertx/gochan.git
synced 2025-09-06 11:46:24 -07:00
Backend: Return JSON when post is submitted via QR
Frontend: request thread and trigger update from returned JSON
This commit is contained in:
parent
36ce238dff
commit
7c116dafc6
3 changed files with 39 additions and 6 deletions
|
@ -221,7 +221,8 @@ export function initQR() {
|
|||
data: data, // $form.serialize(),
|
||||
processData: false,
|
||||
contentType: false,
|
||||
success: (data, _status, _jqXHR) => {
|
||||
dataType: "json",
|
||||
success: (data: PostSubmitResponse, _status, _jqXHR) => {
|
||||
if(data.error) {
|
||||
alertLightbox(data.error, "Error");
|
||||
return;
|
||||
|
@ -229,10 +230,10 @@ export function initQR() {
|
|||
clearQR();
|
||||
const cooldown = (currentThread().id > 0)?replyCooldown:threadCooldown;
|
||||
setButtonTimeout("", cooldown);
|
||||
updateThread().then(clearQR).then(() => {
|
||||
const persist = getBooleanStorageVal("persistentqr", false);
|
||||
if(!persist) closeQR();
|
||||
});
|
||||
$.get({
|
||||
url: data.thread,
|
||||
success: updateThreadSuccess
|
||||
})
|
||||
return false;
|
||||
},
|
||||
error: (_jqXHR, _status, error) => {
|
||||
|
@ -243,6 +244,19 @@ export function initQR() {
|
|||
});
|
||||
}
|
||||
|
||||
function updateThreadSuccess(data: any, status: string, xhr: JQueryXHR) {
|
||||
const $doc = $(data);
|
||||
const $replyContainers = $("div.reply-container");
|
||||
$doc.find("div.reply-container").each((_i, el: HTMLElement) => {
|
||||
const idSelector = `#${el.id}`;
|
||||
const prevIDselector = `#${el.previousElementSibling.id}`;
|
||||
if($replyContainers.filter(idSelector).length == 0) {
|
||||
// new post
|
||||
$(el).insertAfter($replyContainers.filter(prevIDselector));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function copyCaptchaResponse($copyToForm: JQuery<HTMLElement>) {
|
||||
const $captchaResp = $("textarea[name=h-captcha-response]");
|
||||
if($captchaResp.length > 0) {
|
||||
|
|
7
frontend/ts/types/index.d.ts
vendored
7
frontend/ts/types/index.d.ts
vendored
|
@ -100,6 +100,13 @@ declare global {
|
|||
last_modified: string;
|
||||
}
|
||||
|
||||
interface PostSubmitResponse {
|
||||
error?: string;
|
||||
id: number;
|
||||
time: Date;
|
||||
thread: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object representing a staff member retreived by requesting /manage/staffinfo
|
||||
*/
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package posting
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
@ -42,6 +43,7 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
Str("IP", ip)
|
||||
defer func() {
|
||||
if a := recover(); a != nil {
|
||||
writer.WriteHeader(http.StatusInternalServerError)
|
||||
server.ServeError(writer, "Internal server error", wantsJSON, nil)
|
||||
errEv.Caller().
|
||||
Str("recover", fmt.Sprintf("%v", a)).
|
||||
|
@ -369,7 +371,17 @@ func MakePost(writer http.ResponseWriter, request *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
if emailCommand == "noko" {
|
||||
if wantsJSON {
|
||||
topPost := post.ID
|
||||
if !post.IsTopPost {
|
||||
topPost, _ = post.TopPostID()
|
||||
}
|
||||
json.NewEncoder(writer).Encode(map[string]interface{}{
|
||||
"time": post.CreatedOn,
|
||||
"id": post.ID,
|
||||
"thread": config.WebPath(postBoard.Dir, "/res/", strconv.Itoa(topPost)+".html"),
|
||||
})
|
||||
} else if emailCommand == "noko" {
|
||||
if post.IsTopPost {
|
||||
http.Redirect(writer, request, systemCritical.WebRoot+postBoard.Dir+"/res/"+strconv.Itoa(post.ID)+".html", http.StatusFound)
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue