···
-
use crate::{CachedRecord, Repo, error::ServerError};
use tokio_util::sync::CancellationToken;
···
message: "This record was deleted".to_string(),
fn bad_request_handler(err: poem::Error) -> GetRecordResponse {
···
/// also list `InvalidRequest`, `ExpiredToken`, and `InvalidToken`. Of
/// these, slingshot will only return `RecordNotFound` or `InvalidRequest`.
-
BadRequest(Json<XrpcErrorResponseObject>),
cache: HybridCache<String, CachedRecord>,
···
Query(cid): Query<Option<String>>,
-
let at_uri = format!("at://{repo}/{collection}/{rkey}");
···
let repo_api = self.repo.clone();
-
.get_record(repo, collection, rkey, cid)
.map_err(|e| foyer::Error::Other(Box::new(e)))
···
CachedRecord::Found(ref raw) => {
let (found_cid, raw_value) = raw.into();
-
let found_cid = found_cid.as_ref().to_string();
if cid.clone().map(|c| c != found_cid).unwrap_or(false) {
return GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject {
error: "RecordNotFound".to_string(),
···
serde_json::from_str(raw_value.get()).expect("RawValue to be valid json");
GetRecordResponse::Ok(Json(FoundRecordResponseObject {
···
cache: HybridCache<String, CachedRecord>,
_shutdown: CancellationToken,
) -> Result<(), ServerError> {
let repo = Arc::new(repo);
-
OpenApiService::new(Xrpc { cache, repo }, "Slingshot", env!("CARGO_PKG_VERSION"))
-
.server("http://localhost:3000")
let mut app = Route::new()
.nest("/", api_service.scalar())
···
.expect("alskfjalksdjf");
-
.at("/.well-known/did.json", get_did_doc(&host));
let auto_cert = AutoCert::builder()
.directory_url(LETS_ENCRYPT_PRODUCTION)
···
async fn run<L>(listener: L, app: Route) -> Result<(), ServerError>
-
.allow_method(Method::GET)
-
.allow_credentials(false))
···
+
use crate::{CachedRecord, Identity, Repo, error::ServerError};
+
use atrium_api::types::string::{Cid, Did, Handle, Nsid, RecordKey};
use tokio_util::sync::CancellationToken;
···
message: "This record was deleted".to_string(),
+
type XrpcError = Json<XrpcErrorResponseObject>;
+
fn xrpc_error(error: impl AsRef<str>, message: impl AsRef<str>) -> XrpcError {
+
Json(XrpcErrorResponseObject {
+
error: error.as_ref().to_string(),
+
message: message.as_ref().to_string(),
fn bad_request_handler(err: poem::Error) -> GetRecordResponse {
···
/// also list `InvalidRequest`, `ExpiredToken`, and `InvalidToken`. Of
/// these, slingshot will only return `RecordNotFound` or `InvalidRequest`.
+
/// Just using 500 for potentially upstream errors for now
+
ServerError(XrpcError),
cache: HybridCache<String, CachedRecord>,
···
Query(cid): Query<Option<String>>,
+
let did = match Did::new(repo.clone()) {
+
let Ok(handle) = Handle::new(repo) else {
+
return GetRecordResponse::BadRequest(xrpc_error(
+
"repo was not a valid DID or handle",
+
if let Ok(res) = self.identity.handle_to_did(handle).await {
+
if let Some(did) = res {
+
return GetRecordResponse::BadRequest(xrpc_error(
+
"Could not resolve handle repo to a DID",
+
return GetRecordResponse::ServerError(xrpc_error(
+
"errored while trying to resolve handle to DID",
+
let Ok(collection) = Nsid::new(collection) else {
+
return GetRecordResponse::BadRequest(xrpc_error(
+
"invalid NSID for collection",
+
let Ok(rkey) = RecordKey::new(rkey) else {
+
return GetRecordResponse::BadRequest(xrpc_error("InvalidRequest", "invalid rkey"));
+
let cid: Option<Cid> = if let Some(cid) = cid {
+
let Ok(cid) = Cid::from_str(&cid) else {
+
return GetRecordResponse::BadRequest(xrpc_error("InvalidRequest", "invalid CID"));
+
let at_uri = format!("at://{}/{}/{}", &*did, &*collection, &*rkey);
···
let repo_api = self.repo.clone();
+
.get_record(&did, &collection, &rkey, &cid)
.map_err(|e| foyer::Error::Other(Box::new(e)))
···
CachedRecord::Found(ref raw) => {
let (found_cid, raw_value) = raw.into();
if cid.clone().map(|c| c != found_cid).unwrap_or(false) {
return GetRecordResponse::BadRequest(Json(XrpcErrorResponseObject {
error: "RecordNotFound".to_string(),
···
serde_json::from_str(raw_value.get()).expect("RawValue to be valid json");
GetRecordResponse::Ok(Json(FoundRecordResponseObject {
+
cid: Some(found_cid.as_ref().to_string()),
···
cache: HybridCache<String, CachedRecord>,
_shutdown: CancellationToken,
) -> Result<(), ServerError> {
let repo = Arc::new(repo);
+
let api_service = OpenApiService::new(
+
env!("CARGO_PKG_VERSION"),
+
.server("http://localhost:3000")
let mut app = Route::new()
.nest("/", api_service.scalar())
···
.expect("alskfjalksdjf");
+
app = app.at("/.well-known/did.json", get_did_doc(&host));
let auto_cert = AutoCert::builder()
.directory_url(LETS_ENCRYPT_PRODUCTION)
···
async fn run<L>(listener: L, app: Route) -> Result<(), ServerError>
+
.allow_methods([Method::GET])
+
.allow_credentials(false),