diff --git a/a.out b/a.out deleted file mode 100644 index dd7982f..0000000 Binary files a/a.out and /dev/null differ diff --git a/src/PluginHost.cpp b/src/PluginHost.cpp index 8391cf9..8e1f04e 100644 --- a/src/PluginHost.cpp +++ b/src/PluginHost.cpp @@ -681,19 +681,26 @@ Lv2PluginInfo::FindWritablePathProperties(PluginHost *lv2Host, const LilvPlugin std::filesystem::path bundleDirectoryName = std::filesystem::path(bundle_path()).parent_path().filename(); std::filesystem::path legacyUploadPath = lv2Host->MapPath(bundleDirectoryName.string()); - if (std::filesystem::exists(legacyUploadPath)) - { - if (!std::filesystem::exists(legacyUploadPath / ".migrated")) - { - fileProperty->useLegacyModDirectory(true); - fileProperty->directory(bundleDirectoryName); - } - modFileTypes.rootDirectories().push_back(bundleDirectoryName.filename()); // push the private directory! - } fileProperty->setModFileTypes(modFileTypes); fileProperty->directory(bundleDirectoryName); + if (std::filesystem::exists(legacyUploadPath) + && !std::filesystem::exists(legacyUploadPath / ".migrated")) + { + fileProperty->useLegacyModDirectory(true); + fileProperty->directory(bundleDirectoryName); + modFileTypes.rootDirectories().push_back(bundleDirectoryName.filename()); // push the private directory! + } else { + if (modFileTypes.rootDirectories().size() == 1) + { + std::string modName = modFileTypes.rootDirectories()[0]; + auto modDirectory = modFileTypes.GetModDirectory(modName); + fileProperty->directory(modDirectory->pipedalPath); + } + } + + fileProperties.push_back(fileProperty); } else { unsupportedPatchProperty = true; diff --git a/src/WebServer.cpp b/src/WebServer.cpp index f3a4b14..0ad2718 100644 --- a/src/WebServer.cpp +++ b/src/WebServer.cpp @@ -636,6 +636,40 @@ std::string GetFromAddress(const tcp::socket &socket) s << socket.remote_endpoint().address().to_string() << ':' << socket.remote_endpoint().port(); return s.str(); } + +static bool encoding_allowed(const std::string&acceptEncodingHeader,const std::string&encoding) +{ + auto npos = acceptEncodingHeader.find(encoding); + if (npos == std::string::npos) + return false; + std::vector encodings = split(acceptEncodingHeader, ','); + for (auto &e : encodings) + { + if (e.starts_with(encoding)) { + if (e.length() == encoding.length()) + return true; + if (e[encoding.length()] == ';') + return true; + } + } + return false; +} + +static bool can_use_gzip_encoding( + const std::string &acceptEncodingHeader, + const std::filesystem::path &filename, + std::filesystem::path *gzName) +{ + if (!encoding_allowed(acceptEncodingHeader, "gzip")) + return false; + *gzName = filename.string() + ".gz"; + if (std::filesystem::exists(*gzName)) { + return true; + } + return false; +} + + namespace pipedal { @@ -1125,12 +1159,22 @@ namespace pipedal } } + + std::string mimeType = mime_type(filename); + + std::filesystem::path gzName; + + if (can_use_gzip_encoding(req.get(HttpField::accept_encoding) ,filename,&gzName) ) + { + filename = gzName; + res.set(HttpField::content_encoding,"gzip"); + } + if (req.method() != HttpVerb::get) { ServerError(*con, "Unknown HTTP-Method"); return; } - std::string mimeType = mime_type(filename); file.open(filename.c_str(), std::ios::in); if (!file) diff --git a/src/WebServer.hpp b/src/WebServer.hpp index f85657a..e121cc2 100644 --- a/src/WebServer.hpp +++ b/src/WebServer.hpp @@ -71,6 +71,8 @@ public: constexpr static const char* date = "Date"; constexpr static const char* referer = "Referer"; constexpr static const char * location = "Location"; + constexpr static const char* accept_encoding = "Accept-Encoding"; + constexpr static const char* content_encoding = "Content-Encoding"; }; diff --git a/vite/build.sh b/vite/build.sh new file mode 100755 index 0000000..26b6983 --- /dev/null +++ b/vite/build.sh @@ -0,0 +1,14 @@ +#!/bin/bash +npm run build && \ +#remove any existing .gz files. +if ls dist/assets/index*.js.gz 1> /dev/null 2>&1; then + rm dist/assets/index*.js.gz +fi +# generate a .gz file for each index*.js file + +if ls dist/assets/index*.js 1> /dev/null 2>&1; then + for file in dist/assets/index*.js; do + # generate a .gz file + gzip -c $file > $file.gz + done +fi