diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c5979e2..de7b3ba 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -5,7 +5,7 @@ set (CMAKE_INSTALL_PREFIX "/usr/") set (USE_PCH 1) -set (ENABLE_BACKTRACE 1) +set (ENABLE_BACKTRACE 0) set (USE_SANITIZE OFF) # seems to be broken on Ubuntu 24.10 diff --git a/src/PiPedalModel.cpp b/src/PiPedalModel.cpp index b05acc5..4b8375c 100644 --- a/src/PiPedalModel.cpp +++ b/src/PiPedalModel.cpp @@ -2882,5 +2882,5 @@ void PiPedalModel::OnAlsaDriverTerminatedAbnormally() { bool PiPedalModel::IsInUploadsDirectory(const std::string &path) { - return !storage.IsInUploadsDirectory(path); + return storage.IsInUploadsDirectory(path); } \ No newline at end of file diff --git a/src/RingBuffer.hpp b/src/RingBuffer.hpp index f807451..fa56810 100644 --- a/src/RingBuffer.hpp +++ b/src/RingBuffer.hpp @@ -221,63 +221,7 @@ namespace pipedal return readSpace_(); } - bool write_packet(size_t bytes, void *data) - { - if (MULTI_WRITER) - { - std::lock_guard writeLock{writeMutex}; - if (writeSpace() < bytes + sizeof(bytes)) - { - return false; - } - size_t index = this->writePosition; - for (size_t i = 0; i < sizeof(bytes); ++i) - { - buffer[(index++() & ringBufferMask] = ((uint8_t*)(&bytes))[i]; - - } - for (size_t i = 0; i < bytes; ++i) - { - buffer[(index++) & ringBufferMask] = data[i]; - } - { - std::lock_guard lock(mutex); - this->writePosition = (index) & ringBufferMask; - } - if (SEMAPHORE_READER) - { - cvRead.notify_all(); - } - return true; - } - else - { - if (writeSpace() < bytes + sizeof(bytes)) - { - return false; - } - size_t index = this->writePosition; - for (size_t i = 0; i < sizeof(bytes); ++i) - { - buffer[(index++() & ringBufferMask] = ((uint8_t*)(&bytes))[i]; - - } - for (size_t i = 0; i < bytes; ++i) - { - buffer[(index++) & ringBufferMask] = data[i]; - } - { - std::lock_guard lock(mutex); - this->writePosition = (index) & ringBufferMask; - } - if (SEMAPHORE_READER) - { - cvRead.notify_all(); - } - return true; - } - } - + bool write(size_t bytes, uint8_t *data) { if (MULTI_WRITER) diff --git a/src/WebServerConfig.cpp b/src/WebServerConfig.cpp index 1405f2b..a46ca0e 100644 --- a/src/WebServerConfig.cpp +++ b/src/WebServerConfig.cpp @@ -246,6 +246,26 @@ public: try { std::string segment = request_uri.segment(1); + if (segment == "downloadMediaFile") { + fs::path path = request_uri.query("path"); + + if (!fs::exists(path) || !this->model->IsInUploadsDirectory(path) || HasDotDot(path)) + { + throw PiPedalException("File not found."); + } + auto mimeType = GetMimeType(path); + if (mimeType.empty()) { + throw PiPedalException("Can't download files of this type."); + } + res.set(HttpField::content_type, mimeType); + res.set(HttpField::cache_control, "no-cache"); + std::string disposition = GetContentDispositionHeader(path.stem().string(), path.extension().string()); + res.set(HttpField::content_disposition, disposition); + size_t contentLength = std::filesystem::file_size(path); + res.setContentLength(contentLength); + return; + } + if (segment == "downloadPluginPresets") { std::string name; @@ -263,6 +283,7 @@ public: res.set(HttpField::content_disposition, GetContentDispositionHeader(name, PLUGIN_PRESETS_EXTENSION)); return; } + if (segment == "downloadPreset") { std::string name; @@ -322,7 +343,29 @@ public: { std::string segment = request_uri.segment(1); - if (segment == "downloadPluginPresets") + if (segment == "downloadMediaFile") { + fs::path path = request_uri.query("path"); + + bool t = this->model->IsInUploadsDirectory(path); + std::cout << (t? "true": "false") << std::endl; + (void)t; + if (!fs::exists(path) || !this->model->IsInUploadsDirectory(path) || HasDotDot(path)) + { + throw PiPedalException("File not found."); + } + auto mimeType = GetMimeType(path); + if (mimeType.empty()) { + throw PiPedalException("Can't download files of this type."); + } + res.set(HttpField::content_type, mimeType); + res.set(HttpField::cache_control, "no-cache"); + std::string disposition = GetContentDispositionHeader(path.stem().string(), path.extension().string()); + res.set(HttpField::content_disposition, disposition); + size_t contentLength = std::filesystem::file_size(path); + res.setContentLength(contentLength); + res.setBodyFile(path,false); + return; + } else if (segment == "downloadPluginPresets") { std::string name; std::string content; @@ -451,23 +494,6 @@ public: { std::string segment = request_uri.segment(1); - if (segment == "downloadMediaFile") { - fs::path path = request_uri.query("path"); - - if (!fs::exists(path) || !this->model->IsInUploadsDirectory(path) || HasDotDot(path)) - { - throw PiPedalException("File not found."); - } - auto mimeType = GetMimeType(path); - if (mimeType.empty()) { - throw PiPedalException("Can't download files of this type."); - } - res.set(HttpField::content_type, mimeType); - res.set(HttpField::cache_control, "no-cache"); - std::string disposition = GetContentDispositionHeader(path.stem().string(), path.extension().string()); - res.set(HttpField::content_disposition, disposition); - res.setBodyFile(path,false); - } if (segment == "uploadPluginPresets") { PluginPresets presets; diff --git a/vite/src/pipedal/FilePropertyDialog.tsx b/vite/src/pipedal/FilePropertyDialog.tsx index 65d1cd6..019bc2b 100644 --- a/vite/src/pipedal/FilePropertyDialog.tsx +++ b/vite/src/pipedal/FilePropertyDialog.tsx @@ -101,6 +101,7 @@ export interface FilePropertyDialogProps extends WithStyles { instanceId: number, selectedFile: string, onOk: (fileProperty: UiFileProperty, selectedItem: string) => void, + onApply: (fileProperty: UiFileProperty, selectedItem: string) => void, onCancel: () => void }; export interface FilePropertyDialogState { @@ -124,6 +125,7 @@ export interface FilePropertyDialogState { newFolderDialogOpen: boolean; renameDialogOpen: boolean; moveDialogOpen: boolean; + initialSelection: string; }; function pathExtension(path: string) { @@ -218,7 +220,8 @@ export default withStyles( menuAnchorEl: null, newFolderDialogOpen: false, renameDialogOpen: false, - moveDialogOpen: false + moveDialogOpen: false, + initialSelection: this.props.selectedFile }; this.requestScroll = true; } @@ -380,6 +383,10 @@ export default withStyles( onSelectValue(fileEntry: FileEntry) { this.requestScroll = true; + if (!fileEntry.isDirectory) + { + this.props.onApply(this.props.fileProperty,fileEntry.pathname); + } this.setState({ selectedFile: fileEntry.pathname, selectedFileIsDirectory: fileEntry.isDirectory, @@ -756,7 +763,10 @@ export default withStyles(
 
-