"feat: Refactor database connection in myp.db and update notifications"
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -14,9 +14,37 @@ class NotificationManager {
|
|||||||
this.isOpen = false;
|
this.isOpen = false;
|
||||||
this.notifications = [];
|
this.notifications = [];
|
||||||
|
|
||||||
|
// CSRF-Token aus Meta-Tag holen
|
||||||
|
this.csrfToken = this.getCSRFToken();
|
||||||
|
|
||||||
this.init();
|
this.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holt das CSRF-Token aus dem Meta-Tag
|
||||||
|
* @returns {string} Das CSRF-Token
|
||||||
|
*/
|
||||||
|
getCSRFToken() {
|
||||||
|
const metaTag = document.querySelector('meta[name="csrf-token"]');
|
||||||
|
return metaTag ? metaTag.getAttribute('content') : '';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Erstellt die Standard-Headers für API-Anfragen mit CSRF-Token
|
||||||
|
* @returns {Object} Headers-Objekt
|
||||||
|
*/
|
||||||
|
getAPIHeaders() {
|
||||||
|
const headers = {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.csrfToken) {
|
||||||
|
headers['X-CSRFToken'] = this.csrfToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
return headers;
|
||||||
|
}
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
if (!this.notificationToggle) return;
|
if (!this.notificationToggle) return;
|
||||||
|
|
||||||
@@ -241,9 +269,7 @@ class NotificationManager {
|
|||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/notifications/${notificationId}/read`, {
|
const response = await fetch(`/api/notifications/${notificationId}/read`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: this.getAPIHeaders()
|
||||||
'Content-Type': 'application/json',
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -253,6 +279,8 @@ class NotificationManager {
|
|||||||
notification.read = true;
|
notification.read = true;
|
||||||
this.updateUI();
|
this.updateUI();
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
console.error('Fehler beim Markieren als gelesen:', response.status, response.statusText);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Markieren als gelesen:', error);
|
console.error('Fehler beim Markieren als gelesen:', error);
|
||||||
@@ -263,9 +291,7 @@ class NotificationManager {
|
|||||||
try {
|
try {
|
||||||
const response = await fetch('/api/notifications/mark-all-read', {
|
const response = await fetch('/api/notifications/mark-all-read', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: this.getAPIHeaders()
|
||||||
'Content-Type': 'application/json',
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
@@ -274,6 +300,8 @@ class NotificationManager {
|
|||||||
notification.read = true;
|
notification.read = true;
|
||||||
});
|
});
|
||||||
this.updateUI();
|
this.updateUI();
|
||||||
|
} else {
|
||||||
|
console.error('Fehler beim Markieren aller als gelesen:', response.status, response.statusText);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fehler beim Markieren aller als gelesen:', error);
|
console.error('Fehler beim Markieren aller als gelesen:', error);
|
||||||
|
Reference in New Issue
Block a user