Skip to content

Commit

Permalink
Create effective content type field for delegating inscriptions.
Browse files Browse the repository at this point in the history
  • Loading branch information
arik-so committed Mar 15, 2024
1 parent c4d1c01 commit 216a044
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ pub struct Inscription {
pub children: Vec<InscriptionId>,
pub content_length: Option<usize>,
pub content_type: Option<String>,
/// Exposes the "real" content type, applicable to delegating inscriptions
pub effective_content_type: Option<String>,
pub fee: u64,
pub height: u32,
pub id: InscriptionId,
Expand Down
10 changes: 10 additions & 0 deletions src/subcommand/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1467,6 +1467,15 @@ impl Server {
let info = Index::inscription_info(&index, query)?
.ok_or_not_found(|| format!("inscription {query}"))?;

let effective_mime_type = if let Some(delegate_id) = info.inscription.delegate() {
let delegate_result = index.get_inscription_by_id(delegate_id);
if let Ok(Some(delegate)) = delegate_result {
delegate.content_type().map(str::to_string)
} else {
info.inscription.content_type().map(str::to_string)
}
} else { info.inscription.content_type().map(str::to_string) };

Ok(if accept_json {
Json(api::Inscription {
address: info
Expand All @@ -1487,6 +1496,7 @@ impl Server {
children: info.children,
content_length: info.inscription.content_length(),
content_type: info.inscription.content_type().map(|s| s.to_string()),
effective_content_type: effective_mime_type,
fee: info.entry.fee,
height: info.entry.height,
id: info.entry.id,
Expand Down
1 change: 1 addition & 0 deletions tests/json_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ fn get_inscription() {
children: Vec::new(),
content_length: Some(3),
content_type: Some("text/plain;charset=utf-8".to_string()),
effective_content_type: Some("text/plain;charset=utf-8".to_string()),
fee: 138,
height: 2,
id: inscription_id,
Expand Down

0 comments on commit 216a044

Please sign in to comment.