diff --git a/ceres/src/lfs/handler.rs b/ceres/src/lfs/handler.rs index 5f127c4de..891a52fdb 100644 --- a/ceres/src/lfs/handler.rs +++ b/ceres/src/lfs/handler.rs @@ -12,11 +12,13 @@ use bytes::Bytes; use callisto::{lfs_locks, lfs_objects, lfs_split_relations}; use chrono::{prelude::*, Duration}; use common::errors::{GitLFSError, MegaError}; +use futures::Stream; use jupiter::context::Context; use jupiter::storage::lfs_db_storage::LfsDbStorage; use rand::prelude::*; use sea_orm::ActiveValue::Set; use sea_orm::{DatabaseTransaction, EntityTrait, IntoActiveModel, TransactionTrait}; +use tokio_stream::wrappers::ReceiverStream; pub async fn lfs_retrieve_lock( storage: LfsDbStorage, @@ -355,14 +357,15 @@ pub async fn lfs_upload_object( /// Download object from storage. /// 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, oid: &String) -> Result { +pub async fn lfs_download_object( + context: Context, + oid: &String, +) -> Result>, GitLFSError> { let config = context.config.lfs; let stg = context.services.lfs_db_storage.clone(); let lfs_storage = context.services.lfs_storage.clone(); if config.enable_split { let meta = lfs_get_meta(stg.clone(), oid).await; - // let relation_db = context.services.lfs_storage.clone(); - match meta { Ok(meta) => { // client didn't support split, splice the object and return it. @@ -372,14 +375,29 @@ pub async fn lfs_download_object(context: Context, oid: &String) -> Result { // check if the oid is a part of a split object, if so, return the part. @@ -390,13 +408,18 @@ pub async fn lfs_download_object(context: Context, oid: &String) -> Result, Path(oid): Path, ) -> Result { - // Load request parameters into struct. let result = handler::lfs_download_object(state.context.clone(), &oid).await; match result { - Ok(bytes) => Ok(Response::builder().body(Body::from(bytes)).unwrap()), + Ok(byte_stream) => Ok(Response::builder() + .header("Content-Type", LFS_CONTENT_TYPE) + .body(Body::from_stream(byte_stream)) + .unwrap()), Err(err) => Ok({ Response::builder() .status(StatusCode::INTERNAL_SERVER_ERROR)