Proyectos de Subversion LeadersLinked - Services

Rev

Rev 283 | Rev 341 | Ir a la última revisión | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 283 Rev 333
Línea 77... Línea 77...
77
        $this->logger       = $logger;
77
        $this->logger       = $logger;
78
        $this->config       = $config;
78
        $this->config       = $config;
79
        $this->translator   = $translator;
79
        $this->translator   = $translator;
80
    }
80
    }
Línea -... Línea 81...
-
 
81
 
-
 
82
    
-
 
83
    public function storageAction()
-
 
84
    {
-
 
85
        $currentNetworkPlugin = $this->plugin('currentNetworkPlugin');
-
 
86
        $currentNetwork = $currentNetworkPlugin->getNetwork();
-
 
87
        
-
 
88
        $request = $this->getRequest();
-
 
89
        if ($request->isGet()) {
-
 
90
            
-
 
91
            $code = $this->params()->fromRoute('code');
-
 
92
            if(empty($code)) {
-
 
93
                $data = [
-
 
94
                    'success' => false,
-
 
95
                    'data' => 'ERROR_STORAGE_CODE_INVALID'
-
 
96
                ];
-
 
97
                
-
 
98
                return new JsonModel($data);
-
 
99
            }
-
 
100
            
-
 
101
            $storageFileMapper = \LeadersLinked\Mapper\StorageFileMapper::getInstance($this->adapter);
-
 
102
            $storageFile = $storageFileMapper->fetchOneByCode($code);
-
 
103
            
-
 
104
           
-
 
105
            
-
 
106
            if($storageFile) {
-
 
107
               
-
 
108
                
-
 
109
                if(file_exists($storageFile->path)) {
-
 
110
                    
-
 
111
                    // Try to open file
-
 
112
                    if (!is_readable($storageFile->path)) {
-
 
113
                        return $this->getResponse()->setStatusCode(500);
-
 
114
                    }
-
 
115
                    
-
 
116
                    // Get file size in bytes.
-
 
117
                    $fileSize = filesize($storageFile->path);
-
 
118
                    
-
 
119
                    // Get MIME type of the file.
-
 
120
                    $mimeType = mime_content_type($storageFile->path);
-
 
121
                    if($mimeType===false) {
-
 
122
                        $mimeType = 'application/octet-stream';
-
 
123
                    }
-
 
124
                    
-
 
125
                    $fileContent = file_get_contents($storageFile->path);
-
 
126
                    
-
 
127
                    $response = $this->getResponse();
-
 
128
                    $headers = $response->getHeaders();
-
 
129
                    $headers->addHeaderLine('Content-type: ' . $mimeType);
-
 
130
                    $headers->addHeaderLine('Content-length: ' . $fileSize);
-
 
131
                    
-
 
132
                    if($fileContent!==false) {
-
 
133
                        $response->setContent($fileContent);
-
 
134
                        return $response;
-
 
135
                    } else {
-
 
136
                        $this->getResponse()->setStatusCode(500);
-
 
137
                        return;
-
 
138
                    }
-
 
139
                } else {
-
 
140
                    return $this->getResponse()->setStatusCode(404);
-
 
141
                }
-
 
142
      
-
 
143
            } else {
-
 
144
                return $this->getResponse()->setStatusCode(404);
-
 
145
            }
-
 
146
            
-
 
147
            
-
 
148
            
-
 
149
            
-
 
150
            
-
 
151
            
-
 
152
        
-
 
153
        } else {
-
 
154
            $data = [
-
 
155
                'success' => false,
-
 
156
                'data' => 'ERROR_METHOD_NOT_ALLOWED'
-
 
157
            ];
-
 
158
            
-
 
159
            return new JsonModel($data);
-
 
160
        }
Línea 81... Línea 161...
81
 
161
    }
82
 
162
 
83
 
163
 
Línea 876... Línea 956...
876
            ];
956
            ];
Línea 877... Línea 957...
877
            
957
            
878
            return new JsonModel($response);
958
            return new JsonModel($response);
879
        }
959
        }
-
 
960
    }
-
 
961
    
880
    }
962