From c85466995d7d3268afd454210bfa12d5035a6ad2 Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Thu, 9 Feb 2023 16:23:59 +0100 Subject: [PATCH] Added a TTL parameter to setCookie() --- static/skin/index.js | 16 ++++++++++------ test/server.cpp | 4 ++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/static/skin/index.js b/static/skin/index.js index 81ddc9712..de047f592 100644 --- a/static/skin/index.js +++ b/static/skin/index.js @@ -46,10 +46,14 @@ return (url); } - function setCookie(cookieName, cookieValue) { - const date = new Date(); - date.setTime(date.getTime() + oneDayDelta); - document.cookie = `${cookieName}=${cookieValue};expires=${date.toUTCString()};sameSite=Strict`; + function setCookie(cookieName, cookieValue, ttl) { + let exp = ""; + if ( ttl ) { + const date = new Date(); + date.setTime(date.getTime() + ttl); + exp = `expires=${date.toUTCString()};`; + } + document.cookie = `${cookieName}=${cookieValue};${exp}sameSite=Strict`; } function getCookie(cookieName) { @@ -375,7 +379,7 @@ if (filterType) { params.set(filterType, filterValue); window.history.pushState({}, null, `?${params.toString()}`); - setCookie(filterCookieName, params.toString()); + setCookie(filterCookieName, params.toString(), oneDayDelta); } updateFilterColors(); updateFeedLink(); @@ -520,7 +524,7 @@ } } updateFeedLink(); - setCookie(filterCookieName, params.toString()); + setCookie(filterCookieName, params.toString(), oneDayDelta); }; // required by i18n.js:setUserLanguage() diff --git a/test/server.cpp b/test/server.cpp index 17eaaaf0a..8e1393c14 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -63,7 +63,7 @@ const ResourceCollection resources200Compressible{ { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.css" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/index.css?cacheid=ac5767d8" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/index.js" }, - { STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=c333bdba" }, + { STATIC_CONTENT, "/ROOT%23%3F/skin/index.js?cacheid=2f15ed7d" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js" }, { STATIC_CONTENT, "/ROOT%23%3F/skin/iso6391To3.js?cacheid=ecde2bb3" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/skin/isotope.pkgd.min.js" }, @@ -284,7 +284,7 @@ R"EXPECTEDRESULT( href="/ROOT%23%3F/skin/index.css?cacheid=ac5767d8" - + )EXPECTEDRESULT" },