Skip to content

Commit

Permalink
fix: webhook now uses utility::mime_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskowicz1 committed Oct 20, 2023
1 parent c530a98 commit dfb0b85
Showing 1 changed file with 1 addition and 7 deletions.
8 changes: 1 addition & 7 deletions src/dpp/webhook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,13 @@ json webhook::to_json_impl(bool with_id) const {
}

webhook& webhook::load_image(const std::string &image_blob, const image_type type, bool is_base64_encoded) {
static const std::map<image_type, std::string> mimetypes = {
{ i_gif, "image/gif" },
{ i_jpg, "image/jpeg" },
{ i_png, "image/png" },
{ i_webp, "image/webp" },
};
if (image_blob.size() > MAX_ICON_SIZE) {
throw dpp::length_exception("Webhook icon file exceeds discord limit of 256 kilobytes");
}

/* If there's already image data defined, free the old data, to prevent a memory leak */
delete image_data;
image_data = new std::string("data:" + mimetypes.find(type)->second + ";base64," + (is_base64_encoded ? image_blob : base64_encode((unsigned char const*)image_blob.data(), (unsigned int)image_blob.length())));
image_data = new std::string("data:" + utility::mime_type(type) + ";base64," + (is_base64_encoded ? image_blob : base64_encode((unsigned char const*)image_blob.data(), (unsigned int)image_blob.length())));

Check notice on line 105 in src/dpp/webhook.cpp

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/dpp/webhook.cpp#L105

C-style pointer casting

return *this;
}
Expand Down

0 comments on commit dfb0b85

Please sign in to comment.