mirror of
https://github.com/blacksky-algorithms/rsky.git
synced 2025-03-15 07:27:23 +00:00
Use internal tag on enum representation of Subject
This commit is contained in:
@ -95,28 +95,28 @@ pub struct AccountView {
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct StatusAttr {
|
||||
pub applied: bool,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub r#ref: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(untagged)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
#[serde(tag = "$type")]
|
||||
pub enum Subject {
|
||||
#[serde(rename = "com.atproto.admin.defs#repoRef")]
|
||||
RepoRef(RepoRef),
|
||||
#[serde(rename = "com.atproto.repo.strongRef")]
|
||||
StrongRef(StrongRef),
|
||||
#[serde(rename = "com.atproto.admin.defs#repoBlobRef")]
|
||||
RepoBlobRef(RepoBlobRef),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct RepoRef {
|
||||
#[serde(rename = "$type")]
|
||||
pub r#type: String,
|
||||
pub did: String,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, Clone)]
|
||||
pub struct RepoBlobRef {
|
||||
#[serde(rename = "$type")]
|
||||
pub r#type: String,
|
||||
pub did: String,
|
||||
pub cid: String,
|
||||
#[serde(rename = "recordUri")]
|
||||
|
@ -1,9 +1,7 @@
|
||||
use serde_json::Value;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||
pub struct StrongRef {
|
||||
#[serde(rename = "$type")]
|
||||
pub r#type: String,
|
||||
pub uri: String,
|
||||
pub cid: String,
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ pub struct AvailabilityFlags {
|
||||
pub include_deactivated: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct GetAccountAdminStatusOutput {
|
||||
pub takedown: StatusAttr,
|
||||
pub deactivated: StatusAttr,
|
||||
|
@ -38,7 +38,6 @@ async fn inner_get_subject_status(
|
||||
if let Some(takedown) = takedown {
|
||||
body = Some(GetSubjectStatusOutput {
|
||||
subject: Subject::RepoBlobRef(RepoBlobRef {
|
||||
r#type: "com.atproto.admin.defs#repoBlobRef".to_string(),
|
||||
did,
|
||||
cid: blob,
|
||||
record_uri: None,
|
||||
@ -66,7 +65,6 @@ async fn inner_get_subject_status(
|
||||
if let (Some(cid), Some(takedown)) = (cid, takedown) {
|
||||
body = Some(GetSubjectStatusOutput {
|
||||
subject: Subject::StrongRef(StrongRef {
|
||||
r#type: "com.atproto.repo.strongRef".to_string(),
|
||||
uri,
|
||||
cid: cid.to_string(),
|
||||
}),
|
||||
@ -80,7 +78,6 @@ async fn inner_get_subject_status(
|
||||
if let Some(status) = status {
|
||||
body = Some(GetSubjectStatusOutput {
|
||||
subject: Subject::RepoRef(RepoRef {
|
||||
r#type: "com.atproto.admin.defs#repoRef".to_string(),
|
||||
did,
|
||||
}),
|
||||
takedown: Some(status.takedown),
|
||||
@ -103,9 +100,9 @@ pub async fn get_subject_status(
|
||||
blob: Option<String>,
|
||||
s3_config: &State<SdkConfig>,
|
||||
_auth: Moderator,
|
||||
) -> Result<(), status::Custom<Json<InternalErrorMessageResponse>>> {
|
||||
) -> Result<Json<GetSubjectStatusOutput>, status::Custom<Json<InternalErrorMessageResponse>>> {
|
||||
match inner_get_subject_status(did, uri, blob, s3_config).await {
|
||||
Ok(_) => Ok(()),
|
||||
Ok(res) => Ok(Json(res)),
|
||||
Err(error) => {
|
||||
let internal_error = InternalErrorMessageResponse {
|
||||
code: Some(InternalErrorCode::InternalError),
|
||||
|
@ -491,6 +491,7 @@ impl<'r> FromRequest<'r> for AdminToken {
|
||||
)),
|
||||
Some(parsed) => {
|
||||
let BasicAuth { username, password } = parsed;
|
||||
|
||||
if username != "admin" || password != env::var("PDS_ADMIN_PASS").unwrap() {
|
||||
Outcome::Error((
|
||||
Status::BadRequest,
|
||||
|
Reference in New Issue
Block a user