Proyectos de Subversion LeadersLinked - Services

Rev

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

Rev 814 Rev 823
Línea 120... Línea 120...
120
                ];
120
                ];
Línea 121... Línea 121...
121
                
121
                
122
                return new JsonModel($data);
122
                return new JsonModel($data);
Línea -... Línea 123...
-
 
123
            }
123
            }
124
            
124
            
125
            // Usar la clase Storage para manejar rutas correctamente
Línea 125... Línea -...
125
            $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
-
 
126
            $storageFile = $storageFileMapper->fetchOneByCode($code);
-
 
127
            
-
 
128
            $storageDir = $this->config['leaderslinked.storage.path'];
-
 
129
            $storageFileFullPath = $storageDir . DIRECTORY_SEPARATOR . $storageFile->path;
126
            $storage = \LeadersLinked\Library\Storage::getInstance($this->config, $this->adapter);
130
            
127
            $storageFileFullPath = $storage->getFilePathByCode($code);
131
            if($storageFileFullPath) {
128
            
132
                if(file_exists($storageFileFullPath)) {
129
            if($storageFileFullPath && file_exists($storageFileFullPath)) {
133
                    
130
                
134
                    // Check if the path is a directory instead of a file
131
                // Check if the path is a directory instead of a file
135
                    if(is_dir($storageFileFullPath)) {
132
                if(is_dir($storageFileFullPath)) {
136
                        $this->logger->err('StorageFile path is a directory instead of a file: ' . $storageFile->path . ' (code: ' . $code . ')');
133
                    $this->logger->err('StorageFile path is a directory instead of a file: ' . $storageFileFullPath . ' (code: ' . $code . ')');
137
                        return $this->getResponse()->setStatusCode(500);
134
                    return $this->getResponse()->setStatusCode(500);
138
                    }
135
                }
139
                    
136
                
140
                    // Try to open file
137
                // Try to open file
141
                    if (!is_readable($storageFileFullPath)) {
138
                if (!is_readable($storageFileFullPath)) {
142
                        return $this->getResponse()->setStatusCode(500);
139
                    return $this->getResponse()->setStatusCode(500);
143
                    }
140
                }
144
                    
141
                
145
                    // Get file size in bytes.
142
                // Get file size in bytes.
146
                    $fileSize = filesize($storageFileFullPath);
143
                $fileSize = filesize($storageFileFullPath);
147
                    
144
                
148
                    // Get MIME type of the file.
145
                // Get MIME type of the file.
149
                    $mimeType = mime_content_type($storageFileFullPath);
146
                $mimeType = mime_content_type($storageFileFullPath);
150
                    if($mimeType===false) {
147
                if($mimeType===false) {
-
 
148
                    $mimeType = 'application/octet-stream';
151
                        $mimeType = 'application/octet-stream';
149
                }
Línea 152... Línea 150...
152
                    }
150
                
153
                    
151
                // Usar la ruta completa para leer el contenido del archivo
154
                    $fileContent = file_get_contents($storageFile->path);
152
                $fileContent = file_get_contents($storageFileFullPath);
155
                    
153
                    
Línea 163... Línea 161...
163
                        return $response;
161
                        return $response;
164
                    } else {
162
                    } else {
165
                        $this->getResponse()->setStatusCode(500);
163
                        $this->getResponse()->setStatusCode(500);
166
                        return;
164
                        return;
167
                    }
165
                    }
168
                } else {
-
 
169
                    $this->logger->err('storageFileFullPath not found = ' . $storageFileFullPath);
-
 
170
                    return $this->getResponse()->setStatusCode(404);
-
 
171
                }
-
 
172
            } else {
166
            } else {
-
 
167
                $this->logger->err('storageFileFullPath not found or could not be resolved for code = ' . $code);
173
                return $this->getResponse()->setStatusCode(404);
168
                return $this->getResponse()->setStatusCode(404);
174
            }
169
            }
Línea 175... Línea 170...
175
        
170
        
176
        } else {
171
        } else {