vor ähnlichkeitsprüfung
This commit is contained in:
93
web/app.js
93
web/app.js
@@ -1,4 +1,5 @@
|
||||
const API_URL = 'https://fb.srv.medeba-media.de/api';
|
||||
const LOGIN_PAGE = 'login.html';
|
||||
|
||||
let initialViewParam = null;
|
||||
try {
|
||||
@@ -37,6 +38,30 @@ const PROFILE_NAMES = {
|
||||
4: 'Profil 4',
|
||||
5: 'Profil 5'
|
||||
};
|
||||
|
||||
function redirectToLogin() {
|
||||
try {
|
||||
const redirect = encodeURIComponent(window.location.href);
|
||||
window.location.href = `${LOGIN_PAGE}?redirect=${redirect}`;
|
||||
} catch (_error) {
|
||||
window.location.href = LOGIN_PAGE;
|
||||
}
|
||||
}
|
||||
|
||||
async function ensureAuthenticated() {
|
||||
try {
|
||||
const response = await fetch(`${API_URL}/session`, { credentials: 'include' });
|
||||
if (response.status === 401) {
|
||||
redirectToLogin();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.warn('Konnte Auth-Status nicht prüfen:', error);
|
||||
redirectToLogin();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function apiFetch(url, options = {}) {
|
||||
const config = {
|
||||
@@ -48,7 +73,36 @@ function apiFetch(url, options = {}) {
|
||||
config.headers = { ...options.headers };
|
||||
}
|
||||
|
||||
return fetch(url, config);
|
||||
return fetch(url, config).then((response) => {
|
||||
if (response.status === 401) {
|
||||
redirectToLogin();
|
||||
throw new Error('Nicht angemeldet');
|
||||
}
|
||||
return response;
|
||||
});
|
||||
}
|
||||
|
||||
function markAppReady() {
|
||||
if (document && document.body) {
|
||||
document.body.classList.remove('auth-pending');
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogout() {
|
||||
try {
|
||||
await fetch(`${API_URL}/logout`, { method: 'POST', credentials: 'include' });
|
||||
} catch (error) {
|
||||
// ignore network errors on logout
|
||||
}
|
||||
redirectToLogin();
|
||||
}
|
||||
|
||||
function bindLogoutButton() {
|
||||
const btn = document.getElementById('logoutBtn');
|
||||
if (!btn) {
|
||||
return;
|
||||
}
|
||||
btn.addEventListener('click', handleLogout);
|
||||
}
|
||||
|
||||
function sortPostsByCreatedAt() {
|
||||
@@ -4544,16 +4598,27 @@ window.addEventListener('resize', () => {
|
||||
});
|
||||
|
||||
// Initialize
|
||||
initializeBookmarks();
|
||||
loadAutoRefreshSettings();
|
||||
initializeFocusParams();
|
||||
initializeTabFromUrl();
|
||||
updateMergeControlsUI();
|
||||
loadSortMode();
|
||||
resetManualPostForm();
|
||||
loadProfile();
|
||||
startProfilePolling();
|
||||
fetchPosts();
|
||||
checkAutoCheck();
|
||||
startUpdatesStream();
|
||||
applyAutoRefreshSettings();
|
||||
async function bootstrapApp() {
|
||||
const authenticated = await ensureAuthenticated();
|
||||
if (!authenticated) {
|
||||
return;
|
||||
}
|
||||
|
||||
markAppReady();
|
||||
bindLogoutButton();
|
||||
initializeBookmarks();
|
||||
loadAutoRefreshSettings();
|
||||
initializeFocusParams();
|
||||
initializeTabFromUrl();
|
||||
updateMergeControlsUI();
|
||||
loadSortMode();
|
||||
resetManualPostForm();
|
||||
loadProfile();
|
||||
startProfilePolling();
|
||||
fetchPosts();
|
||||
checkAutoCheck();
|
||||
startUpdatesStream();
|
||||
applyAutoRefreshSettings();
|
||||
}
|
||||
|
||||
bootstrapApp();
|
||||
|
||||
Reference in New Issue
Block a user