Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update api #182

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions atrium-api/src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ where
}
}
}
/// Set the current endpoint.
pub fn configure_endpoint(&self, endpoint: String) {
self.inner.configure_endpoint(endpoint);
}
/// Configures the moderation services to be applied on requests.
pub fn configure_labelers_header(&self, labeler_dids: Option<Vec<Did>>) {
pub fn configure_labelers_header(&self, labeler_dids: Option<Vec<(Did, bool)>>) {
self.inner.configure_labelers_header(labeler_dids);
}
/// Configures the atproto-proxy header to be applied on requests.
Expand Down Expand Up @@ -621,9 +625,10 @@ mod tests {
.expect("describe_server should be succeeded");
assert_eq!(headers.read().await.last(), Some(&HeaderMap::new()));

agent.configure_labelers_header(Some(vec!["did:plc:test1"
.parse()
.expect("did should be valid")]));
agent.configure_labelers_header(Some(vec![(
"did:plc:test1".parse().expect("did should be valid"),
false,
)]));
agent
.api
.com
Expand All @@ -641,8 +646,8 @@ mod tests {
);

agent.configure_labelers_header(Some(vec![
"did:plc:test1".parse().expect("did should be valid"),
"did:plc:test2".parse().expect("did should be valid"),
("did:plc:test1".parse().expect("did should be valid"), true),
("did:plc:test2".parse().expect("did should be valid"), false),
]));
agent
.api
Expand All @@ -656,14 +661,14 @@ mod tests {
headers.read().await.last(),
Some(&HeaderMap::from_iter([(
HeaderName::from_static("atproto-accept-labelers"),
HeaderValue::from_static("did:plc:test1, did:plc:test2"),
HeaderValue::from_static("did:plc:test1;redact, did:plc:test2"),
)]))
);

assert_eq!(
agent.get_labelers_header().await,
Some(vec![
String::from("did:plc:test1"),
String::from("did:plc:test1;redact"),
String::from("did:plc:test2")
])
);
Expand Down
24 changes: 20 additions & 4 deletions atrium-api/src/agent/inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,21 @@ impl<S, T> WrapperClient<S, T> {
.expect("failed to write proxy header")
.replace(value);
}
fn configure_labelers_header(&self, labelers_dids: Option<Vec<Did>>) {
fn configure_labelers_header(&self, labelers_dids: Option<Vec<(Did, bool)>>) {
*self
.labelers_header
.write()
.expect("failed to write labelers header") =
labelers_dids.map(|dids| dids.iter().map(|did| did.as_ref().into()).collect())
.expect("failed to write labelers header") = labelers_dids.map(|dids| {
dids.iter()
.map(|(did, redact)| {
if *redact {
format!("{};redact", did.as_ref())
} else {
did.as_ref().into()
}
})
.collect()
})
}
}

Expand Down Expand Up @@ -123,6 +132,13 @@ where
notify: Arc::new(Notify::new()),
}
}
pub fn configure_endpoint(&self, endpoint: String) {
*self
.store
.endpoint
.write()
.expect("failed to write endpoint") = endpoint;
}
pub fn configure_proxy_header(&self, did: Did, service_type: impl AsRef<str>) {
self.inner
.configure_proxy_header(format!("{}#{}", did.as_ref(), service_type.as_ref()));
Expand All @@ -134,7 +150,7 @@ where
.configure_proxy_header(format!("{}#{}", did.as_ref(), service_type.as_ref()));
cloned
}
pub fn configure_labelers_header(&self, labeler_dids: Option<Vec<Did>>) {
pub fn configure_labelers_header(&self, labeler_dids: Option<Vec<(Did, bool)>>) {
self.inner.configure_labelers_header(labeler_dids);
}
pub async fn get_labelers_header(&self) -> Option<Vec<String>> {
Expand Down
4 changes: 2 additions & 2 deletions atrium-api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ pub enum Union<T> {
#[derive(serde::Serialize, serde::Deserialize, Debug, Clone, PartialEq)]
pub struct UnknownData {
#[serde(rename = "$type")]
r#type: String,
pub r#type: String,
#[serde(flatten)]
data: Ipld,
pub data: Ipld,
}

impl Eq for UnknownData {}
Expand Down
Loading