|
|
@@ -8,11 +8,32 @@
|
|
|
#include <grpcpp/grpcpp.h>
|
|
|
#include <cctype>
|
|
|
#include <optional>
|
|
|
+#include <sstream>
|
|
|
+#include <iomanip>
|
|
|
|
|
|
namespace smartbotic::webserver::api {
|
|
|
|
|
|
using namespace common;
|
|
|
|
|
|
+namespace {
|
|
|
+
|
|
|
+// std::to_string(static_cast<int>(0.5)) prints "0" - a fractional field
|
|
|
+// limit like 0.5 MB would read back as "larger than the 0 MB limit", which
|
|
|
+// is worse than useless. Print with enough precision to keep a fraction,
|
|
|
+// then drop a trailing ".0"/".00" etc so a whole number still reads as one.
|
|
|
+std::string formatMb(double mb) {
|
|
|
+ std::ostringstream ss;
|
|
|
+ ss << std::fixed << std::setprecision(2) << mb;
|
|
|
+ std::string s = ss.str();
|
|
|
+ if (s.find('.') != std::string::npos) {
|
|
|
+ while (!s.empty() && s.back() == '0') s.pop_back();
|
|
|
+ if (!s.empty() && s.back() == '.') s.pop_back();
|
|
|
+ }
|
|
|
+ return s;
|
|
|
+}
|
|
|
+
|
|
|
+} // namespace
|
|
|
+
|
|
|
WebhookController::WebhookController(storage::StorageClient& storage,
|
|
|
runners::RunnerRegistry& registry,
|
|
|
runners::LoadBalancer& load_balancer,
|
|
|
@@ -418,7 +439,7 @@ bool WebhookController::buildFormTriggerData(const httplib::Request& req,
|
|
|
// this only tightens, never loosens.
|
|
|
const double max_mb = f.value("maxSizeMb", 0.0);
|
|
|
if (max_mb > 0 && static_cast<double>(file.content.size()) > max_mb * 1024 * 1024) {
|
|
|
- error = label + " is larger than the " + std::to_string(static_cast<int>(max_mb)) +
|
|
|
+ error = label + " is larger than the " + formatMb(max_mb) +
|
|
|
" MB limit for this field.";
|
|
|
return false;
|
|
|
}
|