Binary data can be a filename now.

This commit is contained in:
tastytea 2018-02-09 20:14:50 +01:00
parent b8ef1be5d1
commit 071ebdc607
Signed by: tastytea
GPG Key ID: 59346E0EA35C67E5
3 changed files with 22 additions and 10 deletions

View File

@ -2,7 +2,7 @@ cmake_minimum_required (VERSION 3.7)
include(GNUInstallDirs)
project (mastodon-cpp
VERSION 0.2.10
VERSION 0.2.11
LANGUAGES CXX
)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC")
@ -34,7 +34,7 @@ set_target_properties(mastodon-cpp PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${mastodon-cpp_VERSION_MAJOR}
)
target_link_libraries(mastodon-cpp ${CURL_LIBRARIES} ssl crypto curlpp)
target_link_libraries(mastodon-cpp ssl crypto ${CURL_LIBRARIES} curlpp)
install(TARGETS mastodon-cpp LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
install(FILES ${PROJECT_SOURCE_DIR}/src/mastodon-cpp.hpp
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})

View File

@ -120,9 +120,21 @@ const curlpp::Forms API::maptoformdata(const parametermap &map)
for (const auto &it : map)
{
if (it.second.size() == 1)
{
formdata.push_back(new curlpp::FormParts::Content(it.first,
it.second.front()));
{ // If the file is not base64-encoded, treat as filename
if ((it.first == "avatar" ||
it.first == "header" ||
it.first == "file") &&
it.second.front().substr(0, 4).compare("data") != 0)
{
ttdebug << it.first << ": Filename detected.\n";
formdata.push_back(
new curlpp::FormParts::File(it.first, it.second.front()));
}
else
{
formdata.push_back(
new curlpp::FormParts::Content(it.first, it.second.front()));
}
}
else
{

View File

@ -35,7 +35,7 @@ namespace Mastodon
{
/*!
* @brief Class for the Mastodon API. All input is expected to be UTF-8.
* Binary data must be base64-encoded.
* Binary data must be base64-encoded or a filename.
* @section error Error codes
* | Code | Explanation |
* | --------: |:------------------------------|
@ -246,7 +246,7 @@ public:
/*!
* @brief Make a PATCH request.
*
* Binary data must be base64-encoded.
* Binary data must be base64-encoded or a filename.
*
* @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing parameters
@ -289,7 +289,7 @@ public:
* @brief Make a POST request which doesn't require an argument, pass
* parameters.
*
* Binary data must be base64-encoded.
* Binary data must be base64-encoded or a filename.
*
* @param call A call defined in Mastodon::API::v1
* @param parameters A Mastodon::API::parametermap containing parameters
@ -305,7 +305,7 @@ public:
/*!
* @brief Make a POST request which requires an argument, pass parameters.
*
* Binary data must be base64-encoded.
* Binary data must be base64-encoded or a filename.
*
* @param call A call defined in Mastodon::API::v1
* @param argument The non-optional argument
@ -323,7 +323,7 @@ public:
/*!
* @brief Make a custom POST request.
*
* Binary data must be base64-encoded.
* Binary data must be base64-encoded or a filename.
*
* @param call String in the form `/api/v1/example`
* @param parameters A Mastodon::API::parametermap containing parameters