Add support for RSS tags. Also add cgi::tolower().
This commit is contained in:
parent
a23019dcf1
commit
9707694be6
|
@ -26,7 +26,7 @@ steps:
|
|||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- apt-get update -q
|
||||
- apt-get install -qq build-essential cmake g++-10 clang pkg-config
|
||||
- apt-get install -qq catch libcgicc-dev nlohmann-json3-dev libgit2-dev libcurl4-openssl-dev
|
||||
- apt-get install -qq catch libcgicc-dev nlohmann-json3-dev libgit2-dev libcurl4-openssl-dev libicu-dev
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake -G "Unix Makefiles" -DWITH_TESTS=YES ..
|
||||
- make VERBOSE=1
|
||||
|
@ -62,7 +62,7 @@ steps:
|
|||
- alias apt-get='rm -f /var/cache/apt/archives/lock && apt-get'
|
||||
- apt-get update -q
|
||||
- apt-get install -qq build-essential cmake clang pkg-config
|
||||
- apt-get install -qq catch libcgicc-dev nlohmann-json-dev libgit2-dev libcurl4-openssl-dev
|
||||
- apt-get install -qq catch libcgicc-dev nlohmann-json-dev libgit2-dev libcurl4-openssl-dev libicu-dev
|
||||
- rm -rf build && mkdir -p build && cd build
|
||||
- cmake -G "Unix Makefiles" -DWITH_TESTS=YES ..
|
||||
- make VERBOSE=1
|
||||
|
|
|
@ -41,6 +41,7 @@ find_package(nlohmann_json REQUIRED CONFIG)
|
|||
find_package(Filesystem REQUIRED COMPONENTS Final Experimental)
|
||||
pkg_check_modules(libgit2 REQUIRED IMPORTED_TARGET libgit2)
|
||||
find_package(CURL 7.56 REQUIRED)
|
||||
find_package(ICU REQUIRED COMPONENTS uc)
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(src/generators)
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
:uri-nlohmann-json: https://nlohmann.github.io/json/
|
||||
:uri-libgit2: https://libgit2.org/
|
||||
:uri-libcurl: https://curl.haxx.se/libcurl/
|
||||
:uti-icu: http://site.icu-project.org/
|
||||
|
||||
*{project}* turns form data into JSON and opens a pull request on
|
||||
link:https://schlomp.space/FediBlock/data[FediBlock/data]. Also included are
|
||||
|
@ -87,6 +88,7 @@ Existing screenshots will not be overwritten.
|
|||
* link:{uri-nlohmann-json}[nlohmann-json] (tested: 3.7 / 2.1)
|
||||
* link:{uri-libgit2}[libgit2] with SSH support (tested: 1.0 / 0.26)
|
||||
* link:{uri-libcurl}[libcurl] (at least: 7.56)
|
||||
* link:{uri-icu}[icu] (tested: 67.1 / 60.2)
|
||||
* Optional
|
||||
** Tests: link:{uri-catch}[Catch] (tested: 2.5 / 1.10)
|
||||
** DEB package: link:{uri-dpkg}[dpkg] (tested: 1.19)
|
||||
|
|
|
@ -21,9 +21,9 @@ target_link_libraries(fediblock
|
|||
PkgConfig::libgit2)
|
||||
|
||||
if(${CMAKE_VERSION} VERSION_LESS 3.12)
|
||||
target_link_libraries(fediblock PUBLIC ${CURL_LIBRARIES})
|
||||
target_link_libraries(fediblock PUBLIC ${CURL_LIBRARIES} ICU::uc)
|
||||
else()
|
||||
target_link_libraries(fediblock PUBLIC CURL::libcurl)
|
||||
target_link_libraries(fediblock PUBLIC CURL::libcurl ICU::uc)
|
||||
endif()
|
||||
|
||||
add_executable(${PROJECT_NAME} main.cpp)
|
||||
|
|
30
src/cgi.cpp
30
src/cgi.cpp
|
@ -20,11 +20,14 @@
|
|||
#include "time.hpp"
|
||||
|
||||
#include <cgicc/Cgicc.h>
|
||||
#include <unicode/unistr.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <fstream>
|
||||
#include <ios>
|
||||
#include <iostream>
|
||||
#include <iterator>
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
|
@ -33,6 +36,7 @@
|
|||
namespace FediBlock::cgi
|
||||
{
|
||||
|
||||
using std::back_inserter;
|
||||
using std::getline;
|
||||
using std::ios;
|
||||
using std::ofstream;
|
||||
|
@ -40,6 +44,7 @@ using std::runtime_error;
|
|||
using std::string;
|
||||
using std::string_view;
|
||||
using std::stringstream;
|
||||
using std::transform;
|
||||
using std::vector;
|
||||
using std::chrono::system_clock;
|
||||
|
||||
|
@ -50,6 +55,8 @@ entry_type parse_formdata()
|
|||
cgicc::Cgicc cgi;
|
||||
entry.instance = cgi("instance");
|
||||
entry.tags = string_to_vector(cgi("tags"));
|
||||
transform(entry.tags.begin(), entry.tags.end(), entry.tags.begin(),
|
||||
[](const auto &tag) { return tolower(tag); });
|
||||
entry.receipts = string_to_vector(cgi("receipts"));
|
||||
entry.description = cgi("description");
|
||||
entry.report_time = time::to_string(system_clock::now());
|
||||
|
@ -96,4 +103,27 @@ vector<string> string_to_vector(const string_view str)
|
|||
return vec;
|
||||
}
|
||||
|
||||
vector<string> get_tags()
|
||||
{
|
||||
cgicc::Cgicc cgi;
|
||||
vector<cgicc::FormEntry> tags_form;
|
||||
vector<string> tags_string;
|
||||
|
||||
cgi.getElement("tags[]", tags_form);
|
||||
transform(tags_form.begin(), tags_form.end(), back_inserter(tags_string),
|
||||
[](const auto &element) { return tolower(element.getValue()); });
|
||||
|
||||
return tags_string;
|
||||
}
|
||||
|
||||
string tolower(const string_view str)
|
||||
{
|
||||
string result;
|
||||
|
||||
const auto unistr{icu::UnicodeString(str.data(), "UTF-8").toLower()};
|
||||
unistr.toUTF8String(result);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
} // namespace FediBlock::cgi
|
||||
|
|
12
src/cgi.hpp
12
src/cgi.hpp
|
@ -36,6 +36,18 @@ using std::vector;
|
|||
// Split a string at commas, return a vector.
|
||||
[[nodiscard]] vector<string> 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.
|
||||
*
|
||||
* @since 0.1.0
|
||||
*/
|
||||
[[nodiscard]] vector<string> get_tags();
|
||||
|
||||
// Return str in lowercase.
|
||||
[[nodiscard]] string tolower(string_view str);
|
||||
|
||||
} // namespace FediBlock::cgi
|
||||
|
||||
#endif // FEDIBLOCK_BACKEND_CGI_HPP
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
|
||||
#include "rss.hpp"
|
||||
#include "cgi.hpp"
|
||||
#include "files.hpp"
|
||||
#include "git.hpp"
|
||||
#include "time.hpp"
|
||||
|
@ -218,7 +219,7 @@ int main(int argc, char *argv[])
|
|||
}
|
||||
const auto entries{files::read_json_files(true)};
|
||||
cout << "Content-Type: application/rss+xml\r\n\r\n";
|
||||
write_rss(cout, entries, {});
|
||||
write_rss(cout, entries, cgi::get_tags());
|
||||
}
|
||||
catch (const exception &e)
|
||||
{
|
||||
|
|
Reference in New Issue