Skip to content

Commit

Permalink
feat: moved the limit to a constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Jul 22, 2024
1 parent 6310673 commit e5b0212
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/dpp/user.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

namespace dpp {

constexpr uint32_t MAX_AVATAR_SIZE = 10240 * 1000; // 10240KB.

/**
* @brief Various bitmask flags used to represent information about a dpp::user
*/
Expand Down
4 changes: 2 additions & 2 deletions src/dpp/cluster/user.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ void cluster::current_user_edit(const std::string &nickname, const std::string&
};

if (!avatar_blob.empty()) {
if(avatar_blob.size() > (10240 * 1000)) { // Avatar limit is 10240 kb.
if(avatar_blob.size() > MAX_AVATAR_SIZE) { // Avatar limit is 10240 kb.
throw dpp::length_exception(err_icon_size, "Avatar file exceeds discord limit of 10240 kilobytes");
}
j["avatar"] = "data:" + mimetypes.find(avatar_type)->second + ";base64," + base64_encode((unsigned char const*)avatar_blob.data(), static_cast<unsigned int>(avatar_blob.length()));
Expand All @@ -48,7 +48,7 @@ void cluster::current_user_edit(const std::string &nickname, const std::string&
/* There doesn't seem to be a banner limit (probably due to the limit of 640x280)
* however, this is here as a precautionary.
*/
if(banner_blob.size() > (10240 * 1000)) {
if(banner_blob.size() > MAX_AVATAR_SIZE) {
throw dpp::length_exception(err_icon_size, "Banner file exceeds discord limit of 10240 kilobytes");
}
j["banner"] = "data:" + mimetypes.find(banner_type)->second + ";base64," + base64_encode((unsigned char const*)banner_blob.data(), static_cast<unsigned int>(banner_blob.length()));
Expand Down

0 comments on commit e5b0212

Please sign in to comment.