🚀 مُصادَق: تحديث برمجي جديد 2026-05-03 01:26

This commit is contained in:
Hamza-Ayed
2026-05-03 01:26:23 +03:00
parent 6373f7572f
commit 5dbbbc1c8a
2 changed files with 22 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
/**
* مُصادَق — API Client with JWT Auth & Refresh Flow
*/
const API = {
window.API = {
baseUrl: '/Application/public/api.php',
accessToken: localStorage.getItem('access_token'),

View File

@@ -231,13 +231,13 @@
const errorEl = document.getElementById('login-error');
try {
const result = await API.post('/auth/login', { email, password });
const result = await window.API.post('/auth/login', { email, password });
if (result.success) {
localStorage.setItem('access_token', result.data.access_token);
if (result.data.refresh_token) {
localStorage.setItem('refresh_token', result.data.refresh_token);
}
API.accessToken = result.data.access_token;
window.API.accessToken = result.data.access_token;
navigate();
}
} catch (err) {
@@ -250,6 +250,25 @@
}
}
// ── AI Query Handler ─────────────────────────────────────
document.getElementById('ai-query').addEventListener('keydown', async (e) => {
if (e.key === 'Enter') {
const query = e.target.value;
const answerEl = document.getElementById('ai-answer');
if (!query) return;
answerEl.textContent = 'جاري التحليل...';
e.target.value = '';
try {
const res = await window.API.post('/ai/query', { query });
answerEl.textContent = res.data.answer;
} catch (err) {
answerEl.textContent = 'عذراً، حدث خطأ أثناء معالجة طلبك.';
}
}
});
// ── Start the app ────────────────────────────────────────
navigate();
</script>