mirror of
https://tangled.org/tranquil.farm/tranquil-pds
synced 2026-08-01 06:56:05 +00:00
sync: parse xrpc query params into real types
Lewis: May this revision serve well! <lu5a@proton.me>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use axum::{
|
||||
Json,
|
||||
body::Body,
|
||||
extract::{Query, State},
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
http::header,
|
||||
response::{IntoResponse, Response},
|
||||
@@ -9,6 +9,7 @@ use axum::{
|
||||
use serde::{Deserialize, Serialize};
|
||||
use tracing::error;
|
||||
use tranquil_pds::api::error::ApiError;
|
||||
use tranquil_pds::api::query::XrpcQuery;
|
||||
use tranquil_pds::state::AppState;
|
||||
use tranquil_pds::sync::util::{RepoAccessLevel, assert_repo_availability};
|
||||
use tranquil_types::{CidLink, Did, Tid};
|
||||
@@ -21,7 +22,7 @@ pub struct GetBlobParams {
|
||||
|
||||
pub async fn get_blob(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<GetBlobParams>,
|
||||
XrpcQuery(params): XrpcQuery<GetBlobParams>,
|
||||
) -> Response {
|
||||
let did = params.did;
|
||||
let cid = params.cid;
|
||||
@@ -61,7 +62,7 @@ pub async fn get_blob(
|
||||
#[derive(Deserialize)]
|
||||
pub struct ListBlobsParams {
|
||||
pub did: Did,
|
||||
pub since: Option<String>,
|
||||
pub since: Option<Tid>,
|
||||
pub limit: Option<i64>,
|
||||
pub cursor: Option<String>,
|
||||
}
|
||||
@@ -75,7 +76,7 @@ pub struct ListBlobsOutput {
|
||||
|
||||
pub async fn list_blobs(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<ListBlobsParams>,
|
||||
XrpcQuery(params): XrpcQuery<ListBlobsParams>,
|
||||
) -> Response {
|
||||
let did = params.did;
|
||||
|
||||
@@ -95,7 +96,7 @@ pub async fn list_blobs(
|
||||
state
|
||||
.repos
|
||||
.blob
|
||||
.list_blobs_since_rev(&did, &Tid::from(since.clone()))
|
||||
.list_blobs_since_rev(&did, since)
|
||||
.await
|
||||
.map(|cids| {
|
||||
let mut cids = cids;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use axum::{
|
||||
Json,
|
||||
extract::{Query, State},
|
||||
extract::State,
|
||||
http::StatusCode,
|
||||
response::{IntoResponse, Response},
|
||||
};
|
||||
@@ -12,6 +12,7 @@ use std::str::FromStr;
|
||||
use tracing::error;
|
||||
use tranquil_db_traits::AccountStatus;
|
||||
use tranquil_pds::api::error::ApiError;
|
||||
use tranquil_pds::api::query::XrpcQuery;
|
||||
use tranquil_pds::state::AppState;
|
||||
use tranquil_pds::sync::util::{
|
||||
RepoAccessLevel, assert_repo_availability, get_account_with_status,
|
||||
@@ -22,7 +23,7 @@ async fn get_rev_from_commit(state: &AppState, cid_str: &str) -> Option<Tid> {
|
||||
let cid = Cid::from_str(cid_str).ok()?;
|
||||
let block = state.block_store.get(&cid).await.ok()??;
|
||||
let commit = Commit::from_cbor(&block).ok()?;
|
||||
Some(Tid::from(commit.rev().to_string()))
|
||||
Some(Tid::from(commit.rev().clone()))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
@@ -38,7 +39,7 @@ pub struct GetLatestCommitOutput {
|
||||
|
||||
pub async fn get_latest_commit(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<GetLatestCommitParams>,
|
||||
XrpcQuery(params): XrpcQuery<GetLatestCommitParams>,
|
||||
) -> Response {
|
||||
let did = params.did;
|
||||
|
||||
@@ -98,7 +99,7 @@ pub struct ListReposOutput {
|
||||
|
||||
pub async fn list_repos(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<ListReposParams>,
|
||||
XrpcQuery(params): XrpcQuery<ListReposParams>,
|
||||
) -> Response {
|
||||
let limit = params.limit.unwrap_or(50).clamp(1, 1000);
|
||||
let cursor_did: Option<Did> = params.cursor.as_ref().and_then(|s| s.parse().ok());
|
||||
@@ -173,7 +174,7 @@ pub struct GetRepoStatusOutput {
|
||||
|
||||
pub async fn get_repo_status(
|
||||
State(state): State<AppState>,
|
||||
Query(params): Query<GetRepoStatusParams>,
|
||||
XrpcQuery(params): XrpcQuery<GetRepoStatusParams>,
|
||||
) -> Response {
|
||||
let did = params.did;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user