AsyncValidateLoadArchivesController.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\Validator;
  5. use PhpOffice\PhpSpreadsheet\IOFactory;
  6. use ZipArchive;
  7. use Illuminate\Support\Str;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. use ElephantIO\Client;
  11. /**
  12. * Async Controller for validating Excel and ZIP files for equipment documentation loading
  13. * Validates Excel headers structure and compares file listings with ZIP contents using queues
  14. */
  15. class AsyncValidateLoadArchivesController extends Controller
  16. {
  17. private $responseController;
  18. private $encryptionController;
  19. private $documentManagementController;
  20. private $functionsController;
  21. private $notificationsController;
  22. private $socketClient;
  23. // Expected headers in row 7 of Excel file with their corresponding column letters
  24. private $expectedHeaders = [
  25. ['letter' => 'D', 'category' => 'CÓDIGO DE EQUIPO'],
  26. ['letter' => 'H', 'category' => 'FICHA DE SEGURIDAD DE PRODUCTOS QUÍMICOS'],
  27. ['letter' => 'J', 'category' => 'FICHA TÉCNICA'],
  28. ['letter' => 'L', 'category' => 'FOTOGRAFÍAS - DIAGRAMAS'],
  29. ['letter' => 'N', 'category' => 'DATOS DEL PROVEEDOR'],
  30. ['letter' => 'P', 'category' => 'MANUALES DE OPERACIÓN'],
  31. ['letter' => 'R', 'category' => 'MANUALES DE MANTENIMIENTO PREVENTIVO'],
  32. ['letter' => 'T', 'category' => 'MANUALES DE MANTENIMIENTO CORRECTIVO'],
  33. ['letter' => 'V', 'category' => 'DOCUMENTOS ADICIONALES']
  34. ];
  35. // Mapping of file extensions to their types for validation
  36. private $extensionTypes = [
  37. // Archivos de almacenamiento
  38. 'zip' => 'STORAGE', 'rar' => 'STORAGE', 'tar' => 'STORAGE', '7z' => 'STORAGE',
  39. // Formatos de audio
  40. 'mp3' => 'AUDIO', 'mpeg' => 'AUDIO', 'wav' => 'AUDIO', 'ogg' => 'AUDIO', 'opus' => 'AUDIO',
  41. // Archivos de imagen
  42. 'jpeg' => 'IMG', 'jpg' => 'IMG', 'png' => 'IMG', 'gif' => 'IMG', 'bmp' => 'IMG', 'tiff' => 'IMG', 'svg' => 'IMG',
  43. // Archivos de texto
  44. 'txt' => 'TEXT',
  45. // Archivos de video
  46. 'webm' => 'VIDEO', 'mpeg4' => 'VIDEO', 'mp4' => 'VIDEO', '3gpp' => 'VIDEO', 'mov' => 'VIDEO', 'avi' => 'VIDEO', 'wmv' => 'VIDEO', 'flv' => 'VIDEO',
  47. // Planos de Auto CAD
  48. 'dwg' => 'CAD', 'dxf' => 'CAD',
  49. // Modelos de 3D Studio
  50. '3ds' => '3D',
  51. // Dibujos de Illustrator
  52. 'ai' => 'ILLUSTRATOR',
  53. // Imágenes de Photoshop
  54. 'psd' => 'PHOTOSHOP',
  55. // Formato de documento portátil
  56. 'pdf' => 'PDF',
  57. // Hoja de cálculo en Excel
  58. 'xls' => 'EXCEL', 'xlsx' => 'EXCEL',
  59. // Presentaciones de PowerPoint
  60. 'ppt' => 'POWERPOINT', 'pptx' => 'POWERPOINT',
  61. // Documentos de texto de Word
  62. 'doc' => 'WORD', 'docx' => 'WORD',
  63. // Dibujos de Visio
  64. 'vsd' => 'VISIO', 'vsdx' => 'VISIO'
  65. ];
  66. public function __construct()
  67. {
  68. $this->responseController = new ResponseController();
  69. $this->encryptionController = new EncryptionController();
  70. $this->documentManagementController = new DocumentManagementController();
  71. $this->functionsController = new FunctionsController();
  72. $this->notificationsController = new NotificationsController();
  73. $url = 'http://localhost:3200';
  74. $this->socketClient = new Client(Client::engine(Client::CLIENT_4X, $url));
  75. $this->socketClient->initialize();
  76. $this->socketClient->of('/');
  77. }
  78. /**
  79. * EmitNotification use
  80. */
  81. public function emitNotification(Request $request):bool{
  82. $module = $request['module'];
  83. $title = $request['title'];
  84. $content = $request['content'];
  85. $actions = is_string($request['actions']) ? json_decode($request['actions'], true) : $request['actions'];
  86. $audience = [$request['audience']];
  87. $idUser = $request['idUser'] ?? $request['audience'];
  88. $line = $request['line'] ?? 1;
  89. $idOrder = $request['idOrder'] ?? null;
  90. $orderType = $request['orderType'] ?? null;
  91. $this->notificationsController->emitNotification($module, $title, $content, $actions, $audience, $idUser, $line, $this->socketClient ,$idOrder, $orderType);
  92. return true;
  93. }
  94. /***
  95. * Encryption endpoint
  96. *
  97. */
  98. public function encrypt(Request $request){
  99. $encryptString = $this->encryptionController->encrypt($request['value']);
  100. if(!$encryptString){
  101. return $this->responseController->makeResponse(true, "La cadena no fue encriptada correctamente", [], 400);
  102. }
  103. return $this->responseController->makeResponse(false, "Cadena encriptada correctamente", ['encrypted' => $encryptString], 200);
  104. }
  105. /**
  106. * Validation endpoint that dispatches file process to bat job
  107. */
  108. public function validateFilesWithBat(Request $request){
  109. $validator = Validator::make($request->all(), [
  110. 'id_user' => 'required|string',
  111. 'linea' => 'required|integer',
  112. 'excel_file' => 'required|file|mimes:xlsx,xls',
  113. 'zip_file' => 'required|file|mimes:zip'
  114. ]);
  115. if ($validator->fails()) {
  116. return $this->responseController->makeResponse(
  117. true,
  118. 'Se encontraron uno o más errores.',
  119. $this->responseController->makeErrors($validator->errors()->messages()),
  120. 400
  121. );
  122. }
  123. $jobId = Str::uuid();
  124. $userId = '0000000001';
  125. // $idUser = $this->encryptionController->decrypt($request->input('id_user'));
  126. // if(!$idUser){
  127. // return $this->responseController->makeResponse(true, "El id del usuario que realizó la petición no fue encriptado correctamente", [], 400);
  128. // }
  129. // Validate Excel file headers structure
  130. $excelValidation = $this->validateExcelHeaders($request->file('excel_file'));
  131. if ($excelValidation['error']) {
  132. return $this->responseController->makeResponse(true, $excelValidation['message'], [], 400);
  133. }
  134. // Validate ZIP file integrity
  135. $zipValidation = $this->validateZipFile($request->file('zip_file'));
  136. if ($zipValidation['error']) {
  137. return $this->responseController->makeResponse(true, $zipValidation['message'], [], 400);
  138. }
  139. // Extract and validate file listings from Excel
  140. $filesValidation = $this->extractAndValidateFiles($request->file('excel_file'));
  141. if ($filesValidation['error']) {
  142. return $this->responseController->makeResponse(true, $filesValidation['message'], [], 400);
  143. }
  144. // Compare Excel file listings with ZIP contents
  145. $comparison = $this->compareExcelWithZip($filesValidation['files'], $request->file('zip_file'));
  146. // Check for file size validation errors
  147. if (isset($comparison['error'])) {
  148. return $this->responseController->makeResponse(true, $comparison['error'], [], 400);
  149. }
  150. // Upload temp files
  151. $tempFiles = $this->uploadTempFiles($request);
  152. if ($tempFiles['error']) {
  153. return $this->responseController->makeResponse(
  154. true,
  155. $tempFiles['message'],
  156. [
  157. 'valid' => false,
  158. 'missing_in_zip' => $comparison['missing_in_zip'] ?? [],
  159. 'extra_in_zip' => $comparison['extra_in_zip'] ?? []
  160. ],
  161. 400
  162. );
  163. }
  164. if (!$comparison['valid']) {
  165. return $this->responseController->makeResponse(
  166. true,
  167. 'Los archivos no coinciden entre Excel y ZIP',
  168. [
  169. 'valid' => false,
  170. 'missing_in_zip' => $comparison['missing_in_zip'],
  171. 'extra_in_zip' => $comparison['extra_in_zip']
  172. ],
  173. 400
  174. );
  175. }
  176. $idFileZip = $this->encryptionController->decrypt($tempFiles['files']['zip']);
  177. if(!$idFileZip){
  178. return $this->responseController->makeResponse(true, "El id del archivo que desea eliminar no fue encriptado correctamente", [], 400);
  179. }
  180. $idFileExcel = $this->encryptionController->decrypt($tempFiles['files']['excel']);
  181. if(!$idFileExcel){
  182. return $this->responseController->makeResponse(true, "El id del archivo que desea eliminar no fue encriptado correctamente", [], 400);
  183. }
  184. // Guardar en bd::S002V01TVAJO
  185. $validationJobId = DB::table('S002V01TVAJO')->insertGetId([
  186. 'VAJO_COJO' => $jobId,
  187. 'VAJO_IDUS' => $userId,
  188. 'VAJO_NULI' => $request->input('linea'),
  189. 'VAJO_ESTA' => 'queued',
  190. 'VAJO_PRPE' => 0,
  191. 'VAJO_EXTE' => $idFileExcel,
  192. 'VAJO_ZITE' => $idFileZip,
  193. 'VAJO_FERE' => now(),
  194. 'VAJO_FEMO' => now()
  195. ]);
  196. return $this->responseController->makeResponse(
  197. false,
  198. 'Validación iniciada',
  199. [
  200. 'job_id' => $validationJobId,
  201. 'status' => 'queued',
  202. 'valid' => $comparison['valid'],
  203. 'missing_in_zip' => $comparison['missing_in_zip'],
  204. 'extra_in_zip' => $comparison['extra_in_zip']
  205. ]
  206. );
  207. }
  208. /**
  209. * Process endpoint that moves temp files to final storage
  210. */
  211. public function processLoadArchives(Request $request)
  212. {
  213. $validator = Validator::make($request->all(), [
  214. 'id_user' => 'required|string',
  215. 'linea' => 'required|integer',
  216. 'temp_files' => 'required|array',
  217. 'temp_files.excel' => 'required|string',
  218. 'temp_files.zip' => 'required|string',
  219. 'individual_temp_files' => 'required|array'
  220. ]);
  221. if ($validator->fails()) {
  222. return $this->responseController->makeResponse(
  223. true,
  224. 'Se encontraron uno o más errores.',
  225. $this->responseController->makeErrors($validator->errors()->messages()),
  226. 400
  227. );
  228. }
  229. $form = $request->all();
  230. $idUser = '0000000001';
  231. // $idUser = $this->encryptionController->decrypt($form['id_user']);
  232. // if (!$idUser) {
  233. // return $this->responseController->makeResponse(true, 'ID de usuario inválido.', [], 400);
  234. // }
  235. $finalFiles = [];
  236. try {
  237. // Verificar estado de archivos antes de procesarlos
  238. $tempFiles = [$form['temp_files']['excel'], $form['temp_files']['zip']];
  239. foreach ($form['individual_temp_files'] as $tempFile) {
  240. $tempFiles[] = $tempFile['temp_id'];
  241. }
  242. foreach ($tempFiles as $tempId) {
  243. $tempIdDec = $this->encryptionController->decrypt($tempId);
  244. if ($tempIdDec) {
  245. $tempFile = DB::table('S002V01TARTE')->where('ARTE_IDAR', $tempIdDec)->first();
  246. if ($tempFile && $tempFile->ARTE_ESTA === 'Eliminado') {
  247. return $this->responseController->makeResponse(
  248. true,
  249. 'La acción no puede completarse porque uno o más archivos han sido eliminados lógicamente.',
  250. [],
  251. 400
  252. );
  253. }
  254. }
  255. }
  256. // Move Excel to final
  257. $excelFinal = $this->moveToFinal($form['temp_files']['excel'], $form['linea'], $idUser);
  258. if (!$excelFinal) {
  259. return $this->responseController->makeResponse(true, 'Error procesando Excel', [], 400);
  260. }
  261. $finalFiles['excel'] = $excelFinal;
  262. // Move ZIP to final
  263. $zipFinal = $this->moveToFinal($form['temp_files']['zip'], $form['linea'], $idUser);
  264. if (!$zipFinal) {
  265. return $this->responseController->makeResponse(true, 'Error procesando ZIP', [], 400);
  266. }
  267. $finalFiles['zip'] = $zipFinal;
  268. // Move individual temp files to final storage
  269. $individualFiles = [];
  270. foreach ($form['individual_temp_files'] as $tempFile) {
  271. $finalFileId = $this->moveToFinal($tempFile['temp_id'], $form['linea'], $idUser);
  272. if ($finalFileId) {
  273. $individualFiles[] = [
  274. 'original_name' => $tempFile['original_name'],
  275. 'final_id' => $finalFileId
  276. ];
  277. }
  278. }
  279. $finalFiles['individual_files'] = $individualFiles;
  280. return $this->responseController->makeResponse(false, 'Archivos procesados exitosamente.', $finalFiles);
  281. } catch (\Exception $e) {
  282. return $this->responseController->makeResponse(true, 'Error interno: ' . $e->getMessage(), [], 500);
  283. }
  284. }
  285. /**
  286. * Moves a temporary file to final storage using DocumentManagementController
  287. */
  288. private function moveToFinal($tempId, $line, $idUser)
  289. {
  290. try {
  291. $tempIdDec = $this->encryptionController->decrypt($tempId);
  292. if (!$tempIdDec) {
  293. return false;
  294. }
  295. $tempFile = DB::table('S002V01TARTE')->where('ARTE_IDAR', $tempIdDec)->first();
  296. if (!$tempFile) {
  297. return false;
  298. }
  299. // Validar estado del archivo temporal
  300. if ($tempFile->ARTE_ESTA === 'Eliminado') {
  301. return false;
  302. }
  303. $result = $this->documentManagementController->moveFinalFile($line, 'ADSI', 'LA', $tempFile, $idUser);
  304. return $result[0] ? $result[1] : false;
  305. } catch (\Exception $e) {
  306. return false;
  307. }
  308. }
  309. /**
  310. * Validates that Excel file has the correct headers in row 7
  311. * Each column must match the expected category name exactly
  312. */
  313. private function validateExcelHeaders($file)
  314. {
  315. try {
  316. $spreadsheet = IOFactory::load($file->getPathname());
  317. $worksheet = $spreadsheet->getActiveSheet();
  318. // Check each expected header in row 7
  319. foreach ($this->expectedHeaders as $header) {
  320. $cellValue = $worksheet->getCell($header['letter'] . '7')->getValue();
  321. if (trim($cellValue) !== $header['category']) {
  322. return [
  323. 'error' => true,
  324. 'message' => "El encabezado en la columna {$header['letter']} no coincide. Se esperaba: '{$header['category']}', se encontró: '{$cellValue}'"
  325. ];
  326. }
  327. }
  328. return ['error' => false];
  329. } catch (\Exception $e) {
  330. return ['error' => true, 'message' => 'Error al procesar el archivo Excel: ' . $e->getMessage()];
  331. }
  332. }
  333. /**
  334. * Validates ZIP file integrity and ensures it's not empty
  335. */
  336. private function validateZipFile($file)
  337. {
  338. $zip = new ZipArchive();
  339. $result = $zip->open($file->getPathname());
  340. if ($result !== TRUE) {
  341. return ['error' => true, 'message' => 'No se pudo abrir el archivo ZIP.'];
  342. }
  343. if ($zip->numFiles === 0) {
  344. $zip->close();
  345. return ['error' => true, 'message' => 'El archivo ZIP está vacío.'];
  346. }
  347. $zip->close();
  348. return ['error' => false];
  349. }
  350. /**
  351. * Extracts file listings from Excel starting from row 8
  352. * Validates file extensions and creates structured file list
  353. * Only processes rows with equipment code (column D)
  354. */
  355. private function extractAndValidateFiles($file)
  356. {
  357. try {
  358. $spreadsheet = IOFactory::load($file->getPathname());
  359. $worksheet = $spreadsheet->getActiveSheet();
  360. $highestRow = $worksheet->getHighestRow();
  361. $files = [];
  362. // Process each row starting from row 8 (data rows)
  363. for ($row = 8; $row <= $highestRow; $row++) {
  364. $equipmentCode = trim($worksheet->getCell('D' . $row)->getValue());
  365. if (empty($equipmentCode)) continue; // Skip rows without equipment code
  366. $hasFiles = false;
  367. $rowFiles = [];
  368. // Check each file category column (excluding equipment code column D)
  369. foreach ($this->expectedHeaders as $header) {
  370. if ($header['letter'] === 'D') continue;
  371. $cellValue = trim($worksheet->getCell($header['letter'] . $row)->getValue());
  372. if (empty($cellValue)) continue;
  373. // Handle multiple files separated by commas
  374. $fileNames = explode(',', $cellValue);
  375. foreach ($fileNames as $fileName) {
  376. $fileName = trim($fileName);
  377. if (empty($fileName)) continue;
  378. // Validate file extension
  379. $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  380. if (!isset($this->extensionTypes[$extension])) {
  381. return [
  382. 'error' => true,
  383. 'message' => "Extensión inválida '{$extension}' en archivo '{$fileName}' para equipo '{$equipmentCode}'"
  384. ];
  385. }
  386. $rowFiles[] = [
  387. 'equipment_code' => $equipmentCode,
  388. 'file_name' => $fileName,
  389. 'type' => $this->getFileType($extension)
  390. ];
  391. $hasFiles = true;
  392. }
  393. }
  394. if ($hasFiles) {
  395. $files = array_merge($files, $rowFiles);
  396. }
  397. }
  398. return ['error' => false, 'files' => $files];
  399. } catch (\Exception $e) {
  400. return ['error' => true, 'message' => 'Error al extraer archivos del Excel: ' . $e->getMessage()];
  401. }
  402. }
  403. /**
  404. * Compares file listings from Excel with actual files in ZIP
  405. * Returns validation status and lists of missing/extra files
  406. */
  407. private function compareExcelWithZip($excelFiles, $zipFile)
  408. {
  409. $zip = new ZipArchive();
  410. $zip->open($zipFile->getPathname());
  411. // Extract all file names and sizes from ZIP
  412. $zipFiles = [];
  413. $zipFileSizes = [];
  414. for ($i = 0; $i < $zip->numFiles; $i++) {
  415. $fullPath = $zip->getNameIndex($i);
  416. // Skip directories (entries ending with /)
  417. if (substr($fullPath, -1) === '/') {
  418. continue;
  419. }
  420. // Extract filename and size
  421. $fileName = basename($fullPath);
  422. if (!empty($fileName)) {
  423. $zipFiles[] = $fileName;
  424. $zipFileSizes[$fileName] = $zip->statIndex($i)['size'];
  425. }
  426. }
  427. $zip->close();
  428. // Validate file sizes using FunctionsController
  429. foreach ($zipFileSizes as $fileName => $size) {
  430. $extension = strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
  431. if (!$this->functionsController->checkFileSize($extension, $size)) {
  432. $sizeMB = round($size / (1024 * 1024), 2);
  433. return [
  434. 'valid' => false,
  435. 'error' => "El archivo '{$fileName}' excede el límite de tamaño. Tamaño: {$sizeMB}MB"
  436. ];
  437. }
  438. }
  439. // Get file names from Excel listings
  440. $excelFileNames = array_column($excelFiles, 'file_name');
  441. // Find discrepancies between Excel and ZIP
  442. $missingInZip = array_diff($excelFileNames, $zipFiles);
  443. $extraInZip = array_diff($zipFiles, $excelFileNames);
  444. $isValid = empty($missingInZip) && empty($extraInZip);
  445. return [
  446. 'valid' => $isValid,
  447. 'missing_in_zip' => array_values($missingInZip),
  448. 'extra_in_zip' => array_values($extraInZip)
  449. ];
  450. }
  451. /**
  452. * Uploads Excel and ZIP files as temporary files using DocumentManagementController
  453. */
  454. private function uploadTempFiles(Request $request)
  455. {
  456. try {
  457. $tempFiles = [];
  458. // Upload Excel file
  459. $excelRequest = new Request();
  460. $excelRequest->files->set('file', $request->file('excel_file'));
  461. $excelRequest->merge([
  462. 'id_user' => $request->input('id_user'),
  463. 'linea' => $request->input('linea')
  464. ]);
  465. $excelResponse = $this->documentManagementController->uploadTempFile($excelRequest);
  466. $excelData = json_decode($excelResponse->getContent());
  467. if ($excelData->error) {
  468. $errorMsg = isset($excelData->message) ? $excelData->message : 'Error desconocido subiendo Excel';
  469. return ['error' => true, 'message' => 'Error subiendo Excel: ' . $errorMsg];
  470. }
  471. $tempFiles['excel'] = $excelData->response->idArchivo;
  472. // Upload ZIP file
  473. $zipRequest = new Request();
  474. $zipRequest->files->set('file', $request->file('zip_file'));
  475. $zipRequest->merge([
  476. 'id_user' => $request->input('id_user'),
  477. 'linea' => $request->input('linea')
  478. ]);
  479. $zipResponse = $this->documentManagementController->uploadTempFile($zipRequest);
  480. $zipData = json_decode($zipResponse->getContent());
  481. if ($zipData->error) {
  482. $errorMsg = isset($zipData->message) ? $zipData->message : 'Error desconocido subiendo ZIP';
  483. return ['error' => true, 'message' => 'Error subiendo ZIP: ' . $errorMsg];
  484. }
  485. $tempFiles['zip'] = $zipData->response->idArchivo;
  486. return ['error' => false, 'files' => $tempFiles];
  487. } catch (\Exception $e) {
  488. return ['error' => true, 'message' => 'Error en uploadTempFiles: ' . $e->getMessage()];
  489. }
  490. }
  491. /**
  492. * Gets file type based on extension
  493. */
  494. private function getFileType($extension){
  495. $typeMap = [
  496. 'zip' => 'STORAGE', 'rar' => 'STORAGE', 'tar' => 'STORAGE', '7z' => 'STORAGE',
  497. 'mp3' => 'AUDIO', 'mpeg' => 'AUDIO', 'wav' => 'AUDIO', 'ogg' => 'AUDIO', 'opus' => 'AUDIO',
  498. 'jpeg' => 'IMG', 'jpg' => 'IMG', 'png' => 'IMG', 'gif' => 'IMG', 'bmp' => 'IMG', 'tiff' => 'IMG', 'svg' => 'IMG',
  499. 'txt' => 'TEXT',
  500. 'webm' => 'VIDEO', 'mpeg4' => 'VIDEO', 'mp4' => 'VIDEO', '3gpp' => 'VIDEO', 'mov' => 'VIDEO', 'avi' => 'VIDEO', 'wmv' => 'VIDEO', 'flv' => 'VIDEO',
  501. 'dwg' => 'CAD', 'dxf' => 'CAD', '3ds' => '3D', 'ai' => 'ILLUSTRATOR', 'psd' => 'PHOTOSHOP',
  502. 'pdf' => 'PDF', 'xls' => 'EXCEL', 'xlsx' => 'EXCEL', 'ppt' => 'POWERPOINT', 'pptx' => 'POWERPOINT',
  503. 'doc' => 'WORD', 'docx' => 'WORD', 'vsd' => 'VISIO', 'vsdx' => 'VISIO'
  504. ];
  505. return $typeMap[$extension] ?? 'UNKNOWN';
  506. }
  507. }