|
1 |
| -use alloy::transports::http::reqwest::Url; |
| 1 | +use alloy::transports::http::reqwest::{self, Url}; |
| 2 | +use mime_sniffer::MimeTypeSniffer; |
2 | 3 | use serde::{Deserialize, Serialize};
|
3 | 4 | use std::path::PathBuf;
|
4 | 5 | use thiserror::Error;
|
@@ -46,6 +47,8 @@ pub enum OperatorMetadataError {
|
46 | 47 | LogoUrlInvalid,
|
47 | 48 | #[error("Logo url has an invalid image extension")]
|
48 | 49 | LogoUrlInvalidImageExtension,
|
| 50 | + #[error("Logo has an unsupported mime type")] |
| 51 | + LogoUrlInvalidMimeType, |
49 | 52 |
|
50 | 53 | #[error("Website url is invalid")]
|
51 | 54 | WebsiteUrlInvalid,
|
@@ -104,7 +107,12 @@ impl OperatorMetadata {
|
104 | 107 | if path.extension().map(|ext| ext != "png").unwrap_or(true) {
|
105 | 108 | return Err(LogoUrlInvalidImageExtension);
|
106 | 109 | }
|
107 |
| - // TODO: check if the server returns the content with a "image/png" mime type |
| 110 | + let response = reqwest::get(&self.logo).await.unwrap(); |
| 111 | + let body = response.bytes().await.unwrap(); |
| 112 | + |
| 113 | + if body.sniff_mime_type().map_or(true, |m| m != "image/png") { |
| 114 | + return Err(LogoUrlInvalidMimeType); |
| 115 | + } |
108 | 116 |
|
109 | 117 | // website, if non-empty, must have less than 1024 characters,
|
110 | 118 | // not point to localhost or 127.0.0.1, and must be a valid URL that matches the regex
|
|
0 commit comments