Search in sources :

Example 1 with ArchiveElement

use of jetbrains.buildServer.server.rest.data.ArchiveElement in project teamcity-rest by JetBrains.

the class FilesSubResource method getZipped.

@GET
@Path("/archived" + "{path:(/.*)?}")
@Produces({ MediaType.WILDCARD })
@ApiOperation(value = "Get specific file zipped.", nickname = "getZippedFile")
public Response getZipped(@PathParam("path") final String path, @QueryParam("basePath") final String basePath, @QueryParam("locator") final String locator, @QueryParam("name") final String name, @Context HttpServletRequest request) {
    final String processedPath = myProvider.preprocess(StringUtil.removeLeadingSlash(path));
    String actualBasePath = basePath != null ? myProvider.preprocess(basePath) : processedPath;
    String finalName = myProvider.preprocess(name);
    if (StringUtil.isEmpty(finalName)) {
        finalName = myProvider.getArchiveName(processedPath) + ".zip";
    }
    // include al files recursively by default
    String actualLocator = Locator.setDimensionIfNotPresent(locator, BuildArtifactsFinder.DIMENSION_RECURSIVE, "true");
    // do not expand archives by default
    actualLocator = Locator.setDimensionIfNotPresent(actualLocator, BuildArtifactsFinder.ARCHIVES_DIMENSION_NAME, "false");
    final FileApiUrlBuilder urlBuilder = fileApiUrlBuilder(locator, myUrlPrefix);
    final List<ArtifactTreeElement> elements = BuildArtifactsFinder.getItems(myProvider.getElement(processedPath), actualBasePath, actualLocator, urlBuilder, myBeanContext.getServiceLocator());
    final ArchiveElement archiveElement = new ArchiveElement(elements, finalName);
    final Response.ResponseBuilder builder = getContentByStream(archiveElement, request, new StreamingOutputProvider() {

        @Override
        public boolean isRangeSupported() {
            return false;
        }

        @Override
        public StreamingOutput getStreamingOutput(@Nullable final Long startOffset, @Nullable final Long length) {
            return archiveElement.getStreamingOutput(startOffset, length, () -> "request " + WebUtil.getRequestDump(request));
        }
    });
    for (ArtifactTreeElement element : elements) {
        if (!myProvider.fileContentServed(Util.concatenatePath(actualBasePath, element.getFullName()), request))
            break;
    }
    // see jetbrains.buildServer.web.util.WebUtil.addCacheHeadersForIE and http://youtrack.jetbrains.com/issue/TW-9821 for details)
    if (WebUtil.isIE10OrLower(request)) {
        builder.header("Cache-Control", "private,must-revalidate");
        builder.header("Pragma", "private");
    }
    return builder.build();
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) FileApiUrlBuilder(jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder) ArtifactTreeElement(jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement) ArchiveElement(jetbrains.buildServer.server.rest.data.ArchiveElement) ApiOperation(io.swagger.annotations.ApiOperation)

Aggregations

ApiOperation (io.swagger.annotations.ApiOperation)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 ArchiveElement (jetbrains.buildServer.server.rest.data.ArchiveElement)1 FileApiUrlBuilder (jetbrains.buildServer.server.rest.model.files.FileApiUrlBuilder)1 ArtifactTreeElement (jetbrains.buildServer.web.artifacts.browser.ArtifactTreeElement)1