diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index f11ecec..8e4e3d5 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -831,55 +831,15 @@ redirect(s"${repository.owner}/${repository.name}/releases") }) - /** - * Download repository contents as a zip archive as compatible URL. - */ - get("/:owner/:repository/archive/:branch.zip")(referrersOnly { repository => - val branch = params("branch") - 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.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.xz", repository, "") - }) - - /** - * Download all repository contents as an archive. - */ - get("/:owner/:repository/archive/:branch/:name")(referrersOnly { repository => - val branch = params("branch") + get("/:owner/:repository/archive/:name")(referrersOnly { repository => val name = params("name") - archiveRepository(branch, name, repository, "") + archiveRepository(name, repository, "") }) - /** - * Download repositories subtree contents as an archive. - */ - get("/:owner/:repository/archive/:branch/*/:name")(referrersOnly { repository => - val branch = params("branch") + get("/:owner/:repository/archive/*/:name")(referrersOnly { repository => val name = params("name") val path = multiParams("splat").head - archiveRepository(branch, name, repository, path) + archiveRepository(name, repository, path) }) get("/:owner/:repository/network/members")(referrersOnly { repository => @@ -1175,12 +1135,11 @@ } private def archiveRepository( - revision: String, filename: String, repository: RepositoryService.RepositoryInfo, path: String ) = { - def archive(archiveFormat: String, archive: ArchiveOutputStream)( + def archive(revision: String, archiveFormat: String, archive: ArchiveOutputStream)( entryCreator: (String, Long, Int) => ArchiveEntry ): Unit = { using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git => @@ -1222,15 +1181,15 @@ val tarRe = """(.+)\.tar\.(gz|bz2|xz)$""".r filename match { - case zipRe(branch) => + case zipRe(revision) => response.setHeader( "Content-Disposition", - s"attachment; filename=${repository.name}-${branch}${suffix}.zip" + s"attachment; filename=${repository.name}-${revision}${suffix}.zip" ) contentType = "application/octet-stream" response.setBufferSize(1024 * 1024) using(new ZipArchiveOutputStream(response.getOutputStream)) { zip => - archive(".zip", zip) { (path, size, mode) => + archive(revision, ".zip", zip) { (path, size, mode) => val entry = new ZipArchiveEntry(path) entry.setSize(size) entry.setUnixMode(mode) @@ -1238,10 +1197,10 @@ } } () - case tarRe(branch, compressor) => + case tarRe(revision, compressor) => response.setHeader( "Content-Disposition", - s"attachment; filename=${repository.name}-${branch}${suffix}.tar.${compressor}" + s"attachment; filename=${repository.name}-${revision}${suffix}.tar.${compressor}" ) contentType = "application/octet-stream" response.setBufferSize(1024 * 1024) @@ -1254,7 +1213,7 @@ tar.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR) tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU) tar.setAddPaxHeadersForNonAsciiNames(true) - archive(".tar.gz", tar) { (path, size, mode) => + archive(revision, ".tar.gz", tar) { (path, size, mode) => val entry = new TarArchiveEntry(path) entry.setSize(size) entry.setMode(mode) @@ -1264,7 +1223,7 @@ } () case _ => - BadRequest() + NotFound() } } diff --git a/src/main/scala/gitbucket/core/plugin/PluginRepository.scala b/src/main/scala/gitbucket/core/plugin/PluginRepository.scala index c1e4b48..3aac3e8 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRepository.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRepository.scala @@ -6,9 +6,12 @@ import gitbucket.core.controller.Context import org.json4s._ import org.apache.commons.io.IOUtils + import java.net.Authenticator +import org.slf4j.LoggerFactory object PluginRepository { + private val logger = LoggerFactory.getLogger(getClass) implicit val formats = DefaultFormats def parsePluginJson(json: String): Seq[PluginMetadata] = { @@ -16,29 +19,33 @@ } def getPlugins()(implicit context: Context): Seq[PluginMetadata] = { - val url = new java.net.URL("https://plugins.gitbucket-community.org/releases/plugins.json") - - val in = context.settings.proxy match { - case Some(proxy) => - (proxy.user, proxy.password) match { - case (Some(user), Some(password)) => - Authenticator.setDefault(new Authenticator() { - override def getPasswordAuthentication = new PasswordAuthentication(user, password.toCharArray) - }) - case _ => - Authenticator.setDefault(null) - } - - url - .openConnection(new JProxy(JProxy.Type.HTTP, new InetSocketAddress(proxy.host, proxy.port))) - .getInputStream - case None => url.openStream() + try { + val url = new java.net.URL("https://plugins.gitbucket-community.org/releases/plugins.json") + val in = context.settings.proxy match { + case Some(proxy) => + (proxy.user, proxy.password) match { + case (Some(user), Some(password)) => + Authenticator.setDefault(new Authenticator() { + override def getPasswordAuthentication = new PasswordAuthentication(user, password.toCharArray) + }) + case _ => + Authenticator.setDefault(null) + } + + url + .openConnection(new JProxy(JProxy.Type.HTTP, new InetSocketAddress(proxy.host, proxy.port))) + .getInputStream + + case None => url.openStream() + } + val str = IOUtils.toString(in, "UTF-8") + parsePluginJson(str) + } catch { + case t: Throwable => + logger.warn("Failed to access to the plugin repository: " + t.toString) + Nil } - - val str = IOUtils.toString(in, "UTF-8") - parsePluginJson(str) } - } // Mapped from plugins.json diff --git a/src/main/twirl/gitbucket/core/repo/files.scala.html b/src/main/twirl/gitbucket/core/repo/files.scala.html index 877411f..5059b69 100644 --- a/src/main/twirl/gitbucket/core/repo/files.scala.html +++ b/src/main/twirl/gitbucket/core/repo/files.scala.html @@ -33,7 +33,7 @@