Proyectos de Subversion LeadersLinked - Backend

Rev

Rev 17018 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 17018 Rev 17350
Línea 290... Línea 290...
290
                ];
290
                ];
Línea 291... Línea 291...
291
                
291
                
292
                return new JsonModel($data);
292
                return new JsonModel($data);
Línea -... Línea 293...
-
 
293
            }
293
            }
294
            
294
            
295
            // Usar la clase Storage para manejar rutas correctamente
Línea 295... Línea -...
295
            $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
-
 
296
            $storageFile = $storageFileMapper->fetchOneByCode($code);
-
 
297
            
296
            $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
Línea -... Línea 297...
-
 
297
            $storageFileFullPath = $storage->getFilePathByCode($code);
-
 
298
            
-
 
299
            if($storageFileFullPath && file_exists($storageFileFullPath)) {
-
 
300
                
-
 
301
                // Check if the path is a directory instead of a file
Línea 298... Línea -...
298
            
-
 
299
            
-
 
300
            if($storageFile) {
302
                if(is_dir($storageFileFullPath)) {
301
                
303
                    $this->logger->err('StorageFile path is a directory instead of a file: ' . $storageFileFullPath . ' (code: ' . $code . ')');
302
                
304
                    return $this->getResponse()->setStatusCode(500);
303
                if(file_exists($storageFile->path)) {
305
                }
304
                    
306
                
305
                    // Try to open file
307
                // Try to open file
306
                    if (!is_readable($storageFile->path)) {
308
                if (!is_readable($storageFileFullPath)) {
307
                        return $this->getResponse()->setStatusCode(500);
309
                    return $this->getResponse()->setStatusCode(500);
308
                    }
310
                }
309
                    
311
                
310
                    // Get file size in bytes.
312
                // Get file size in bytes.
311
                    $fileSize = filesize($storageFile->path);
313
                $fileSize = filesize($storageFileFullPath);
312
                    
314
                
313
                    // Get MIME type of the file.
315
                // Get MIME type of the file.
-
 
316
                $mimeType = mime_content_type($storageFileFullPath);
314
                    $mimeType = mime_content_type($storageFile->path);
317
                if($mimeType===false) {
Línea 315... Línea 318...
315
                    if($mimeType===false) {
318
                    $mimeType = 'application/octet-stream';
316
                        $mimeType = 'application/octet-stream';
319
                }
317
                    }
320
                
318
                    
321
                // Usar la ruta completa para leer el contenido del archivo
Línea 328... Línea 331...
328
                        return $response;
331
                        return $response;
329
                    } else {
332
                    } else {
330
                        $this->getResponse()->setStatusCode(500);
333
                        $this->getResponse()->setStatusCode(500);
331
                        return;
334
                        return;
332
                    }
335
                    }
333
                } else {
-
 
334
                    return $this->getResponse()->setStatusCode(404);
-
 
335
                }
-
 
336
                
-
 
337
            } else {
336
            } else {
-
 
337
                $this->logger->err('storageFileFullPath not found or could not be resolved for code = ' . $code);
338
                return $this->getResponse()->setStatusCode(404);
338
                return $this->getResponse()->setStatusCode(404);
339
            }
339
            }
340
            
-
 
341
            
340
        
342
            
-
 
343
            
-
 
344
            
-
 
345
            
-
 
346
            
-
 
347
        } else {
341
        } else {
348
            $data = [
342
            $data = [
349
                'success' => false,
343
                'success' => false,
350
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
344
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
351
            ];
345
            ];