(refs #1439)Fix pattern matching for assemble GitLFS URL

This commit is contained in:
Naoki Takezoe
2017-02-01 08:03:02 +09:00
parent 5a510d5703
commit fd8add4fcd
2 changed files with 38 additions and 40 deletions

View File

@@ -64,11 +64,10 @@ class GitLfsTransferServlet extends HttpServlet {
}
private def getPathInfo(req: HttpServletRequest, res: HttpServletResponse): Option[(String, String, String)] = {
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))
req.getRequestURI.substring(1).split("/").reverse match {
case Array(oid, repository, owner, _*) => Some((owner, repository, oid))
case _ => None
}
}
private def sendError(res: HttpServletResponse, status: Int, message: String): Unit = {

View File

@@ -76,42 +76,41 @@ class GitRepositoryServlet extends GitServlet with SystemSettingsService {
case Some(baseUrl) => {
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
req.getRequestURI.substring(0, index).split("/").reverse match {
case Array(repository, owner, _*) =>
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.
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()
res.setContentType("application/vnd.git-lfs+json")
using(res.getWriter){ out =>
out.print(write(batchResponse))
out.flush()
}
}
}
}