Skip to content

Commit

Permalink
Hide BVM Network inscriptions (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
casey committed Jan 15, 2024
1 parent 41d9474 commit 6e0661c
Showing 1 changed file with 22 additions and 16 deletions.
38 changes: 22 additions & 16 deletions src/inscriptions/inscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,27 +290,19 @@ impl Inscription {
pub(crate) fn hidden(&self) -> bool {
use regex::bytes::Regex;

const BVM_NETWORK: &[u8] = b"<body style=\"background:#F61;color:#fff;\">\
<h1 style=\"height:100%\">bvm.network</h1></body>";

lazy_static! {
static ref CONTENT: Regex = Regex::new(r"^\s*/content/[[:xdigit:]]{64}i\d+\s*$").unwrap();
static ref BRC_420: Regex = Regex::new(r"^\s*/content/[[:xdigit:]]{64}i\d+\s*$").unwrap();
}

if self
self
.body()
.map(|body| CONTENT.is_match(body))
.map(|body| BRC_420.is_match(body) || body.starts_with(BVM_NETWORK))
.unwrap_or_default()
{
return true;
}

if self.metaprotocol.is_some() {
return true;
}

if let Media::Code(_) | Media::Text | Media::Unknown = self.media() {
return true;
}

false
|| self.metaprotocol.is_some()
|| matches!(self.media(), Media::Code(_) | Media::Text | Media::Unknown)
}
}

Expand Down Expand Up @@ -827,6 +819,20 @@ mod tests {
Some(" /content/09a8d837ec0bcaec668ecf405e696a16bee5990863659c224ff888fb6f8f45e7i0 \n"),
true,
);
case(
Some("text/html"),
Some(
r#"<body style="background:#F61;color:#fff;"><h1 style="height:100%">bvm.network</h1></body>"#,
),
true,
);
case(
Some("text/html"),
Some(
r#"<body style="background:#F61;color:#fff;"><h1 style="height:100%">bvm.network</h1></body>foo"#,
),
true,
);

assert!(Inscription {
content_type: Some("text/plain".as_bytes().into()),
Expand Down

0 comments on commit 6e0661c

Please sign in to comment.