Download api/upload.php from felix-fx/fx-1: direct link, hf CLI and curl.
- Browser
- Download file 3.26 kB
-
https://huggingface.co/felix-fx/fx-1/resolve/main/api/upload.php
- Command line
-
hf download hf://felix-fx/fx-1/api/upload.php
-
curl -L -o upload.php https://huggingface.co/felix-fx/fx-1/resolve/main/api/upload.php
3.26 kB
| // /api/upload.php | |
| require_once __DIR__ . '/utils/Config.php'; | |
| require_once __DIR__ . '/utils/Response.php'; | |
| require_once __DIR__ . '/services/FileValidator.php'; | |
| require_once __DIR__ . '/services/ModrinthService.php'; | |
| require_once __DIR__ . '/services/SupabaseService.php'; | |
| // تحميل الإعدادات | |
| Config::load(__DIR__ . '/../.env'); | |
| // التأكد من أن الطلب POST | |
| if ($_SERVER['REQUEST_METHOD'] !== 'POST') { | |
| Response::error('يُسمح بطلبات POST فقط.', 405); | |
| } | |
| // استلام البيانات من FormData | |
| $title = $_POST['addonTitle'] ?? null; | |
| $description = $_POST['shortDescription'] ?? null; | |
| $gameVersions = isset($_POST['gameVersions']) ? json_decode($_POST['gameVersions'], true) : []; | |
| $projectType = $_POST['projectType'] ?? 'mod'; | |
| $loaderType = $_POST['loaderType'] ?? 'fabric'; // افتراضي لـ Java | |
| $file = $_FILES['addonFile'] ?? null; | |
| // التحقق الأولي | |
| if (!$title || !$description || empty($gameVersions) || !$file) { | |
| Response::error('يرجى إكمال جميع الحقول المطلوبة.'); | |
| } | |
| try { | |
| // 1. التحقق من الملف | |
| $validator = new FileValidator(); | |
| $basicCheck = $validator->validateBasic($file); | |
| if (!$basicCheck['valid']) { | |
| Response::error($basicCheck['error']); | |
| } | |
| $contentCheck = $validator->validateContent($file['tmp_name'], $basicCheck['extension']); | |
| if (!$contentCheck['valid']) { | |
| Response::error($contentCheck['error']); | |
| } | |
| // 2. إنشاء مشروع على Modrinth | |
| $modrinth = new ModrinthService(Config::get('MODRINTH_TOKEN')); | |
| $project = $modrinth->createProject([ | |
| 'title' => $title, | |
| 'description' => $description, | |
| 'project_type' => $projectType, | |
| 'categories' => [$loaderType] // يمكن إضافة المزيد حسب الحاجة | |
| ]); | |
| $modrinthProjectId = $project['id']; | |
| $modrinthSlug = $project['slug']; | |
| // 3. رفع النسخة الأولى للملف | |
| $version = $modrinth->createVersion($modrinthProjectId, [ | |
| 'name' => $title . ' v1.0.0', | |
| 'version_number' => '1.0.0', | |
| 'game_versions' => $gameVersions, | |
| 'loaders' => [$loaderType] | |
| ], $file['tmp_name']); | |
| // 4. حفظ البيانات في Supabase | |
| $supabase = new SupabaseService( | |
| Config::get('SUPABASE_URL'), | |
| Config::get('SUPABASE_SERVICE_KEY') | |
| ); | |
| $supabaseData = [ | |
| 'title' => $title, | |
| 'description' => $description, | |
| 'modrinth_id' => $modrinthProjectId, | |
| 'modrinth_slug' => $modrinthSlug, | |
| 'project_type' => $projectType, | |
| 'upload_status' => 'unlisted', | |
| 'file_size' => $file['size'], | |
| 'minecraft_versions' => $gameVersions | |
| ]; | |
| $saved = $supabase->saveAddon($supabaseData); | |
| // نجاح! | |
| Response::success([ | |
| 'message' => 'تم الرفع والربط بنجاح!', | |
| 'modrinth_url' => "https://modrinth.com/{$projectType}/{$modrinthSlug}", | |
| 'project_id' => $modrinthProjectId | |
| ]); | |
| } catch (Exception $e) { | |
| // تسجيل الخطأ في السجل (اختياري) | |
| error_log($e->getMessage()); | |
| Response::error('حدث خطأ أثناء المعالجة: ' . $e->getMessage(), 500); | |
| } | |