(refs #2048)Fix archive downloading

This commit is contained in:
Naoki Takezoe
2018-06-05 11:58:05 +09:00
parent 7a795525ed
commit c3eb30c01d

View File

@@ -822,12 +822,43 @@ trait RepositoryViewerControllerBase extends ControllerBase {
})
/**
* Download repository contents as an archive as compatible URL.
* Download repository contents as a zip archive as compatible URL.
*/
get("/:owner/:repository/archive/:branch.:suffix")(referrersOnly { repository =>
get("/:owner/:repository/archive/:branch.zip")(referrersOnly { repository =>
val branch = params("branch")
val suffix = params("suffix")
archiveRepository(branch, branch + "." + suffix, repository, "")
archiveRepository(branch, branch + ".zip", repository, "")
})
/**
* Download repository contents as a tar.gz archive as compatible URL.
*/
get("/:owner/:repository/archive/:branch.tar.gz")(referrersOnly { repository =>
val branch = params("branch")
archiveRepository(branch, branch + ".tar.gz", repository, "")
})
/**
* Download repository contents as a tar.gz archive as compatible URL.
*/
get("/:owner/:repository/archive/:branch.tar.gz")(referrersOnly { repository =>
val branch = params("branch")
archiveRepository(branch, branch + ".tar.gz", repository, "")
})
/**
* Download repository contents as a tar.bz2 archive as compatible URL.
*/
get("/:owner/:repository/archive/:branch.tar.bz2")(referrersOnly { repository =>
val branch = params("branch")
archiveRepository(branch, branch + ".tar.bz2", repository, "")
})
/**
* Download repository contents as a tar.xz archive as compatible URL.
*/
get("/:owner/:repository/archive/:branch.tar.xz")(referrersOnly { repository =>
val branch = params("branch")
archiveRepository(branch, branch + ".tar.bz2", repository, "")
})
/**
@@ -1134,7 +1165,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
}
}
def archiveRepository(
private def archiveRepository(
revision: String,
filename: String,
repository: RepositoryService.RepositoryInfo,
@@ -1176,7 +1207,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
}
}
val suffix = path.split("/").lastOption.map("-" + _).getOrElse("")
val suffix =
path.split("/").lastOption.collect { case x if x.length > 0 => "-" + x.replace('/', '_') }.getOrElse("")
val zipRe = """(.+)\.zip$""".r
val tarRe = """(.+)\.tar\.(gz|bz2|xz)$""".r