Skip to content

Commit

Permalink
changed the contentType for the ledger content sources
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinrp committed Nov 13, 2023
1 parent de67886 commit 64078b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
13 changes: 4 additions & 9 deletions crates/api/src/v1/ledger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,33 @@ pub struct LedgerSource {
pub last_registry_index: RegistryIndex,
/// The HTTP GET URL location for the ledger source.
pub url: String,
/// Content type for the ledger source.
pub content_type: LedgerSourceContentType,
/// Optional, server accepts for HTTP Range header.
#[serde(skip_serializing_if = "is_false")]
pub accept_ranges: bool,
/// Content type for the ledger source.
#[serde(default, skip_serializing_if = "is_ledger_packed")]
pub content_type: LedgerSourceContentType,
}

fn is_false(b: &bool) -> bool {
!b
}

fn is_ledger_packed(content_type: &LedgerSourceContentType) -> bool {
content_type == &LedgerSourceContentType::Packed
}

/// Content type for the ledger source.
#[derive(Default, PartialEq, Serialize, Deserialize)]
pub enum LedgerSourceContentType {
/// The content type is binary representation of the LogId and RecordId hashes without padding.
/// In the case of `sha256` hash algorithm, this is a repeating sequence of 64 bytes (32 bytes
/// for each the LogId and RecordId) without padding.
#[default]
#[serde(rename = "application/vnd.bytecodealliance.registry.ledger.packed")]
#[serde(rename = "application/vnd.warg.ledger.packed")]
Packed,
}

impl LedgerSourceContentType {
/// Returns the content type represented as a string.
pub fn as_str(&self) -> &'static str {
match self {
Self::Packed => "application/vnd.bytecodealliance.registry.ledger.packed",
Self::Packed => "application/vnd.warg.ledger.packed",
}
}
}
11 changes: 6 additions & 5 deletions crates/server/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1391,6 +1391,7 @@ components:
- firstRegistryIndex
- lastRegistryIndex
- url
- contentType
properties:
firstRegistryIndex:
type: integer
Expand All @@ -1404,14 +1405,14 @@ components:
type: string
description: The HTTP GET URL to fetch the source.
example: http://registry.example.com/ledger/0
acceptRanges:
type: boolean
description: Flag indicating if the server accepts byte ranges with `Range` header.
contentType:
type: string
description: The content type of source.
enum: ["application/vnd.bytecodealliance.registry.ledger.packed"]
example: "application/vnd.bytecodealliance.registry.ledger.packed"
enum: ["application/vnd.warg.ledger.packed"]
example: "application/vnd.warg.ledger.packed"
acceptRanges:
type: boolean
description: Flag indicating if the server accepts byte ranges with `Range` header.
CheckpointNotFoundError:
type: object
additionalProperties: false
Expand Down

0 comments on commit 64078b3

Please sign in to comment.