Download src/lib/fileTypes.ts from felix-fx/fx-1: direct link, hf CLI and curl.
- Browser
- Download file 6.89 kB
-
https://huggingface.co/felix-fx/fx-1/resolve/main/src/lib/fileTypes.ts
- Command line
-
hf download hf://felix-fx/fx-1/src/lib/fileTypes.ts
-
curl -L -o fileTypes.ts https://huggingface.co/felix-fx/fx-1/resolve/main/src/lib/fileTypes.ts
6.89 kB
| // أنواع ملفات ماينكرافت المدعومة حسب المنصة | |
| export interface FileTypeInfo { | |
| extension: string; | |
| name: string; | |
| description: string; | |
| platform: 'java' | 'bedrock' | 'both'; | |
| mimeTypes: string[]; | |
| } | |
| export const FILE_TYPES: FileTypeInfo[] = [ | |
| // Java Edition | |
| { | |
| extension: '.jar', | |
| name: 'Java Mod', | |
| description: 'ملف مود جافا (يتطلب Forge أو Fabric)', | |
| platform: 'java', | |
| mimeTypes: ['application/java-archive', 'application/x-java-archive'], | |
| }, | |
| { | |
| extension: '.zip', | |
| name: 'Resource Pack / Data Pack', | |
| description: 'حزمة موارد أو حزمة بيانات', | |
| platform: 'both', | |
| mimeTypes: ['application/zip', 'application/x-zip-compressed'], | |
| }, | |
| // Bedrock Edition | |
| { | |
| extension: '.mcaddon', | |
| name: 'Bedrock Add-On', | |
| description: 'إضافة بيدروك كاملة (سلوك + موارد)', | |
| platform: 'bedrock', | |
| mimeTypes: ['application/octet-stream'], | |
| }, | |
| { | |
| extension: '.mcpack', | |
| name: 'Bedrock Pack', | |
| description: 'حزمة موارد أو سلوك لبيدروك', | |
| platform: 'bedrock', | |
| mimeTypes: ['application/octet-stream'], | |
| }, | |
| { | |
| extension: '.mcworld', | |
| name: 'Bedrock World', | |
| description: 'خريطة/عالم ماينكرافت بيدروك', | |
| platform: 'bedrock', | |
| mimeTypes: ['application/octet-stream'], | |
| }, | |
| { | |
| extension: '.mctemplate', | |
| name: 'Bedrock Template', | |
| description: 'قالب عالم بيدروك', | |
| platform: 'bedrock', | |
| mimeTypes: ['application/octet-stream'], | |
| }, | |
| { | |
| extension: '.mcfunction', | |
| name: 'Function File', | |
| description: 'ملف وظائف ماينكرافت', | |
| platform: 'both', | |
| mimeTypes: ['text/plain'], | |
| }, | |
| ]; | |
| // الحصول على امتدادات الملفات حسب المنصة | |
| export const getAcceptedExtensions = (platform: 'java' | 'bedrock' | 'both'): string[] => { | |
| if (platform === 'both') { | |
| return FILE_TYPES.map(ft => ft.extension); | |
| } | |
| return FILE_TYPES | |
| .filter(ft => ft.platform === platform || ft.platform === 'both') | |
| .map(ft => ft.extension); | |
| }; | |
| // الحصول على نوع الملف من الامتداد | |
| export const getFileTypeFromExtension = (filename: string): FileTypeInfo | undefined => { | |
| const extension = filename.toLowerCase().substring(filename.lastIndexOf('.')); | |
| return FILE_TYPES.find(ft => ft.extension === extension); | |
| }; | |
| // التحقق من توافق الملف مع المنصة | |
| export const isFileCompatibleWithPlatform = (filename: string, platform: 'java' | 'bedrock' | 'both'): boolean => { | |
| const fileType = getFileTypeFromExtension(filename); | |
| if (!fileType) return false; | |
| if (platform === 'both') return true; | |
| if (fileType.platform === 'both') return true; | |
| return fileType.platform === platform; | |
| }; | |
| // الحصول على نوع الملف للتخزين في قاعدة البيانات | |
| export const getFileTypeForStorage = (filename: string): string => { | |
| const extension = filename.toLowerCase().substring(filename.lastIndexOf('.')); | |
| // إزالة النقطة من البداية | |
| return extension.replace('.', ''); | |
| }; | |
| // التحقق من صحة الملف | |
| export const validateFile = (file: File, platform: 'java' | 'bedrock' | 'both'): { | |
| valid: boolean; | |
| error?: string; | |
| fileType?: FileTypeInfo; | |
| } => { | |
| const maxSize = 100 * 1024 * 1024; // 100 MB | |
| if (file.size > maxSize) { | |
| return { | |
| valid: false, | |
| error: 'حجم الملف كبير جداً. الحد الأقصى 100 ميجابايت', | |
| }; | |
| } | |
| const fileType = getFileTypeFromExtension(file.name); | |
| if (!fileType) { | |
| return { | |
| valid: false, | |
| error: 'نوع الملف غير مدعوم. الأنواع المدعومة: ' + FILE_TYPES.map(ft => ft.extension).join(', '), | |
| }; | |
| } | |
| if (!isFileCompatibleWithPlatform(file.name, platform)) { | |
| const compatibleTypes = getAcceptedExtensions(platform); | |
| return { | |
| valid: false, | |
| error: `هذا النوع من الملفات غير متوافق مع منصة ${platform === 'java' ? 'جافا' : 'بيدروك'}. الأنواع المتوافقة: ${compatibleTypes.join(', ')}`, | |
| }; | |
| } | |
| return { | |
| valid: true, | |
| fileType, | |
| }; | |
| }; | |
| // عرض حجم الملف بشكل مقروء | |
| export const formatFileSize = (bytes: number): string => { | |
| if (bytes === 0) return '0 Bytes'; | |
| const k = 1024; | |
| const sizes = ['Bytes', 'KB', 'MB', 'GB']; | |
| const i = Math.floor(Math.log(bytes) / Math.log(k)); | |
| return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i]; | |
| }; | |
| // الحصول على أيقونة نوع الملف | |
| export const getFileTypeIcon = (extension: string): string => { | |
| const iconMap: Record<string, string> = { | |
| '.jar': '☕', | |
| '.zip': '📦', | |
| '.mcaddon': '🎮', | |
| '.mcpack': '📋', | |
| '.mcworld': '🌍', | |
| '.mctemplate': '📄', | |
| '.mcfunction': '⚙️', | |
| }; | |
| return iconMap[extension] || '📁'; | |
| }; | |
| // الحصول على لون نوع الملف | |
| export const getFileTypeColor = (extension: string): string => { | |
| const colorMap: Record<string, string> = { | |
| '.jar': 'text-orange-500', | |
| '.zip': 'text-blue-500', | |
| '.mcaddon': 'text-green-500', | |
| '.mcpack': 'text-purple-500', | |
| '.mcworld': 'text-cyan-500', | |
| '.mctemplate': 'text-yellow-500', | |
| '.mcfunction': 'text-gray-500', | |
| }; | |
| return colorMap[extension] || 'text-muted-foreground'; | |
| }; | |
| // الحصول على الامتداد الصحيح حسب المنصة | |
| export const getCorrectFileExtension = (platform: string, originalExtension: string): string => { | |
| // إذا كانت المنصة Bedrock، تأكد من أن الامتداد صحيح | |
| if (platform === 'bedrock') { | |
| // إذا كان الامتداد .jar (خطأ شائع)، حوله للامتداد الصحيح | |
| if (originalExtension === 'jar') { | |
| return 'mcaddon'; // الامتداد الافتراضي لـ Bedrock | |
| } | |
| // الامتدادات الصحيحة لـ Bedrock | |
| const bedrockExtensions = ['mcaddon', 'mcpack', 'mcworld', 'mctemplate', 'zip']; | |
| if (!bedrockExtensions.includes(originalExtension)) { | |
| return 'mcaddon'; | |
| } | |
| } | |
| // إذا كانت المنصة Java | |
| if (platform === 'java') { | |
| const javaExtensions = ['jar', 'zip']; | |
| if (!javaExtensions.includes(originalExtension)) { | |
| return 'jar'; | |
| } | |
| } | |
| return originalExtension; | |
| }; | |
| // إنشاء اسم الملف الصحيح للتحميل | |
| export const createCorrectFilename = (title: string, platform: string, originalExtension: string): string => { | |
| // تنظيف اسم الملف | |
| const cleanTitle = title | |
| .replace(/[^a-zA-Z0-9\u0600-\u06FF\s-_]/g, '') | |
| .replace(/\s+/g, '-') | |
| .trim() || 'addon'; | |
| const correctExtension = getCorrectFileExtension(platform, originalExtension); | |
| return `${cleanTitle}.${correctExtension}`; | |
| }; | |