| 307 | } |
| 308 | |
| 309 | std::string ImagePlace::GetURL() const |
| 310 | { |
| 311 | bool bIsAttachment = false; |
| 312 | bool useOnlySnowflake = false; |
| 313 | bool dontAppendSize = false; |
| 314 | std::string path = ""; |
| 315 | switch (type) |
| 316 | { |
| 317 | case eImagePlace::AVATARS: |
| 318 | path = "avatars"; |
| 319 | break; |
| 320 | case eImagePlace::ICONS: |
| 321 | path = "icons"; |
| 322 | break; |
| 323 | case eImagePlace::CHANNEL_ICONS: |
| 324 | path = "channel-icons"; |
| 325 | break; |
| 326 | case eImagePlace::EMOJIS: |
| 327 | path = "emojis"; |
| 328 | useOnlySnowflake = true; |
| 329 | break; |
| 330 | case eImagePlace::ATTACHMENTS: |
| 331 | path = "z"; |
| 332 | bIsAttachment = true; |
| 333 | dontAppendSize = true; |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | if (path.empty()) { |
| 338 | DbgPrintW("Image %s could not be downloaded! Path is empty!", key.c_str()); |
| 339 | return ""; |
| 340 | } |
| 341 | |
| 342 | if (bIsAttachment) |
| 343 | return place; |
| 344 | |
| 345 | std::string url = GetDiscordCDN() + path + "/" + std::to_string(sf); |
| 346 | |
| 347 | if (!useOnlySnowflake) |
| 348 | url += "/" + place; |
| 349 | |
| 350 | // Add in the webp / png at the end. |
| 351 | url += |
| 352 | #ifdef WEBP_SUP |
| 353 | ".webp"; |
| 354 | #else |
| 355 | ".png"; |
| 356 | #endif // WEBP_SUB |
| 357 | |
| 358 | // Also the size should reflect the active profile picture size. |
| 359 | if (!dontAppendSize) |
| 360 | { |
| 361 | int size = NearestPowerOfTwo(sizeOverride ? sizeOverride : GetProfilePictureSize()); |
| 362 | // actually increase it a bit to increase quality |
| 363 | if (size < 128) |
| 364 | size = 128; |
| 365 | |
| 366 | url += "?size=" + std::to_string(size); |
no test coverage detected