aktueller stand

This commit is contained in:
2025-12-29 19:45:08 +01:00
parent fde5ab91c8
commit 677eac2632
6 changed files with 1888 additions and 272 deletions

View File

@@ -72,6 +72,10 @@ let moderationSettings = {
sports_terms: {},
sports_auto_hide_enabled: false
};
let similaritySettings = {
text_threshold: 0.85,
image_distance_threshold: 6
};
function handleUnauthorized(response) {
if (response && response.status === 401) {
@@ -405,6 +409,84 @@ async function saveModerationSettings(event, { silent = false } = {}) {
}
}
function normalizeSimilarityTextThresholdInput(value) {
const parsed = parseFloat(value);
if (Number.isNaN(parsed)) {
return 0.85;
}
return Math.min(0.99, Math.max(0.5, parsed));
}
function normalizeSimilarityImageThresholdInput(value) {
const parsed = parseInt(value, 10);
if (Number.isNaN(parsed)) {
return 6;
}
return Math.min(64, Math.max(0, parsed));
}
function applySimilaritySettingsUI() {
const textInput = document.getElementById('similarityTextThreshold');
const imageInput = document.getElementById('similarityImageThreshold');
if (textInput) {
textInput.value = similaritySettings.text_threshold ?? 0.85;
}
if (imageInput) {
imageInput.value = similaritySettings.image_distance_threshold ?? 6;
}
}
async function loadSimilaritySettings() {
const res = await apiFetch(`${API_URL}/similarity-settings`);
if (!res.ok) throw new Error('Konnte Ähnlichkeits-Einstellungen nicht laden');
const data = await res.json();
similaritySettings = {
text_threshold: normalizeSimilarityTextThresholdInput(data.text_threshold),
image_distance_threshold: normalizeSimilarityImageThresholdInput(data.image_distance_threshold)
};
applySimilaritySettingsUI();
}
async function saveSimilaritySettings(event, { silent = false } = {}) {
if (event && typeof event.preventDefault === 'function') {
event.preventDefault();
}
const textInput = document.getElementById('similarityTextThreshold');
const imageInput = document.getElementById('similarityImageThreshold');
const textThreshold = textInput
? normalizeSimilarityTextThresholdInput(textInput.value)
: similaritySettings.text_threshold;
const imageThreshold = imageInput
? normalizeSimilarityImageThresholdInput(imageInput.value)
: similaritySettings.image_distance_threshold;
try {
const res = await apiFetch(`${API_URL}/similarity-settings`, {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text_threshold: textThreshold,
image_distance_threshold: imageThreshold
})
});
if (!res.ok) {
const err = await res.json();
throw new Error(err.error || 'Fehler beim Speichern');
}
similaritySettings = await res.json();
applySimilaritySettingsUI();
if (!silent) {
showSuccess('✅ Ähnlichkeitsregeln gespeichert');
}
return true;
} catch (err) {
if (!silent) {
showError('❌ ' + err.message);
}
return false;
}
}
function shorten(text, maxLength = 80) {
if (typeof text !== 'string') {
return '';
@@ -1041,6 +1123,7 @@ async function saveAllSettings(event) {
saveSettings(null, { silent: true }),
saveHiddenSettings(null, { silent: true }),
saveModerationSettings(null, { silent: true }),
saveSimilaritySettings(null, { silent: true }),
saveAllFriends({ silent: true })
]);
@@ -1208,12 +1291,30 @@ if (sportsScoringToggle && sportsScoreInput) {
}
}
const similarityForm = document.getElementById('similaritySettingsForm');
if (similarityForm) {
const textInput = document.getElementById('similarityTextThreshold');
const imageInput = document.getElementById('similarityImageThreshold');
if (textInput) {
textInput.addEventListener('blur', () => {
textInput.value = normalizeSimilarityTextThresholdInput(textInput.value);
});
}
if (imageInput) {
imageInput.addEventListener('blur', () => {
imageInput.value = normalizeSimilarityImageThresholdInput(imageInput.value);
});
}
similarityForm.addEventListener('submit', (e) => saveSimilaritySettings(e));
}
// Initialize
Promise.all([
loadCredentials(),
loadSettings(),
loadHiddenSettings(),
loadModerationSettings(),
loadSimilaritySettings(),
loadProfileFriends()
]).catch(err => showError(err.message));
})();