compressImage
هذا الالتزام موجود في:
181
admin.js
181
admin.js
@@ -5,77 +5,85 @@
|
||||
// تحديد رابط API بناءً على البيئة
|
||||
const API_BASE = (() => {
|
||||
const host = window.location.hostname;
|
||||
if (host === 'localhost' || host === '127.0.0.1' || host.startsWith('192.168.')) {
|
||||
return `http://${host}:3000/api`; // عدّل المنفذ حسب إعدادات السيرفر
|
||||
if (
|
||||
host === "localhost" ||
|
||||
host === "127.0.0.1" ||
|
||||
host.startsWith("192.168.")
|
||||
) {
|
||||
return `http://147.93.123.146:3003/api`;
|
||||
}
|
||||
return '/api';
|
||||
return "/api";
|
||||
})();
|
||||
|
||||
// --- دالة تسجيل الدخول عبر الخادم ---
|
||||
async function checkAuth() {
|
||||
const password = document.getElementById('adminPassword').value;
|
||||
const password = document.getElementById("adminPassword").value;
|
||||
try {
|
||||
const res = await fetch(API_BASE + '/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ password })
|
||||
const res = await fetch(API_BASE + "/login", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({ password }),
|
||||
});
|
||||
const data = await res.json();
|
||||
if (data.success) {
|
||||
sessionStorage.setItem('adminPass', password);
|
||||
document.getElementById('loginSection').classList.add('hidden');
|
||||
document.getElementById('adminContent').classList.remove('hidden');
|
||||
sessionStorage.setItem("adminPass", password);
|
||||
document.getElementById("loginSection").classList.add("hidden");
|
||||
document.getElementById("adminContent").classList.remove("hidden");
|
||||
loadSettings(); // تحميل الإعدادات بعد الدخول
|
||||
} else {
|
||||
alert('❌ ' + (data.message || 'كلمة المرور غير صحيحة'));
|
||||
alert("❌ " + (data.message || "كلمة المرور غير صحيحة"));
|
||||
}
|
||||
} catch (err) {
|
||||
alert('❌ فشل الاتصال بالخادم. تأكد من تشغيل السيرفر.');
|
||||
alert("❌ فشل الاتصال بالخادم. تأكد من تشغيل السيرفر.");
|
||||
}
|
||||
}
|
||||
|
||||
function logout() {
|
||||
document.getElementById('loginSection').classList.remove('hidden');
|
||||
document.getElementById('adminContent').classList.add('hidden');
|
||||
document.getElementById('adminPassword').value = '';
|
||||
document.getElementById("loginSection").classList.remove("hidden");
|
||||
document.getElementById("adminContent").classList.add("hidden");
|
||||
document.getElementById("adminPassword").value = "";
|
||||
}
|
||||
|
||||
// --- تحميل الإعدادات من الخادم ---
|
||||
async function loadSettings() {
|
||||
try {
|
||||
const res = await fetch(API_BASE + '/settings');
|
||||
if (!res.ok) throw new Error('فشل تحميل الإعدادات');
|
||||
const res = await fetch(API_BASE + "/settings");
|
||||
if (!res.ok) throw new Error("فشل تحميل الإعدادات");
|
||||
const data = await res.json();
|
||||
|
||||
document.getElementById('whatsappNumber').value = data.whatsappNumber || '';
|
||||
document.getElementById('facebookUrl').value = data.facebookUrl || '';
|
||||
document.getElementById('instagramUrl').value = data.instagramUrl || '';
|
||||
document.getElementById('appStoreUrl').value = data.appStoreUrl || '';
|
||||
document.getElementById('googlePlayUrl').value = data.googlePlayUrl || '';
|
||||
document.getElementById('apkUrl').value = data.apkUrl || '';
|
||||
document.getElementById("whatsappNumber").value = data.whatsappNumber || "";
|
||||
document.getElementById("facebookUrl").value = data.facebookUrl || "";
|
||||
document.getElementById("instagramUrl").value = data.instagramUrl || "";
|
||||
document.getElementById("whatsappGroupUrl").value = data.whatsappGroupUrl || "";
|
||||
document.getElementById("appStoreUrl").value = data.appStoreUrl || "";
|
||||
document.getElementById("googlePlayUrl").value = data.googlePlayUrl || "";
|
||||
document.getElementById("apkUrl").value = data.apkUrl || "";
|
||||
|
||||
if (data.telegramChatIds && Array.isArray(data.telegramChatIds)) {
|
||||
document.getElementById('telegramChatIds').value = data.telegramChatIds.join('\n');
|
||||
document.getElementById("telegramChatIds").value =
|
||||
data.telegramChatIds.join("\n");
|
||||
}
|
||||
|
||||
renderVideos(data.videos || []);
|
||||
} catch (error) {
|
||||
console.error('خطأ في تحميل الإعدادات:', error);
|
||||
alert('تعذر تحميل الإعدادات. تأكد من تشغيل الخادم.');
|
||||
console.error("خطأ في تحميل الإعدادات:", error);
|
||||
alert("تعذر تحميل الإعدادات. تأكد من تشغيل الخادم.");
|
||||
}
|
||||
}
|
||||
|
||||
// --- عرض الفيديوهات ---
|
||||
function renderVideos(videos) {
|
||||
const container = document.getElementById('videosList');
|
||||
container.innerHTML = '';
|
||||
const container = document.getElementById("videosList");
|
||||
container.innerHTML = "";
|
||||
|
||||
videos.forEach((url, index) => {
|
||||
const videoId = extractYouTubeVideoId(url);
|
||||
const thumbnail = videoId ? `https://img.youtube.com/vi/${videoId}/mqdefault.jpg` : '';
|
||||
const thumbnail = videoId
|
||||
? `https://img.youtube.com/vi/${videoId}/mqdefault.jpg`
|
||||
: "";
|
||||
|
||||
const card = document.createElement('div');
|
||||
card.className = 'bg-zinc-100 p-4 rounded-2xl relative';
|
||||
const card = document.createElement("div");
|
||||
card.className = "bg-zinc-100 p-4 rounded-2xl relative";
|
||||
card.innerHTML = `
|
||||
<img src="${thumbnail}" alt="فيديو" class="w-full h-32 object-cover rounded-xl mb-2">
|
||||
<p class="text-sm truncate" title="${url}">${url}</p>
|
||||
@@ -91,7 +99,7 @@ function extractYouTubeVideoId(url) {
|
||||
const patterns = [
|
||||
/youtube\.com\/watch\?v=([^&]+)/,
|
||||
/youtu\.be\/([^?]+)/,
|
||||
/youtube\.com\/embed\/([^?]+)/
|
||||
/youtube\.com\/embed\/([^?]+)/,
|
||||
];
|
||||
for (let pattern of patterns) {
|
||||
const match = url.match(pattern);
|
||||
@@ -102,127 +110,135 @@ function extractYouTubeVideoId(url) {
|
||||
|
||||
// --- إضافة فيديو جديد ---
|
||||
async function addVideo() {
|
||||
const url = document.getElementById('newVideoUrl').value.trim();
|
||||
const url = document.getElementById("newVideoUrl").value.trim();
|
||||
if (!url) {
|
||||
alert('الرجاء إدخال رابط الفيديو');
|
||||
alert("الرجاء إدخال رابط الفيديو");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch(API_BASE + '/settings');
|
||||
const res = await fetch(API_BASE + "/settings");
|
||||
const data = await res.json();
|
||||
const videos = data.videos || [];
|
||||
videos.push(url);
|
||||
|
||||
const updateRes = await fetch(API_BASE + '/settings', {
|
||||
method: 'POST',
|
||||
const updateRes = await fetch(API_BASE + "/settings", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-admin-password': sessionStorage.getItem('adminPass') || ''
|
||||
"Content-Type": "application/json",
|
||||
"x-admin-password": sessionStorage.getItem("adminPass") || "",
|
||||
},
|
||||
body: JSON.stringify({ videos })
|
||||
body: JSON.stringify({ videos }),
|
||||
});
|
||||
|
||||
if (updateRes.ok) {
|
||||
document.getElementById('newVideoUrl').value = '';
|
||||
document.getElementById("newVideoUrl").value = "";
|
||||
loadSettings(); // إعادة تحميل القائمة
|
||||
alert('✅ تمت إضافة الفيديو بنجاح');
|
||||
alert("✅ تمت إضافة الفيديو بنجاح");
|
||||
} else {
|
||||
alert('❌ فشل إضافة الفيديو');
|
||||
alert("❌ فشل إضافة الفيديو");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
alert('❌ خطأ في الاتصال بالخادم');
|
||||
alert("❌ خطأ في الاتصال بالخادم");
|
||||
}
|
||||
}
|
||||
|
||||
// --- حذف فيديو ---
|
||||
async function deleteVideo(index) {
|
||||
if (!confirm('هل أنت متأكد من حذف هذا الفيديو؟')) return;
|
||||
if (!confirm("هل أنت متأكد من حذف هذا الفيديو؟")) return;
|
||||
|
||||
try {
|
||||
const res = await fetch(API_BASE + '/settings');
|
||||
const res = await fetch(API_BASE + "/settings");
|
||||
const data = await res.json();
|
||||
const videos = data.videos || [];
|
||||
videos.splice(index, 1);
|
||||
|
||||
const updateRes = await fetch(API_BASE + '/settings', {
|
||||
method: 'POST',
|
||||
const updateRes = await fetch(API_BASE + "/settings", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-admin-password': sessionStorage.getItem('adminPass') || ''
|
||||
"Content-Type": "application/json",
|
||||
"x-admin-password": sessionStorage.getItem("adminPass") || "",
|
||||
},
|
||||
body: JSON.stringify({ videos })
|
||||
body: JSON.stringify({ videos }),
|
||||
});
|
||||
|
||||
if (updateRes.ok) {
|
||||
loadSettings();
|
||||
alert('✅ تم الحذف');
|
||||
alert("✅ تم الحذف");
|
||||
} else {
|
||||
alert('❌ فشل الحذف');
|
||||
alert("❌ فشل الحذف");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
alert('❌ خطأ في الاتصال');
|
||||
alert("❌ خطأ في الاتصال");
|
||||
}
|
||||
}
|
||||
|
||||
// --- دوال تحديث الحقول الفردية ---
|
||||
async function updateWhatsApp() {
|
||||
const value = document.getElementById('whatsappNumber').value.trim();
|
||||
await updateField('whatsappNumber', value);
|
||||
const value = document.getElementById("whatsappNumber").value.trim();
|
||||
await updateField("whatsappNumber", value);
|
||||
}
|
||||
async function updateFacebook() {
|
||||
const value = document.getElementById('facebookUrl').value.trim();
|
||||
await updateField('facebookUrl', value);
|
||||
const value = document.getElementById("facebookUrl").value.trim();
|
||||
await updateField("facebookUrl", value);
|
||||
}
|
||||
async function updateInstagram() {
|
||||
const value = document.getElementById('instagramUrl').value.trim();
|
||||
await updateField('instagramUrl', value);
|
||||
const value = document.getElementById("instagramUrl").value.trim();
|
||||
await updateField("instagramUrl", value);
|
||||
}
|
||||
async function updateWhatsAppGroup() {
|
||||
const value = document.getElementById("whatsappGroupUrl").value.trim();
|
||||
await updateField("whatsappGroupUrl", value);
|
||||
}
|
||||
async function updateAppStore() {
|
||||
const value = document.getElementById('appStoreUrl').value.trim();
|
||||
await updateField('appStoreUrl', value);
|
||||
const value = document.getElementById("appStoreUrl").value.trim();
|
||||
await updateField("appStoreUrl", value);
|
||||
}
|
||||
async function updateGooglePlay() {
|
||||
const value = document.getElementById('googlePlayUrl').value.trim();
|
||||
await updateField('googlePlayUrl', value);
|
||||
const value = document.getElementById("googlePlayUrl").value.trim();
|
||||
await updateField("googlePlayUrl", value);
|
||||
}
|
||||
async function updateApk() {
|
||||
const value = document.getElementById('apkUrl').value.trim();
|
||||
await updateField('apkUrl', value);
|
||||
const value = document.getElementById("apkUrl").value.trim();
|
||||
await updateField("apkUrl", value);
|
||||
}
|
||||
|
||||
async function updateTelegramChatIds() {
|
||||
const text = document.getElementById('telegramChatIds').value.trim();
|
||||
const ids = text.split('\n')
|
||||
.map(line => line.trim())
|
||||
.filter(line => line !== '');
|
||||
await updateField('telegramChatIds', ids);
|
||||
const text = document.getElementById("telegramChatIds").value.trim();
|
||||
const ids = text
|
||||
.split("\n")
|
||||
.map((line) => line.trim())
|
||||
.filter((line) => line !== "");
|
||||
await updateField("telegramChatIds", ids);
|
||||
}
|
||||
|
||||
// دالة عامة لتحديث حقل واحد
|
||||
async function updateField(key, value) {
|
||||
const password = document.getElementById('adminPassword').value || sessionStorage.getItem('adminPass') || '';
|
||||
const password =
|
||||
document.getElementById("adminPassword").value ||
|
||||
sessionStorage.getItem("adminPass") ||
|
||||
"";
|
||||
try {
|
||||
const res = await fetch(API_BASE + '/settings', {
|
||||
method: 'POST',
|
||||
const res = await fetch(API_BASE + "/settings", {
|
||||
method: "POST",
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'x-admin-password': password
|
||||
"Content-Type": "application/json",
|
||||
"x-admin-password": password,
|
||||
},
|
||||
body: JSON.stringify({ [key]: value })
|
||||
body: JSON.stringify({ [key]: value }),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
alert('✅ تم الحفظ بنجاح');
|
||||
alert("✅ تم الحفظ بنجاح");
|
||||
} else {
|
||||
const err = await res.json();
|
||||
alert('❌ فشل الحفظ: ' + (err.message || 'خطأ غير معروف'));
|
||||
alert("❌ فشل الحفظ: " + (err.message || "خطأ غير معروف"));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
alert('❌ خطأ في الاتصال بالخادم');
|
||||
alert("❌ خطأ في الاتصال بالخادم");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -237,4 +253,5 @@ window.updateInstagram = updateInstagram;
|
||||
window.updateAppStore = updateAppStore;
|
||||
window.updateGooglePlay = updateGooglePlay;
|
||||
window.updateApk = updateApk;
|
||||
window.updateTelegramChatIds = updateTelegramChatIds;
|
||||
window.updateTelegramChatIds = updateTelegramChatIds;
|
||||
window.updateWhatsAppGroup = updateWhatsAppGroup;
|
||||
|
||||
المرجع في مشكلة جديدة
حظر مستخدم