From ebc055ee0a129403a172d01812e5c48b1bb80fb4 Mon Sep 17 00:00:00 2001 From: blankie Date: Sun, 3 Dec 2023 10:50:47 +1100 Subject: [PATCH] Fix "key 'small' not found" https://social.platypus-sandbox.com/@ashten/AcPlHNRnHGzjZMGX56 --- models.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/models.cpp b/models.cpp index 21aa93a..65c8a1c 100644 --- a/models.cpp +++ b/models.cpp @@ -76,9 +76,14 @@ void from_json(const json& j, Media& media) { } // .contains() check: https://social.platypus-sandbox.com/@ashten/AcPl5zVFxeGu7eSKSe if (j.contains("meta") && (media.type == "image" || media.type == "video" || media.type == "gifv")) { + // .contains() checks: https://social.platypus-sandbox.com/@ashten/AcPlHNRnHGzjZMGX56 const json& meta = j["meta"]; - media.size = meta.at("original").get(); - media.preview_size = meta.at("small").get(); + if (meta.contains("original")) { + media.size = meta["original"].get(); + } + if (meta.contains("small")) { + media.preview_size = meta["small"].get(); + } } if (!j.at("description").is_null()) { media.description = j["description"].get();