diff --git a/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala b/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala index 4c31884..610a19b 100644 --- a/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitLfsTransferServlet.scala @@ -64,10 +64,11 @@ } private def getPathInfo(req: HttpServletRequest, res: HttpServletResponse): Option[(String, String, String)] = { - req.getRequestURI.substring(1).split("/") match { - case Array(_, owner, repository, oid) => Some((owner, repository, oid)) - case _ => None - } + val paths = req.getRequestURI.substring(1).split("/") + val owner = paths.dropRight(2).last + val repository = paths.dropRight(1).last + val oid = paths.last + Some((owner, repository, oid)) } private def sendError(res: HttpServletResponse, status: Int, message: String): Unit = { diff --git a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala index 5ca72be..1910025 100644 --- a/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala +++ b/src/main/scala/gitbucket/core/servlet/GitRepositoryServlet.scala @@ -74,41 +74,44 @@ throw new IllegalStateException("lfs.server_url is not configured.") } case Some(baseUrl) => { - req.getRequestURI.substring(1).replace(".git/", "/").split("/") match { - case Array(_, owner, repository, _*) => { - val timeout = System.currentTimeMillis + (60000 * 10) // 10 min. - val batchResponse = batchRequest.operation match { - case "upload" => - GitLfs.BatchUploadResponse("basic", batchRequest.objects.map { requestObject => - GitLfs.BatchResponseObject(requestObject.oid, requestObject.size, true, - GitLfs.Actions( - upload = Some(GitLfs.Action( - href = baseUrl + "/git-lfs/" + owner + "/" + repository + "/" + requestObject.oid, - header = Map("Authorization" -> StringUtil.encodeBlowfish(timeout + " " + requestObject.oid)), - expires_at = new Date(timeout) - )) - ) - ) - }) - case "download" => - GitLfs.BatchUploadResponse("basic", batchRequest.objects.map { requestObject => - GitLfs.BatchResponseObject(requestObject.oid, requestObject.size, true, - GitLfs.Actions( - download = Some(GitLfs.Action( - href = baseUrl + "/git-lfs/" + owner + "/" + repository + "/" + requestObject.oid, - header = Map("Authorization" -> StringUtil.encodeBlowfish(timeout + " " + requestObject.oid)), - expires_at = new Date(timeout) - )) - ) - ) - }) - } + val index = req.getRequestURI.indexOf(".git") + if(index >= 0){ + val paths = req.getRequestURI.substring(0, index).split("/") + val owner = paths.dropRight(1).last + val repository = paths.last - res.setContentType("application/vnd.git-lfs+json") - using(res.getWriter){ out => - out.print(write(batchResponse)) - out.flush() - } + val timeout = System.currentTimeMillis + (60000 * 10) // 10 min. + val batchResponse = batchRequest.operation match { + case "upload" => + GitLfs.BatchUploadResponse("basic", batchRequest.objects.map { requestObject => + GitLfs.BatchResponseObject(requestObject.oid, requestObject.size, true, + GitLfs.Actions( + upload = Some(GitLfs.Action( + href = baseUrl + "/git-lfs/" + owner + "/" + repository + "/" + requestObject.oid, + header = Map("Authorization" -> StringUtil.encodeBlowfish(timeout + " " + requestObject.oid)), + expires_at = new Date(timeout) + )) + ) + ) + }) + case "download" => + GitLfs.BatchUploadResponse("basic", batchRequest.objects.map { requestObject => + GitLfs.BatchResponseObject(requestObject.oid, requestObject.size, true, + GitLfs.Actions( + download = Some(GitLfs.Action( + href = baseUrl + "/git-lfs/" + owner + "/" + repository + "/" + requestObject.oid, + header = Map("Authorization" -> StringUtil.encodeBlowfish(timeout + " " + requestObject.oid)), + expires_at = new Date(timeout) + )) + ) + ) + }) + } + + res.setContentType("application/vnd.git-lfs+json") + using(res.getWriter){ out => + out.print(write(batchResponse)) + out.flush() } } }