Example #1
0
        } // end of function - LFSBatchPost

        /// <summary>
        /// Creates a <see cref="BatchResponseObject"/> object with information for
        /// each LFS object in the batch request
        /// </summary>
        /// <param name="repo">
        /// The local cached repository
        /// </param>
        /// <param name="reqObj">
        /// The LFS batch request object, with information requested by the client
        /// </param>
        /// <returns>
        /// Task generating a <see cref="BatchResponseObject"/>, with information to
        /// send to the client
        /// </returns>
        public BatchResponseObject CreateBatchLFSResponse(ILocalRepository repo, BatchRequestObject reqObj)
        {
            // Create our main response object
            BatchResponseObject retval = new BatchResponseObject();

            // Loop through all of the objects in the request object
            foreach (var obj in reqObj.Objects)
            {
                // We will need a list of actions to return
                LFSActions actions = new LFSActions();

                // We will use the file info object to get the file size later
                var fileInfo = new FileInfo(repo.LFSObjectPath(obj.OID));
#warning Find a way to get the controller's mapping entry point to build a base URL
                string baseUrl = $"{Request.Scheme}://{Request.Host}/{Request.PathBase}/";

                // Right now, we only support a "download" action, so build it out
                actions.Download = new LFSActions.DownloadAction()
                {
                    ExpiresAt = null,
                    ExpiresIn = 0,
                    HREF      = $"{baseUrl}/{repo.Remote.Server}/{repo.Remote.Owner}/{repo.Remote.Name}/lfs/download/{obj.OID}"
                };

                retval.Objects.Add(new BatchResponseObject.ResponseLFSItem()
                {
                    Authenticated = true,
                    OID           = obj.OID,
                    Size          = (int)fileInfo.Length,
                    Actions       = actions,
                    Error         = null
                });
            } // end of foreach - object in the LFS request objects call
            return(retval);
        }     // end of function - CreateBatchLFSResponse
Example #2
0
        public ActionResult LFSBatchPost(
            string destinationServer,
            string repositoryOwner,
            string repository,
            [FromBody] BatchRequestObject value,
            [FromHeader] string authorization)
        {
            // Create a reference to the local cached repository
            var local = GetLocalRepo(destinationServer, repositoryOwner, repository, authorization);

            // And then return a JSON result for the LFS objects requested
            return(new JsonResult(CreateBatchLFSResponse(local, value)));
        } // end of function - LFSBatchPost
Example #3
0
        public void DefaultsGetsSets()
        {
            var obj = new BatchRequestObject();

            Assert.IsNull(obj.Objects);
            Assert.IsNull(obj.Ref);
            Assert.IsNull(obj.Transfers);
            Assert.IsNull(obj.Operation);
            Assert.IsNotNull((obj.Objects = new List <Item>()));
            Assert.AreEqual("op", (obj.Operation = "op"));
            Assert.IsNotNull((obj.Transfers = new List <string>()));
            Assert.IsNotNull((obj.Ref = new BatchRequestObject.BatchRefObject()));
        } /* End of Function - DefaultsGetsSets */