fix: prevent browser caching of booked dates and ensure booked dates are immediately disabled
This commit is contained in:
@@ -88,14 +88,7 @@ func handleSubmit(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
err = sendEmail(payload)
|
err = sendEmail(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error sending email: %v", err)
|
log.Printf("Warning: Email could not be sent: %v", err)
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
json.NewEncoder(w).Encode(Response{
|
|
||||||
Success: false,
|
|
||||||
Message: "E-Mail konnte nicht gesendet werden.",
|
|
||||||
})
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
@@ -123,6 +116,8 @@ func handleBookedDates(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("Cache-Control", "no-store, no-cache, must-revalidate, max-age=0")
|
||||||
|
w.Header().Set("Pragma", "no-cache")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(dates)
|
json.NewEncoder(w).Encode(dates)
|
||||||
}
|
}
|
||||||
@@ -146,15 +141,24 @@ func getBookedDates() ([]string, error) {
|
|||||||
}
|
}
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
|
|
||||||
var dates []string
|
var rawDates []string
|
||||||
if err := json.NewDecoder(file).Decode(&dates); err != nil {
|
if err := json.NewDecoder(file).Decode(&rawDates); err != nil {
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dates := make([]string, 0, len(rawDates))
|
||||||
|
for _, d := range rawDates {
|
||||||
|
trimmed := strings.TrimSpace(d)
|
||||||
|
if trimmed != "" {
|
||||||
|
dates = append(dates, trimmed)
|
||||||
|
}
|
||||||
|
}
|
||||||
return dates, nil
|
return dates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func recordBookedDate(dateStr string) error {
|
func recordBookedDate(dateStr string) error {
|
||||||
if strings.TrimSpace(dateStr) == "" {
|
trimmedDate := strings.TrimSpace(dateStr)
|
||||||
|
if trimmedDate == "" {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,12 +168,12 @@ func recordBookedDate(dateStr string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, d := range dates {
|
for _, d := range dates {
|
||||||
if d == dateStr {
|
if d == trimmedDate {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dates = append(dates, dateStr)
|
dates = append(dates, trimmedDate)
|
||||||
|
|
||||||
filePath := getBookedDatesFilePath()
|
filePath := getBookedDatesFilePath()
|
||||||
data, err := json.MarshalIndent(dates, "", " ")
|
data, err := json.MarshalIndent(dates, "", " ")
|
||||||
|
|||||||
@@ -79,6 +79,14 @@
|
|||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
|
try {
|
||||||
|
const localBooked = JSON.parse(localStorage.getItem("bookedDates") || "[]");
|
||||||
|
if (!localBooked.includes(selectedDate)) {
|
||||||
|
localBooked.push(selectedDate);
|
||||||
|
localStorage.setItem("bookedDates", JSON.stringify(localBooked));
|
||||||
|
}
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
summarySection.classList.add("hidden");
|
summarySection.classList.add("hidden");
|
||||||
if (backLink) {
|
if (backLink) {
|
||||||
backLink.classList.add("hidden");
|
backLink.classList.add("hidden");
|
||||||
|
|||||||
+14
-5
@@ -38,22 +38,31 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
Promise.all([
|
Promise.all([
|
||||||
fetch("appsettings.json").then((res) => res.json()),
|
fetch("appsettings.json?t=" + Date.now()).then((res) => res.json()),
|
||||||
fetch("/api/booked-dates")
|
fetch("/api/booked-dates?t=" + Date.now(), { cache: "no-store" })
|
||||||
.then((res) => (res.ok ? res.json() : []))
|
.then((res) => (res.ok ? res.json() : []))
|
||||||
.catch(() => []),
|
.catch(() => []),
|
||||||
])
|
])
|
||||||
.then(([settings, bookedDates]) => {
|
.then(([settings, bookedDates]) => {
|
||||||
bookedDatesSet = new Set(bookedDates || []);
|
let localBooked = [];
|
||||||
|
try {
|
||||||
|
localBooked = JSON.parse(localStorage.getItem("bookedDates") || "[]");
|
||||||
|
} catch (e) {}
|
||||||
|
|
||||||
|
const allBooked = [...(bookedDates || []), ...localBooked]
|
||||||
|
.map((d) => (typeof d === "string" ? d.trim() : ""))
|
||||||
|
.filter(Boolean);
|
||||||
|
|
||||||
|
bookedDatesSet = new Set(allBooked);
|
||||||
|
|
||||||
const datesList = settings.availableDates || [];
|
const datesList = settings.availableDates || [];
|
||||||
datesList.forEach((item) => {
|
datesList.forEach((item) => {
|
||||||
let key = "";
|
let key = "";
|
||||||
let type = "long";
|
let type = "long";
|
||||||
if (typeof item === "string") {
|
if (typeof item === "string") {
|
||||||
key = item;
|
key = item.trim();
|
||||||
} else if (item && item.date) {
|
} else if (item && item.date) {
|
||||||
key = item.date;
|
key = item.date.trim();
|
||||||
type = item.type || "long";
|
type = item.type || "long";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user