Files
Agora/views/settings.ejs
T
2026-09-15 21:45:47 +02:00

410 lines
32 KiB
Plaintext

<%- include('partials/header') %>
<script src="/sortable.min.js"></script>
<%- include('partials/sidebar') %>
<main class="content-wrapper">
<section id="section-settings" class="section">
<div class="hero-header">
<h2>Paramètres</h2>
</div>
<% if (typeof currentUser !== 'undefined' && currentUser && currentUser.role === 'admin') { %>
<div class="form-card" style="max-width: 750px; margin: 0 auto 1.5rem auto;">
<h3 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; display: flex; align-items: center; justify-content: space-between;">
<span style="display: flex; align-items: center; gap: 8px;"><i data-lucide="refresh-cw"></i> Système & Mises à jour</span>
<span style="font-size: 0.75rem; background: rgba(255,255,255,0.1); padding: 4px 8px; border-radius: 4px; font-family: monospace;">v<%= appVersion %></span>
</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Vérifiez si une nouvelle version d'Agora est disponible et consultez les instructions de mise à jour.
</p>
<button id="check-update-btn" class="btn-action" style="padding: 10px 20px; display: flex; align-items: center; justify-content: center; gap: 8px;">
<i data-lucide="download-cloud" style="width: 16px; height: 16px;"></i> Vérifier les mises à jour
</button>
<div id="update-results-container" style="display: none; margin-top: 1.5rem; padding-top: 1.5rem; border-top: 1px dashed var(--border);">
<!-- Injecté par JS -->
</div>
</div>
<% } %>
<div class="form-card" style="max-width: 750px; margin: 0 auto 1.5rem auto;">
<h3 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="database"></i> Sources de Recherche
</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Sélectionnez la source principale (prioritaire) et les sources secondaires à utiliser.
</p>
<div style="margin-bottom: 1.5rem;">
<label style="display: block; font-weight: 600; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="list-ordered" style="color: var(--primary); width: 18px; height: 18px;"></i> Priorité & Activation des Sources
</label>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1.2rem;">
Activez les sources et glissez-déposez pour définir leur ordre de priorité. La première source active (cochée) sera la source principale.
</p>
<div id="sources-sortable-container" style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 1rem;">
<!-- Les sources ordonnables seront injectées ici par JS -->
</div>
</div>
</div>
<% if (typeof currentUser !== 'undefined' && currentUser && currentUser.role === 'admin') { %>
<div class="form-card" style="max-width: 750px; margin: 0 auto 1.5rem auto;">
<h3 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="server"></i> Hébergeurs Préférés
</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Glissez et déposez les hébergeurs pour définir leur ordre de préférence. Les liens de téléchargement seront triés selon cet ordre.
</p>
<div id="hosters-sortable-container" style="display: flex; flex-direction: column; gap: 10px; margin-bottom: 1rem;">
<% if (typeof preferredHosters !== 'undefined' && preferredHosters.length > 0) { %>
<% preferredHosters.forEach(function(hoster) {
const h = hoster.toLowerCase();
let domain = h + '.com';
if (h === 'turbobit') domain = 'turbobit.net';
if (h === 'rapidgator') domain = 'rapidgator.net';
if (h === 'mega') domain = 'mega.nz';
if (h === 'gofile') domain = 'gofile.io';
if (h === 'nitroflare') domain = 'nitroflare.com';
%>
<div class="sortable-item" data-hoster="<%= hoster %>" style="display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--bg-main); border: 1px solid var(--border); border-radius: 8px; cursor: grab;">
<div style="display: flex; align-items: center; gap: 12px;">
<i data-lucide="grip-vertical" style="color: var(--text-sec); width: 18px; height: 18px;"></i>
<img src="https://www.google.com/s2/favicons?domain=<%= domain %>&sz=32" alt="logo" style="width: 20px; height: 20px; border-radius: 4px;" onerror="this.style.display='none'; this.nextElementSibling.style.display='inline-block';">
<i data-lucide="server" style="color: var(--text-sec); width: 18px; height: 18px; display: none;"></i>
<span style="font-weight: 500; text-transform: capitalize;"><%= hoster %></span>
</div>
</div>
<% }); %>
<% } %>
</div>
<div style="display: flex; gap: 10px;">
<button id="save-hosters-btn" class="btn-action" style="padding: 10px 20px; display: flex; align-items: center; justify-content: center; gap: 8px; flex: 1;">
<i data-lucide="save" style="width: 16px; height: 16px;"></i> Enregistrer l'ordre
</button>
</div>
</div>
<div class="form-card" style="max-width: 750px; margin: 0 auto 1.5rem auto;">
<h3 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="plug"></i> Configuration des Plugins
</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Modifiez les adresses et clés d'accès des plugins. Les modifications seront appliquées immédiatement sans redémarrage.
</p>
<form id="plugins-config-form">
<% if (typeof pluginsToConfigure !== 'undefined' && pluginsToConfigure.length > 0) { %>
<% pluginsToConfigure.forEach(function(plugin) { %>
<div style="background: rgba(255,255,255,0.03); border: 1px solid var(--border); border-radius: 8px; padding: 1rem; margin-bottom: 1rem;">
<strong style="display: flex; align-items: center; gap: 6px; margin-bottom: 0.8rem; color: var(--text-main); font-size: 0.95rem; text-transform: capitalize;">
<i data-lucide="box" style="width: 14px; height: 14px; color: var(--text-sec);"></i>
<%= plugin.name %>
</strong>
<%
const urlField = plugin.fields.find(f => f.key.endsWith('_URL'));
const urlEmpty = urlField && !urlField.default;
%>
<% if (plugin.name.includes('TMDB')) { %>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 12px; margin-top: -8px;">
<i data-lucide="info" style="width: 14px; height: 14px; vertical-align: middle;"></i>
Pour obtenir une clé d'API, créez un compte gratuit sur <a href="https://www.themoviedb.org/settings/api" target="_blank" style="color: var(--primary);">themoviedb.org</a>, générez une clé (API v3 Auth) et collez-la ci-dessous.
</p>
<% plugin.fields.forEach(function(field) { %>
<div style="margin-bottom: 0.8rem;">
<label for="config_<%= field.key %>" style="font-size: 0.8rem; color: var(--text-sec); margin-bottom: 4px; display: block;"><%= field.label %></label>
<% if (field.key.endsWith('_ENABLED') || field.key === 'JD_FORCED_START') { %>
<select id="config_<%= field.key %>" name="<%= field.key %>" style="width: 100%; padding: 10px; background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: 6px; color: var(--text-main); font-size: 0.9rem;">
<option value="true" <%= field.default === 'true' ? 'selected' : '' %>>Activé</option>
<option value="false" <%= field.default === 'false' ? 'selected' : '' %>>Désactivé</option>
</select>
<% } else { %>
<input type="text" id="config_<%= field.key %>" name="<%= field.key %>"
placeholder="<%= field.placeholder %>" value="<%= field.default || '' %>"
style="width: 100%; padding: 10px; background: rgba(0,0,0,0.2); border: 1px solid var(--border); border-radius: 6px; color: var(--text-main); font-size: 0.9rem;">
<% } %>
</div>
<% }); %>
<% } else { %>
<% plugin.fields.forEach(function(field) { %>
<div style="margin-bottom: 0.8rem;">
<label for="config_<%= field.key %>" style="font-size: 0.8rem; color: var(--text-sec); margin-bottom: 4px; display: block;"><%= field.label %></label>
<input type="text" id="config_<%= field.key %>" name="<%= field.key %>"
placeholder="<%= field.placeholder %>" value="<%= field.default || '' %>"
data-is-url="<%= field.key.endsWith('_URL') ? 'true' : 'false' %>"
data-plugin="<%= plugin.name %>"
style="padding: 8px; font-size: 0.9rem; width: 100%; border: 1px solid var(--border); background: var(--bg-main); color: var(--text-main); border-radius: 6px;">
</div>
<% }); %>
<% } %>
</div>
<% }); %>
<div style="display: flex; gap: 10px;">
<button type="submit" class="btn-action" style="padding: 10px 20px; display: flex; align-items: center; justify-content: center; gap: 8px; flex: 1;">
<i data-lucide="save" style="width: 16px; height: 16px;"></i> Enregistrer & Recharger
</button>
</div>
<% } else { %>
<p style="font-size: 0.85rem; color: var(--text-sec);">Aucun plugin détecté.</p>
<% } %>
</form>
</div>
<% } %>
<div class="form-card" style="max-width: 750px; margin: 0 auto 1.5rem auto;">
<h3 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem;">
Page d'accueil par défaut</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Sélectionnez la page sur laquelle vous souhaitez être redirigé par défaut à l'ouverture de
l'application.
</p>
<select id="select-default-page" style="margin-top: 0.5rem; margin-bottom: 0;">
<option value="/trending">Tendances</option>
<option value="/recent">Ajouts récents</option>
<option value="/search">Recherche</option>
<option value="/downloads">Téléchargements</option>
<option value="/manual">Ajout manuel</option>
<option value="/settings">Paramètres</option>
</select>
</div>
<div class="form-card" style="max-width: 750px; margin: 0 auto;">
<label style="display: flex; align-items: center; justify-content: space-between; cursor: pointer;">
<span style="font-weight: 600;">Intégration JDownloader</span>
<input type="checkbox" id="toggle-jd" style="width: 20px; height: 20px;">
</label>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-top: 10px;">Si désactivé, le lien
1fichier sera affiché directement sous forme de pop-up sans être envoyé à JDownloader.</p>
</div>
<% if (typeof currentUser !== 'undefined' && currentUser && currentUser.role === 'admin') { %>
<div class="form-card" style="max-width: 750px; margin: 1.5rem auto 0 auto;">
<h3 style="margin-bottom: 1rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="users" style="width: 20px; height: 20px;"></i> Gestion des Utilisateurs
</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Gérez les comptes utilisateurs. Seuls les administrateurs ont accès à cette section.
</p>
<!-- Liste des utilisateurs -->
<div id="admin-users-list" style="display: flex; flex-direction: column; gap: 8px; margin-bottom: 1.5rem;">
<!-- Injecté par JS -->
</div>
<!-- Formulaire d'ajout -->
<div style="border-top: 1px solid var(--border); padding-top: 1rem;">
<label style="display: block; font-weight: 600; margin-bottom: 0.5rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="user-plus" style="color: var(--primary); width: 16px; height: 16px;"></i> Ajouter un utilisateur
</label>
<div style="display: flex; gap: 10px; margin-bottom: 12px; align-items: center;">
<input type="text" id="admin-new-username" placeholder="Nom d'utilisateur"
style="flex: 1; margin: 0; padding: 12px 16px;"
minlength="3" maxlength="32" pattern="[a-zA-Z0-9_.\-]+">
<select id="admin-new-role" style="width: auto; min-width: 130px; margin: 0; padding: 12px 16px;">
<option value="user">Utilisateur</option>
<option value="admin">Admin</option>
</select>
</div>
<button id="admin-add-user-btn" class="btn-action" style="width: 100%; padding: 12px 20px;">
Créer l'utilisateur
</button>
</div>
</div>
<% } %>
<!-- Modal pour afficher le mot de passe généré -->
<div id="admin-password-modal" class="modal-overlay hidden">
<div class="modal-content" style="max-width: 420px;">
<h3 style="margin-bottom: 1rem; display: flex; align-items: center; gap: 8px;">
<i data-lucide="key" style="width: 20px; height: 20px; color: var(--primary);"></i>
Mot de passe généré
</h3>
<p style="font-size: 0.85rem; color: var(--text-sec); margin-bottom: 1rem;">
Copiez ce mot de passe et transmettez-le à l'utilisateur. Il ne sera plus affiché.
</p>
<div id="admin-generated-password" style="background: var(--bg-main); border: 1px solid var(--border); border-radius: 8px; padding: 14px; font-family: monospace; font-size: 1.1rem; text-align: center; color: var(--primary); font-weight: 700; letter-spacing: 1px; user-select: all; cursor: text; word-break: break-all;"></div>
<button id="admin-copy-password-btn" style="width: 100%; margin-top: 1rem; padding: 10px; border-radius: 8px; background: var(--bg-card); border: 1px solid var(--border); color: white; font-weight: 600; cursor: pointer;">
Copier le mot de passe
</button>
<button id="admin-close-modal-btn" style="width: 100%; margin-top: 0.5rem; padding: 10px; border-radius: 8px; background: var(--primary); border: none; color: white; font-weight: 600; cursor: pointer;">
Fermer
</button>
</div>
</div>
<div style="text-align: center; margin-top: 3rem; margin-bottom: 1rem;">
<p style="font-size: 0.85rem; color: var(--text-sec); display: inline-flex; align-items: center; gap: 6px; background: var(--bg-card); padding: 6px 12px; border-radius: 20px; border: 1px solid var(--border);">
<i data-lucide="info" style="width: 14px; height: 14px;"></i>
Agora v<%= appVersion %>
</p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
// --- Plugins Config Form ---
const form = document.getElementById('plugins-config-form');
if (form) {
form.addEventListener('submit', async (e) => {
e.preventDefault();
const btn = form.querySelector('button[type="submit"]');
const origHtml = btn.innerHTML;
btn.innerHTML = '<i data-lucide="loader-2" class="spin" style="width: 16px; height: 16px;"></i> Enregistrement...';
btn.disabled = true;
if (window.lucide) lucide.createIcons();
const fd = new FormData(form);
const config = Object.fromEntries(fd.entries());
try {
const res = await fetch('/api/admin/plugins/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ config })
});
const data = await res.json();
if (data.success) {
window.showModal(
'Succès',
`<div style="padding: 1rem; text-align: center; color: var(--text-main);">
<i data-lucide="check-circle" style="color: #10b981; width: 48px; height: 48px; margin-bottom: 1rem;"></i>
<p>Configuration enregistrée avec succès.</p>
<p style="font-size: 0.9rem; color: var(--text-sec); margin-top: 0.5rem;">Plugins actifs : ${data.activeSources.join(', ')}</p>
</div>`
);
if (window.lucide) lucide.createIcons();
setTimeout(() => window.location.reload(), 2000);
} else {
window.showModal('Erreur', `<div style="padding: 1rem; text-align: center; color: #ef4444;"><p>${data.error}</p></div>`);
}
} catch (err) {
window.showModal('Erreur', `<div style="padding: 1rem; text-align: center; color: #ef4444;"><p>Erreur lors de la sauvegarde.</p></div>`);
console.error(err);
} finally {
btn.innerHTML = origHtml;
btn.disabled = false;
if (window.lucide) lucide.createIcons();
}
});
}
// --- Hosters Sorting ---
const hostersContainer = document.getElementById('hosters-sortable-container');
if (hostersContainer) {
Sortable.create(hostersContainer, {
animation: 150,
handle: '.sortable-item', // Permet de draguer sur tout l'item
ghostClass: 'dragging-hoster', // Classe appliquée pendant le drag
});
document.getElementById('save-hosters-btn')?.addEventListener('click', async (e) => {
const btn = e.currentTarget;
const origHtml = btn.innerHTML;
btn.innerHTML = '<i data-lucide="loader-2" class="spin" style="width: 16px; height: 16px;"></i> Enregistrement...';
btn.disabled = true;
if (window.lucide) lucide.createIcons();
const order = Array.from(hostersContainer.querySelectorAll('.sortable-item')).map(el => el.dataset.hoster);
try {
const res = await fetch('/api/admin/hosters/save', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ preferredHosters: order })
});
const data = await res.json();
if (data.success) {
window.showModal(
'Succès',
`<div style="padding: 1rem; text-align: center; color: var(--text-main);">
<i data-lucide="check-circle" style="color: #10b981; width: 48px; height: 48px; margin-bottom: 1rem;"></i>
<p>Ordre des hébergeurs enregistré avec succès !</p>
</div>`
);
if (window.lucide) lucide.createIcons();
} else {
window.showModal('Erreur', `<div style="padding: 1rem; text-align: center; color: #ef4444;"><p>${data.error}</p></div>`);
}
} catch (err) {
window.showModal('Erreur', `<div style="padding: 1rem; text-align: center; color: #ef4444;"><p>Erreur réseau lors de la sauvegarde.</p></div>`);
} finally {
btn.innerHTML = origHtml;
btn.disabled = false;
if (window.lucide) lucide.createIcons();
}
});
}
// --- Updates Checking ---
const checkUpdateBtn = document.getElementById('check-update-btn');
if (checkUpdateBtn) {
checkUpdateBtn.addEventListener('click', async () => {
const btn = checkUpdateBtn;
const origHtml = btn.innerHTML;
btn.innerHTML = '<i data-lucide="loader-2" class="spin" style="width: 16px; height: 16px;"></i> Vérification...';
btn.disabled = true;
if (window.lucide) lucide.createIcons();
const container = document.getElementById('update-results-container');
container.style.display = 'none';
container.innerHTML = '';
try {
const res = await fetch('/api/admin/check-update');
const data = await res.json();
if (data.success) {
container.style.display = 'block';
const isNew = data.currentVersion !== data.latestVersion;
let html = '';
if (isNew) {
html += `<div style="background: rgba(16, 185, 129, 0.1); border: 1px solid #10b981; padding: 12px; border-radius: 6px; margin-bottom: 1rem; color: #10b981; font-weight: 600; display: flex; align-items: center; gap: 8px;">
<i data-lucide="party-popper" style="width: 20px; height: 20px;"></i> Nouvelle version disponible : ${data.latestVersion} !
</div>`;
} else {
html += `<div style="background: rgba(255, 255, 255, 0.05); border: 1px solid var(--border); padding: 12px; border-radius: 6px; margin-bottom: 1rem; color: var(--text-main); font-weight: 500; display: flex; align-items: center; gap: 8px;">
<i data-lucide="check-circle" style="color: #10b981; width: 20px; height: 20px;"></i> Votre système est à jour (v${data.currentVersion}).
</div>`;
}
if (data.notes && data.notes.length > 0) {
html += `<h4 style="margin-bottom: 8px; font-size: 0.9rem;">Nouveautés :</h4><ul style="margin: 0 0 1rem 0; padding-left: 20px; color: var(--text-sec); font-size: 0.85rem; line-height: 1.5;">`;
data.notes.forEach(n => html += `<li>${n}</li>`);
html += `</ul>`;
}
html += `<h4 style="margin-bottom: 8px; font-size: 0.9rem;">Comment mettre à jour :</h4>
<div style="display: flex; flex-direction: column; gap: 10px;">
<div style="background: var(--bg-main); padding: 12px; border-radius: 6px; border: 1px solid var(--border);">
<strong style="display: block; font-size: 0.8rem; color: var(--primary); margin-bottom: 4px;">Via Docker</strong>
<code style="font-size: 0.85rem; color: var(--text-main); user-select: all; cursor: text;">${data.updateInfo.dockerCmd}</code>
</div>
<div style="background: var(--bg-main); padding: 12px; border-radius: 6px; border: 1px solid var(--border);">
<strong style="display: block; font-size: 0.8rem; color: var(--primary); margin-bottom: 4px;">Installation Manuelle (.zip)</strong>
<a href="${data.updateInfo.zipUrl}" target="_blank" style="font-size: 0.85rem; color: var(--text-main); text-decoration: underline;">Télécharger l'archive depuis le site</a>
${data.updateInfo.zipSha256 ? `<div style="margin-top: 8px; font-size: 0.8rem; color: var(--text-muted);">Somme de contrôle (SHA-256) :<br><code style="font-size: 0.75rem; user-select: all; background: rgba(0,0,0,0.2); padding: 2px 4px; border-radius: 4px; word-break: break-all;">${data.updateInfo.zipSha256}</code></div>` : ''}
</div>
</div>`;
container.innerHTML = html;
} else {
window.showModal('Erreur', `<div style="padding: 1rem; text-align: center; color: #ef4444;"><p>${data.error}</p></div>`);
}
} catch (err) {
window.showModal('Erreur', `<div style="padding: 1rem; text-align: center; color: #ef4444;"><p>Erreur réseau lors de la vérification.</p></div>`);
} finally {
btn.innerHTML = origHtml;
btn.disabled = false;
if (window.lucide) lucide.createIcons();
}
});
}
});
</script>
</section>
</main>
<%- include('partials/footer') %>