File indexing completed on 2024-12-22 05:33:08
0001 <?php 0002 /** @noinspection PhpUndefinedFieldInspection */ 0003 0004 /** 0005 * file server - part of Opendesktop.org platform project <https://www.opendesktop.org>. 0006 * 0007 * Copyright (c) 2016 pling GmbH. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <https://www.gnu.org/licenses/>. 0021 */ 0022 class Waveform extends BaseController 0023 { 0024 0025 /** 0026 * @throws Flooer_Exception 0027 */ 0028 public function getFile() { 0029 $id = null; 0030 0031 if (!empty($this->request->id)) { 0032 $id = $this->request->id; 0033 } 0034 0035 $file = $this->models->files->getFile($id); 0036 0037 // check file pre-conditions 0038 if (!$file) { 0039 $this->response->setStatus(404); 0040 throw new Flooer_Exception('Not found', LOG_NOTICE); 0041 } 0042 if (!$file->active) { 0043 $this->log->log("File is inactive (file: $file->id)", LOG_NOTICE); 0044 $this->response->setStatus(404); 0045 throw new Flooer_Exception('Not found', LOG_NOTICE); 0046 } 0047 if (substr($file->type, 0, 5) !== "audio") { 0048 $this->response->setStatus(404); 0049 throw new Flooer_Exception('Not an audio file (' . $file->id . ')', LOG_NOTICE); 0050 } 0051 0052 $collectionId = $file->collection_id; 0053 $collection = $this->models->collections->$collectionId; 0054 0055 // check collection pre-conditions 0056 if (!$collection) { 0057 $this->log->log("Collection not found (file: $file->id)", LOG_NOTICE); 0058 $this->response->setStatus(404); 0059 throw new Flooer_Exception('Not found', LOG_NOTICE); 0060 } 0061 if (!$collection->active) { 0062 $this->log->log("Collection is inactive (file: $file->id)", LOG_NOTICE); 0063 $this->response->setStatus(404); 0064 throw new Flooer_Exception('Not found', LOG_NOTICE); 0065 } 0066 0067 $collectionDir = $this->appConfig->general['filesDir'] . '/' . $collection->name; 0068 $filePath = $collectionDir . '/' . $file->name; 0069 $fileName = $file->name . '.json'; 0070 $fileType = 'application/json'; 0071 $fileJsonWaveform = $filePath . '.json'; 0072 0073 if (file_exists($fileJsonWaveform)) { 0074 $this->_sendFile($fileJsonWaveform, $fileName, $fileType, filesize($fileJsonWaveform), true, false); 0075 } 0076 0077 $this->_generateWaveForm($filePath, $fileJsonWaveform); 0078 if (file_exists($fileJsonWaveform)) { 0079 $this->_sendFile($fileJsonWaveform, $fileName, $fileType, filesize($fileJsonWaveform), true, false); 0080 } 0081 0082 $this->log->log("Waveform file not generated (file: $file->id)", LOG_NOTICE); 0083 $this->response->setStatus(404); 0084 throw new Flooer_Exception('File Not found', LOG_NOTICE); 0085 } 0086 0087 }