Commit 8e3d2577 authored by jan.koester's avatar jan.koester
Browse files

test

parent 52f0df67
Loading
Loading
Loading
Loading
+25 −8
Changes for data/template/default/editor.html: 25 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -704,14 +704,19 @@
        function getCookie(name) {
            const nameEQ = name + "=";
            const ca = document.cookie.split(';');
            const results = [];
            for(let i=0; i < ca.length; i++) {
                let c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1, c.length);
                if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
                if (c.indexOf(nameEQ) == 0) results.push(c.substring(nameEQ.length, c.length));
            }
            return null;
            return results;
        }
        function getAuthId() {
            const ids = getCookie('authid');
            return ids.length > 0 ? ids[0] : null;
        }
        function getAllAuthIds() {
            return getCookie('authid');
        }
        // --- End Cookie Utility ---
@@ -728,7 +733,11 @@
         * @param {number} retries The maximum number of retries.
         */
        async function sendApiRequest(commands, retries = 3) {
            const authId = getAuthId();
            const authIds = getAllAuthIds();

            // Try each authid cookie (multiple instances may set same-name cookies)
            for (let aidx = 0; aidx < Math.max(authIds.length, 1); aidx++) {
                const authId = authIds[aidx] || null;
                let finalCommands = [...commands];
                let authPrepended = false;

@@ -738,7 +747,6 @@
                    if (!isFirstCommandAuth) {
                        finalCommands.unshift({"authid": authId});
                        authPrepended = true;
                    console.log("Prepended authentication command.");
                    }
                } else {
                    console.warn("No 'authid' cookie found. Sending commands unauthenticated.");
@@ -754,7 +762,9 @@
                        });

                        if (response.status === 401) {
                        throw new Error(`HTTP error! status: ${response.status} (Unauthorized)`);
                            // Try next authid cookie if available
                            lastError = new Error(`HTTP error! status: ${response.status} (Unauthorized)`);
                            break;
                        }

                        if (!response.ok) {
@@ -778,18 +788,25 @@

                    } catch (error) {
                        lastError = error;
                    if (error.message.includes('(Unauthorized)')) throw lastError;
                        if (error.message.includes('(Unauthorized)')) break;

                    // console.warn(`API request failed (attempt ${i + 1}/${retries}):`, error);
                        if (i < retries - 1) {
                            const delay = Math.pow(2, i) * 1000 + Math.random() * 500;
                            await new Promise(resolve => setTimeout(resolve, delay));
                        }
                    }
                }
            console.error('Final API request failed after all retries.', lastError);
                // If not a 401, don't try more authids
                if (lastError && !lastError.message.includes('(Unauthorized)')) {
                    throw lastError;
                }
                // If last authid also failed with 401, throw
                if (aidx === authIds.length - 1 || authIds.length === 0) {
                    if (lastError) throw lastError;
                }
            }
            throw new Error('HTTP error! status: 401 (Unauthorized)');
        }

        // --- Modal Functions ---

+2 −2
Changes for src/blogi.cpp: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -409,7 +409,7 @@ void blogi::Blogi::loginPage(libhttppp::HttpRequest &curreq,const int tid,const
        libhttppp::HttpResponse curres;
        libhttppp::HttpCookie authid;

        authid.setcookie(curres,"authid",sessid.c_str(),"",PlgArgs->config->getCookieDomain() ,(1000*60*60*1),"/",false,"1","Lax",false);
        authid.setcookie(curres,"authid",sessid.c_str(),"",PlgArgs->config->getCookieDomain() ,(1000*60*60*1),PlgArgs->config->getprefix().empty() ? "/" : PlgArgs->config->getprefix(),false,"1","Lax",false);

        curres.setState(HTTP307);
        curres.setHeaderData("location")->push_back(PlgArgs->config->getstartpage());
@@ -1644,7 +1644,7 @@ RETRY_REQUEST:
                        cban.setPermission(sessid,cururlform.key.c_str(),false);
                }

                cookie.setcookie(curres, "sessionid", sessid,"",PlgArgs->config->getCookieDomain() ,(1000*60*60*1),"/",false,"1","Lax",false);
                cookie.setcookie(curres, "sessionid", sessid,"",PlgArgs->config->getCookieDomain() ,(1000*60*60*1),PlgArgs->config->getprefix().empty() ? "/" : PlgArgs->config->getprefix(),false,"1","Lax",false);
                curres.setState(HTTP307);
                curres.setHeaderData("location")->push_back(curreq.getRequest());
                curres.setContentType("text/html");