Skip to content
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: 10 additions & 11 deletions ceres/src/lfs/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub async fn lfs_process_batch(
let server_url = context.config.lfs.url.clone();

for object in &batch_vars.objects {
let meta = lfs_get_meta(storage.clone(), object).await;
let meta = lfs_get_meta(storage.clone(), &object.oid).await;
// Found
let found = meta.is_ok();
let mut meta = meta.unwrap_or_default();
Expand Down Expand Up @@ -249,7 +249,7 @@ pub async fn lfs_fetch_chunk_ids(
}
let storage = context.services.lfs_storage.clone();

let meta = lfs_get_meta(storage.clone(), fetch_vars)
let meta = lfs_get_meta(storage.clone(), &fetch_vars.oid)
.await
.map_err(|_| GitLFSError::GeneralError("".to_string()))?;
assert!(meta.splited, "database didn't match the split mode");
Expand Down Expand Up @@ -301,7 +301,7 @@ pub async fn lfs_upload_object(
let lfs_storage = context.services.lfs_storage.clone();
let raw_storage = context.services.raw_storage.clone();

let meta = lfs_get_meta(lfs_storage.clone(), request_vars)
let meta = lfs_get_meta(lfs_storage.clone(), &request_vars.oid)
.await
.unwrap();
if config.enable_split && meta.splited {
Expand Down Expand Up @@ -353,13 +353,13 @@ pub async fn lfs_upload_object(
/// when server enable split, if OID is a complete object, then splice the object and return it.
pub async fn lfs_download_object(
context: Context,
request_vars: &RequestVars,
oid: &String,
) -> Result<Bytes, GitLFSError> {
let config = context.config.lfs;
let stg = context.services.lfs_storage.clone();
let raw_storage = context.services.raw_storage.clone();
if config.enable_split {
let meta = lfs_get_meta(stg.clone(), request_vars).await;
let meta = lfs_get_meta(stg.clone(), oid).await;
// let relation_db = context.services.lfs_storage.clone();

match meta {
Expand All @@ -382,19 +382,18 @@ pub async fn lfs_download_object(
}
Err(_) => {
// check if the oid is a part of a split object, if so, return the part.
let sub_oid = request_vars.oid.clone();
if !lfs_check_sub_oid_exist(stg, &sub_oid).await.unwrap() {
if !lfs_check_sub_oid_exist(stg, oid).await.unwrap() {
return Err(GitLFSError::GeneralError(
"oid didn't belong to any object".to_string(),
));
}

let bytes = raw_storage.get_object(&sub_oid).await.unwrap();
let bytes = raw_storage.get_object(oid).await.unwrap();
Ok(bytes)
}
}
} else {
let meta = lfs_get_meta(stg, request_vars).await.unwrap();
let meta = lfs_get_meta(stg, oid).await.unwrap();
let bytes = raw_storage.get_object(&meta.oid).await.unwrap();
Ok(bytes)
}
Expand Down Expand Up @@ -617,9 +616,9 @@ async fn lfs_add_lock(

async fn lfs_get_meta(
storage: Arc<LfsStorage>,
v: &RequestVars,
oid: &String,
) -> Result<MetaObject, GitLFSError> {
let result = storage.get_lfs_object(v.oid.clone()).await.unwrap();
let result = storage.get_lfs_object(oid.clone()).await.unwrap();

match result {
Some(val) => Ok(MetaObject {
Expand Down
28 changes: 4 additions & 24 deletions mono/src/api/lfs/lfs_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn routers() -> Router<MonoApiServiceState> {
.route("/locks/verify", post(list_locks_for_verification))
.route("/locks/:id/unlock", post(delete_lock))
.route("/objects/batch", post(lfs_process_batch))
.route("/objects/chunkids", get(lfs_fetch_chunk_ids))
.route("/objects/:object_id/chunks", get(lfs_fetch_chunk_ids))
}

pub async fn list_locks(
Expand All @@ -98,15 +98,8 @@ pub async fn list_locks(

pub async fn list_locks_for_verification(
state: State<MonoApiServiceState>,
// req: Request<Body>,
Json(json): Json<VerifiableLockRequest>,
) -> Result<Response<Body>, (StatusCode, String)> {
// tracing::info!("req: {:?}", req);

// let request = Json::from_request(req, &state)
// .await
// .unwrap_or_else(|_| Json(VerifiableLockRequest::default()));

let result = handler::lfs_verify_lock(state.context.services.lfs_storage.clone(), json).await;
match result {
Ok(lock_list) => {
Expand All @@ -129,10 +122,6 @@ pub async fn create_lock(
state: State<MonoApiServiceState>,
Json(json): Json<LockRequest>,
) -> Result<Response<Body>, (StatusCode, String)> {
// let request = Json::from_request(req, &state)
// .await
// .unwrap_or_else(|_| Json(LockRequest::default()));

let result = handler::lfs_create_lock(state.context.services.lfs_storage.clone(), json).await;
match result {
Ok(lock) => {
Expand Down Expand Up @@ -217,19 +206,15 @@ pub async fn lfs_process_batch(

pub async fn lfs_fetch_chunk_ids(
state: State<MonoApiServiceState>,
Path(oid): Path<String>,
Json(json): Json<RequestVars>,
) -> Result<Response<Body>, (StatusCode, String)> {
// let request = Json::from_request(req, &state).await;
// if request.is_err() {
// return Err((StatusCode::BAD_REQUEST, "Invalid request".to_string()));
// }
// let request = request.unwrap();
let result = handler::lfs_fetch_chunk_ids(&state.context, &json).await;
match result {
Ok(response) => {
let size = response.iter().fold(0, |acc, chunk| acc + chunk.size);
let fetch_response = FetchchunkResponse {
oid: json.oid.clone(),
oid,
size,
chunks: response,
};
Expand All @@ -254,12 +239,7 @@ pub async fn lfs_download_object(
Path(oid): Path<String>,
) -> Result<Response, (StatusCode, String)> {
// Load request parameters into struct.
let request_vars = RequestVars {
oid,
authorization: "".to_owned(),
..Default::default()
};
let result = handler::lfs_download_object(state.context.clone(), &request_vars).await;
let result = handler::lfs_download_object(state.context.clone(), &oid).await;
match result {
Ok(bytes) => Ok(Response::builder().body(Body::from(bytes)).unwrap()),
Err(err) => Ok({
Expand Down
2 changes: 1 addition & 1 deletion mono/src/server/https_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub async fn app(config: Config, host: String, port: u16, common: CommonOptions)
// Using Regular Expressions for Path Matching in Protocol
.route(
"/*path",
get(get_method_router).post(post_method_router), // .put(put_method_router),
get(get_method_router).post(post_method_router),
)
.layer(
ServiceBuilder::new().layer(CorsLayer::new().allow_origin(Any).allow_headers(vec![
Expand Down