vor ähnlichkeitsprüfung

This commit is contained in:
2025-12-21 14:21:55 +01:00
parent ffcfce2b31
commit fde5ab91c8
14 changed files with 721 additions and 50 deletions

View File

@@ -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();