diff --git a/src/cgi.cpp b/src/cgi.cpp index da1c136..87b8113 100644 --- a/src/cgi.cpp +++ b/src/cgi.cpp @@ -77,10 +77,24 @@ entry_type parse_formdata() } entry.instance = cgi("instance"); - entry.tags = string_to_vector(cgi("tags")); + if (!cgi("tags").empty()) // Old form. + { + entry.tags = string_to_vector(cgi("tags")); + } + else + { + entry.tags = get_array("tags[]"); + } transform(entry.tags.begin(), entry.tags.end(), entry.tags.begin(), [](const auto &tag) { return tolower(tag); }); - entry.receipts = string_to_vector(cgi("receipts")); + if (!cgi("receipts").empty()) // Old form. + { + entry.receipts = string_to_vector(cgi("receipts")); + } + else + { + entry.receipts = get_array("receipts[]"); + } entry.description = cgi("description"); entry.report_time = time::to_string(system_clock::now()); @@ -143,26 +157,26 @@ vector string_to_vector(const string_view str) return vec; } -vector get_tags() +vector get_array(const string &name) { cgicc::Cgicc cgi; - vector tags_form; - vector tags_string; + vector form; + vector values; - cgi.getElement("tags[]", tags_form); - for (const auto &element : tags_form) + cgi.getElement(name, form); + for (const auto &element : form) { - const string tag{element.getValue()}; - if (!tag.empty()) + const string value{element.getValue()}; + if (!value.empty()) { - const auto new_tags{string_to_vector(tolower(tag))}; - tags_string.insert(tags_string.end(), - std::make_move_iterator(new_tags.begin()), - std::make_move_iterator(new_tags.end())); + const auto new_values{string_to_vector(tolower(value))}; + values.insert(values.end(), + std::make_move_iterator(new_values.begin()), + std::make_move_iterator(new_values.end())); } } - return tags_string; + return values; } string tolower(const string_view str) diff --git a/src/cgi.hpp b/src/cgi.hpp index 8f30302..9929cf3 100644 --- a/src/cgi.hpp +++ b/src/cgi.hpp @@ -39,13 +39,11 @@ using std::vector; [[nodiscard]] vector string_to_vector(string_view str); /*! - * @brief Read tags from QUERY_STRING or stdin and return it as a vector. - * - * For use in rss.cpp. + * @brief Read array from QUERY_STRING or stdin and return it as a vector. * * @since 0.1.0 */ -[[nodiscard]] vector get_tags(); +[[nodiscard]] vector get_array(const string &name); // Return str in lowercase. [[nodiscard]] string tolower(string_view str); diff --git a/src/generators/rss.cpp b/src/generators/rss.cpp index 99ad35b..9cd2ef3 100644 --- a/src/generators/rss.cpp +++ b/src/generators/rss.cpp @@ -222,7 +222,7 @@ int main(int /*argc*/, char * /*argv*/[]) // Ignore, use old version of repo. } const auto entries{files::read_json_files(true)}; - write_rss(cout, entries, cgi::get_tags()); + write_rss(cout, entries, cgi::get_array("tags[]")); } catch (const exception &e) {