oxen-server 0.60.0

Oxen server is a fast data version control backend, supporting local disk and S3. Self host your repositories on your own storage, or use the hosted platform on Oxen.ai. Stores, syncs, and serves versioned datasets, model checkpoints, game assets, studio media, and any large data. Use the oxen CLI to push and pull from the oxen server.
use crate::errors::OxenHttpError;
use crate::helpers::get_repo;
use crate::params::{app_data, path_param};
use actix_web::{HttpRequest, HttpResponse};
use liboxen::repositories;
use liboxen::view::http::STATUS_SUCCESS;
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
struct ActionResponse {
    action: String,
    status: String,
    state: String,
}

impl ActionResponse {
    fn new(action: &str, state: &str) -> Self {
        ActionResponse {
            action: action.to_string(),
            status: STATUS_SUCCESS.to_string(),
            state: state.to_string(),
        }
    }
}

pub async fn completed(req: HttpRequest) -> actix_web::Result<HttpResponse, OxenHttpError> {
    let action = path_param(&req, "action")?;
    log::debug!("{action} action completed");
    Ok(HttpResponse::Ok().json(ActionResponse::new(action, "completed")))
}

/// Record that a push finished, and start a recalculation of the repository's size. A repository
/// held for maintenance reports 429 with a `Retry-After` instead of a completed push.
pub async fn completed_push(req: HttpRequest) -> actix_web::Result<HttpResponse, OxenHttpError> {
    let app_data = app_data(&req)?;
    let namespace = path_param(&req, "namespace")?.to_string();
    let name = path_param(&req, "repo_name")?.to_string();
    let repository = get_repo(app_data, &namespace, &name)?;

    log::debug!("push action completed");
    repositories::size::update_size(&repository)?;

    Ok(HttpResponse::Ok().json(ActionResponse::new("push", "completed")))
}

pub async fn started(req: HttpRequest) -> actix_web::Result<HttpResponse, OxenHttpError> {
    let action = path_param(&req, "action")?;
    Ok(HttpResponse::Ok().json(ActionResponse::new(action, "started")))
}