mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-15 18:05:50 +01:00
(refs #1439)Fix pattern matching for assemble GitLFS URL
This commit is contained in:
@@ -64,11 +64,10 @@ class GitLfsTransferServlet extends HttpServlet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def getPathInfo(req: HttpServletRequest, res: HttpServletResponse): Option[(String, String, String)] = {
|
private def getPathInfo(req: HttpServletRequest, res: HttpServletResponse): Option[(String, String, String)] = {
|
||||||
val paths = req.getRequestURI.substring(1).split("/")
|
req.getRequestURI.substring(1).split("/").reverse match {
|
||||||
val owner = paths.dropRight(2).last
|
case Array(oid, repository, owner, _*) => Some((owner, repository, oid))
|
||||||
val repository = paths.dropRight(1).last
|
case _ => None
|
||||||
val oid = paths.last
|
}
|
||||||
Some((owner, repository, oid))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private def sendError(res: HttpServletResponse, status: Int, message: String): Unit = {
|
private def sendError(res: HttpServletResponse, status: Int, message: String): Unit = {
|
||||||
|
|||||||
@@ -76,42 +76,41 @@ class GitRepositoryServlet extends GitServlet with SystemSettingsService {
|
|||||||
case Some(baseUrl) => {
|
case Some(baseUrl) => {
|
||||||
val index = req.getRequestURI.indexOf(".git")
|
val index = req.getRequestURI.indexOf(".git")
|
||||||
if(index >= 0){
|
if(index >= 0){
|
||||||
val paths = req.getRequestURI.substring(0, index).split("/")
|
req.getRequestURI.substring(0, index).split("/").reverse match {
|
||||||
val owner = paths.dropRight(1).last
|
case Array(repository, owner, _*) =>
|
||||||
val repository = paths.last
|
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 timeout = System.currentTimeMillis + (60000 * 10) // 10 min.
|
res.setContentType("application/vnd.git-lfs+json")
|
||||||
val batchResponse = batchRequest.operation match {
|
using(res.getWriter){ out =>
|
||||||
case "upload" =>
|
out.print(write(batchResponse))
|
||||||
GitLfs.BatchUploadResponse("basic", batchRequest.objects.map { requestObject =>
|
out.flush()
|
||||||
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()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user