From 854d2f67af5e9f62c3e774c47dab9d67f08bb3d6 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 12 Mar 2020 11:32:33 +0100 Subject: [PATCH 1/3] Updated Pleroma endpoints to version 2.0.0. * v1:: * pleroma_conversations_id_read * pleroma_accounts_id_scrobbles * pleroma_scrobble * pleroma_statuses_id_reactions_emoji * pleroma_statuses_id_reactions * pleroma:: * admin_users_nickname_toggle_activation * admin_users_permission_group_permission_group * admin_users_activate * admin_users_deactivate * admin_instances_instance_statuses * admin_statuses * admin_users_force_password_reset * admin_grouped_reports * admin_reports_id_notes * admin_reports_report_id_notes_id * admin_restart * admin_config_descriptions * admin_moderation_log * admin_reload_emoji * admin_users_confirm_email * admin_users_resend_confirm_email * admin_stats * emoji_packs * emoji_packs_name * emoji_packs_name_update_file * emoji_packs_name_update_metadata * emoji_packs_download_from * emoji_packs_list_from * emoji_packs_name_download_shared --- include/api.hpp | 63 +++++++++++++++++++-------- src/api.cpp | 110 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 124 insertions(+), 49 deletions(-) diff --git a/include/api.hpp b/include/api.hpp index aab5f41..b37d282 100644 --- a/include/api.hpp +++ b/include/api.hpp @@ -31,7 +31,7 @@ using std::variant; /*! * @brief Holds %API endpoints. * - * Supported %API endpoints: Mastodon 3.0.1, Pleroma 1.1.7. + * Supported %API endpoints: Mastodon 3.0.1, Pleroma 2.0.0. * * @since 0.1.0 * @@ -43,7 +43,7 @@ public: /*! * @brief An enumeration of all v1 %API endpoints. * - * The original `/` are substituted with `_`. + * The original `/` are substituted with `_`. `:` are omitted. * * @since 0.1.0 */ @@ -184,7 +184,6 @@ public: admin_reports_id_reopen, pleroma_notifications_read, - pleroma_accounts_id_subscribe, pleroma_accounts_id_unsubscribe, pleroma_accounts_id_favourites, @@ -192,17 +191,20 @@ public: pleroma_accounts_update_banner, pleroma_accounts_update_background, pleroma_accounts_confirmation_resend, - pleroma_mascot, - pleroma_conversations_id_statuses, pleroma_conversations_id, + pleroma_conversations_id_read, + pleroma_accounts_id_scrobbles, + pleroma_scrobble, + pleroma_statuses_id_reactions_emoji, + pleroma_statuses_id_reactions, }; /*! * @brief An enumeration of all v2 %API endpoints. * - * The original `/` are substituted with `_`. + * The original `/` are substituted with `_`. `:` are omitted. * * @since 0.1.0 */ @@ -214,7 +216,7 @@ public: /*! * @brief An enumeration of all oauth %API endpoints. * - * The original `/` are substituted with `_`. + * The original `/` are substituted with `_`. `:` are omitted. * * @since 0.1.0 */ @@ -230,7 +232,7 @@ public: * * These endpoints are directly under `/api/`. * - * The original `/` are substituted with `_`. + * The original `/` are substituted with `_`. `:` are omitted. * * @since 0.1.0 */ @@ -243,7 +245,7 @@ public: /*! * @brief An enumeration of all pleroma %API endpoints. * - * The original `/` are substituted with `_`. + * The original `/` are substituted with `_`. `:` are omitted. * * @since 0.1.0 */ @@ -252,38 +254,65 @@ public: admin_users, admin_users_follow, admin_users_unfollow, - admin_users_nickname, + admin_users_nickname_toggle_activation, admin_users_tag, admin_users_nickname_permission_group, admin_users_nickname_permission_group_permission_group, - admin_users_nickname_activation_status, + admin_users_permission_group_permission_group, + admin_users_activate, + admin_users_deactivate, admin_users_nickname_or_id, admin_users_nickname_or_id_statuses, + admin_instances_instance_statuses, + admin_statuses, admin_relay, admin_users_invite_token, admin_users_invites, admin_users_revoke_invite, admin_users_email_invite, admin_users_nickname_password_reset, + admin_users_force_password_reset, admin_reports, + admin_grouped_reports, admin_reports_id, - admin_reports_id_respond, + admin_reports_id_notes, + admin_reports_report_id_notes_id, admin_statuses_id, + admin_restart, + admin_config, + admin_config_descriptions, + admin_moderation_log, + admin_reload_emoji, + admin_users_confirm_email, + admin_users_resend_confirm_email, + admin_stats, + + // No longer documented for Pleroma 2.0.0. + admin_users_nickname, + admin_users_nickname_activation_status, + admin_reports_id_respond, admin_config_migrate_to_db, admin_config_migrate_from_db, - admin_config, emoji, follow_import, captcha, - delete_account, disable_account, - account_register, - notification_settings, healthcheck, - change_email + change_email, + emoji_packs, + emoji_packs_name, + emoji_packs_name_update_file, + emoji_packs_name_update_metadata, + emoji_packs_download_from, + emoji_packs_list_from, + emoji_packs_name_download_shared, + + // No longer documented for Pleroma 2.0.0. + account_register, + }; /*! diff --git a/src/api.cpp b/src/api.cpp index 66e963b..e15dd73 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -150,7 +150,7 @@ const map API::_endpoint_map {v1::admin_accounts, "/api/v1/admin/accounts"}, {v1::admin_accounts_id, "/api/v1/admin/accounts/"}, {v1::admin_accounts_account_id_action, - "/api/v1/admin/accounts//action"}, + "/api/v1/admin/accounts//action"}, {v1::admin_accounts_id_approve, "/api/v1/admin/accounts//approve"}, {v1::admin_accounts_id_reject, "/api/v1/admin/accounts//reject"}, {v1::admin_accounts_id_enable, "/api/v1/admin/accounts//enable"}, @@ -159,33 +159,39 @@ const map API::_endpoint_map {v1::admin_reports, "/api/v1/admin/reports"}, {v1::admin_reports_id, "/api/v1/admin/reports/"}, {v1::admin_reports_id_assign_to_self, - "/api/v1/admin/reports//assign_to_self"}, + "/api/v1/admin/reports//assign_to_self"}, {v1::admin_reports_id_unassign, "/api/v1/admin/reports//unassign"}, {v1::admin_reports_id_resolve, "/api/v1/admin/reports//resolve"}, {v1::admin_reports_id_reopen, "/api/v1/admin/reports//reopen"}, {v1::pleroma_notifications_read, " /api/v1/pleroma/notifications/read"}, - {v1::pleroma_accounts_id_subscribe, - "/api/v1/pleroma/accounts//subscribe"}, + "/api/v1/pleroma/accounts//subscribe"}, {v1::pleroma_accounts_id_unsubscribe, - "/api/v1/pleroma/accounts//unsubscribe"}, + "/api/v1/pleroma/accounts//unsubscribe"}, {v1::pleroma_accounts_id_favourites, - "/api/v1/pleroma/accounts//favourites"}, + "/api/v1/pleroma/accounts//favourites"}, {v1::pleroma_accounts_update_avatar, - "/api/v1/pleroma/accounts/update_avatar"}, + "/api/v1/pleroma/accounts/update_avatar"}, {v1::pleroma_accounts_update_banner, - "/api/v1/pleroma/accounts/update_banner"}, + "/api/v1/pleroma/accounts/update_banner"}, {v1::pleroma_accounts_update_background, - "/api/v1/pleroma/accounts/update_background"}, + "/api/v1/pleroma/accounts/update_background"}, {v1::pleroma_accounts_confirmation_resend, - "/api/v1/pleroma/accounts/confirmation_resend"}, - + "/api/v1/pleroma/accounts/confirmation_resend"}, {v1::pleroma_mascot, "/api/v1/pleroma/mascot"}, - {v1::pleroma_conversations_id_statuses, - "/api/v1/pleroma/conversations//statuses"}, + "/api/v1/pleroma/conversations//statuses"}, {v1::pleroma_conversations_id, "/api/v1/pleroma/conversations/"}, + {v1::pleroma_conversations_id_read, + "/api/v1/pleroma/conversations//read"}, + {v1::pleroma_accounts_id_scrobbles, + "/api/v1/pleroma/accounts//scrobbles"}, + {v1::pleroma_scrobble, "/api/v1/pleroma/scrobble"}, + {v1::pleroma_statuses_id_reactions_emoji, + "/api/v1/pleroma/statuses//reactions/"}, + {v1::pleroma_statuses_id_reactions, + "/api/v1/pleroma/statuses//reactions"}, {v2::search, "/api/v2/search"}, @@ -199,49 +205,89 @@ const map API::_endpoint_map {pleroma::admin_users, "/api/pleroma/admin/users"}, {pleroma::admin_users_follow, "/api/pleroma/admin/users/follow"}, {pleroma::admin_users_unfollow, "/api/pleroma/admin/users/unfollow"}, - {pleroma::admin_users_nickname, "/api/pleroma/admin/users/"}, + {pleroma::admin_users_nickname_toggle_activation, + "/api/pleroma/admin/users//toggle_activation"}, {pleroma::admin_users_tag, "/api/pleroma/admin/users/tag"}, {pleroma::admin_users_nickname_permission_group, - "/api/pleroma/admin/users//permission_group"}, + "/api/pleroma/admin/users//permission_group"}, {pleroma::admin_users_nickname_permission_group_permission_group, - "/api/pleroma/admin/users//permission_group/"}, - {pleroma::admin_users_nickname_activation_status, - "/api/pleroma/admin/users//activation_status"}, + "/api/pleroma/admin/users/" + "/permission_group/"}, + {pleroma::admin_users_permission_group_permission_group, + "/api/pleroma/admin/users/permission_group/"}, + {pleroma::admin_users_activate, "/api/pleroma/admin/users/activate"}, + {pleroma::admin_users_deactivate, "/api/pleroma/admin/users/deactivate"}, {pleroma::admin_users_nickname_or_id, - "/api/pleroma/admin/users/"}, + "/api/pleroma/admin/users/"}, {pleroma::admin_users_nickname_or_id_statuses, - "/api/pleroma/admin/users//statuses"}, + "/api/pleroma/admin/users//statuses"}, + {pleroma::admin_instances_instance_statuses, + "/api/pleroma/admin/instances//statuses"}, + {pleroma::admin_statuses, "/api/pleroma/admin/statuses"}, {pleroma::admin_relay, "/api/pleroma/admin/relay"}, {pleroma::admin_users_invite_token, - "/api/pleroma/admin/users/invite_token"}, + "/api/pleroma/admin/users/invite_token"}, {pleroma::admin_users_invites, "/api/pleroma/admin/users/invites"}, {pleroma::admin_users_revoke_invite, - "/api/pleroma/admin/users/revoke_invite"}, + "/api/pleroma/admin/users/revoke_invite"}, {pleroma::admin_users_email_invite, - "/api/pleroma/admin/users/email_invite"}, + "/api/pleroma/admin/users/email_invite"}, {pleroma::admin_users_nickname_password_reset, - "/api/pleroma/admin/users//password_reset"}, + "/api/pleroma/admin/users//password_reset"}, + {pleroma::admin_users_force_password_reset, + "/api/pleroma/admin/users/force_password_reset"}, {pleroma::admin_reports, "/api/pleroma/admin/reports"}, + {pleroma::admin_grouped_reports, "/api/pleroma/admin/grouped_reports"}, {pleroma::admin_reports_id, "/api/pleroma/admin/reports/"}, - {pleroma::admin_reports_id_respond, - "/api/pleroma/admin/reports//respond"}, + {pleroma::admin_reports_id_notes, "/api/pleroma/admin/reports//notes"}, + {pleroma::admin_reports_report_id_notes_id, + "/api/pleroma/admin/reports//notes/"}, {pleroma::admin_statuses_id, "/api/pleroma/admin/statuses/"}, - {pleroma::admin_config_migrate_to_db, - "/api/pleroma/admin/config/migrate_to_db"}, - {pleroma::admin_config_migrate_from_db, - "/api/pleroma/admin/config/migrate_from_db"}, + {pleroma::admin_restart, "/api/pleroma/admin/restart"}, {pleroma::admin_config, "/api/pleroma/admin/config"}, + {pleroma::admin_config_descriptions, + "/api/pleroma/admin/config/descriptions"}, + {pleroma::admin_moderation_log, "/api/pleroma/admin/moderation_log"}, + {pleroma::admin_reload_emoji, "/api/pleroma/admin/reload_emoji"}, + {pleroma::admin_users_confirm_email, + "/api/pleroma/admin/users/confirm_email"}, + {pleroma::admin_users_resend_confirm_email, + "/api/pleroma/admin/users/resend_confirm_email"}, + {pleroma::admin_stats, "/api/pleroma/admin/stats"}, + + {pleroma::admin_users_nickname, "/api/pleroma/admin/users/"}, + {pleroma::admin_users_nickname_activation_status, + "/api/pleroma/admin/users//activation_status"}, + {pleroma::admin_reports_id_respond, + "/api/pleroma/admin/reports//respond"}, + {pleroma::admin_config_migrate_to_db, + "/api/pleroma/admin/config/migrate_to_db"}, + {pleroma::admin_config_migrate_from_db, + "/api/pleroma/admin/config/migrate_from_db"}, {pleroma::emoji, "/api/pleroma/emoji"}, {pleroma::follow_import, "/api/pleroma/follow_import"}, {pleroma::captcha, "/api/pleroma/captcha,"}, {pleroma::delete_account, "/api/pleroma/delete_account"}, {pleroma::disable_account, "/api/pleroma/disable_account"}, - {pleroma::account_register, "/api/pleroma/account/register"}, - {pleroma::notification_settings, "/api/pleroma/notification_settings"}, {pleroma::healthcheck, "/api/pleroma/healthcheck"}, {pleroma::change_email, "/api/pleroma/change_email"}, + {pleroma::emoji_packs, "/api/pleroma/emoji/packs"}, + {pleroma::emoji_packs_name, "/api/pleroma/emoji/packs/"}, + {pleroma::emoji_packs_name_update_file, + "/api/pleroma/emoji/packs//update_file"}, + {pleroma::emoji_packs_name_update_metadata, + "/api/pleroma/emoji/packs//update_metadata"}, + {pleroma::emoji_packs_download_from, + "/api/pleroma/emoji/packs/download_from"}, + {pleroma::emoji_packs_list_from, + "/api/pleroma/emoji/packs/list_from"}, + {pleroma::emoji_packs_name_download_shared, + "/api/pleroma/emoji/packs//download_shared"}, + + {pleroma::account_register, "/api/pleroma/account/register"}, + }; } // namespace mastodonpp From 00056c224e2377bbbf366a99f69eb79d7671357f Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 12 Mar 2020 11:40:11 +0100 Subject: [PATCH 2/3] Update parameter replacements for Pleroma 2.0.0. --- src/curl_wrapper.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index bfa59ee..510f1c8 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -355,8 +355,9 @@ bool CURLWrapper::replace_parameter_in_uri(string &uri, { static constexpr array replace { - "id", "nickname", "nickname_or_id", "account_id", - "list_id", "hashtag", "permission_group" + "id", "nickname", "nickname_or_id", "account_id", "list_id", + "hashtag", "permission_group", "instance", "report_id", "name", + "emoji" }; if (any_of(replace.begin(), replace.end(), [¶meter](const auto &s) { return s == parameter.first; })) From da1c2ba409a4857ab83f42443419b5fa10790291 Mon Sep 17 00:00:00 2001 From: tastytea Date: Thu, 12 Mar 2020 12:06:31 +0100 Subject: [PATCH 3/3] Handle more than one replacement in replace_parameter_in_uri(). --- src/curl_wrapper.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/curl_wrapper.cpp b/src/curl_wrapper.cpp index 510f1c8..9341069 100644 --- a/src/curl_wrapper.cpp +++ b/src/curl_wrapper.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include namespace mastodonpp @@ -30,8 +31,10 @@ namespace mastodonpp using std::get; using std::holds_alternative; using std::any_of; +using std::transform; using std::array; // NOLINT(misc-unused-using-decls) using std::atomic; +using std::toupper; using std::uint8_t; using std::uint16_t; @@ -362,7 +365,15 @@ bool CURLWrapper::replace_parameter_in_uri(string &uri, if (any_of(replace.begin(), replace.end(), [¶meter](const auto &s) { return s == parameter.first; })) { - const auto pos{uri.find('<')}; + const string searchstring{[¶meter] + { + string s{"<"}; + s += parameter.first; + transform(s.begin(), s.end(), s.begin(), + [](const unsigned char c){ return toupper(c); }); + return s; + }()}; + const auto pos{uri.find(searchstring)}; if (pos != string::npos) { uri.replace(pos, parameter.first.size() + 2,