From a1b266e0efa2b09d69740b7b41d0ba648170da81 Mon Sep 17 00:00:00 2001
From: Kai Reinhard <K.Reinhard@micromata.de>
Date: Wed, 23 Jan 2019 23:49:10 +0000
Subject: [PATCH] Options openDownloads and autoChangeDir implemented.

---
 borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java |   37 +++++++++++++++++++++----------------
 1 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java b/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
index abf41ea..90fe225 100644
--- a/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
+++ b/borgbutler-server/src/main/java/de/micromata/borgbutler/server/rest/ArchivesRest.java
@@ -34,9 +34,8 @@
     private static Logger log = LoggerFactory.getLogger(ArchivesRest.class);
 
     /**
-     *
-     * @param repoName Name of repository ({@link Repository#getName()}.
-     * @param archiveId Id or name of archive.
+     * @param repoName      Name of repository ({@link Repository#getName()}.
+     * @param archiveId     Id or name of archive.
      * @param prettyPrinter If true then the json output will be in pretty format.
      * @return Repository (including list of archives) as json string.
      * @see JsonUtils#toJson(Object, boolean)
@@ -54,15 +53,15 @@
     }
 
     /**
-     *
-     * @param archiveId Id or name of archive.
-     * @param searchString The string to search for (key words separated by white chars, trailing ! char represents exclude).
-     * @param mode Flat (default) or tree.
-     * @param currentDirectory The current displayed directory (only files and directories contained will be returned).
-     * @param maxResultSize maximum number of file items to return (default is 50).
-     * @param diffArchiveId If given, the differences between archiveId and diffArchiveId will be returned.
-     * @param force If false (default), non cached file lists will not be loaded by borg.
-     * @param prettyPrinter If true then the json output will be in pretty format.
+     * @param archiveId                     Id or name of archive.
+     * @param searchString                  The string to search for (key words separated by white chars, trailing ! char represents exclude).
+     * @param mode                          Flat (default) or tree.
+     * @param currentDirectory              The current displayed directory (only files and directories contained will be returned).
+     * @param maxResultSize                 maximum number of file items to return (default is 50).
+     * @param diffArchiveId                 If given, the differences between archiveId and diffArchiveId will be returned.
+     * @param autoChangeDirectoryToLeafItem If given, this method will step automatically into single sub directories.
+     * @param force                         If false (default), non cached file lists will not be loaded by borg.
+     * @param prettyPrinter                 If true then the json output will be in pretty format.
      * @return Repository (including list of archives) as json string.
      * @see JsonUtils#toJson(Object, boolean)
      */
@@ -75,13 +74,15 @@
                                      @QueryParam("currentDirectory") String currentDirectory,
                                      @QueryParam("maxResultSize") String maxResultSize,
                                      @QueryParam("diffArchiveId") String diffArchiveId,
+                                     @QueryParam("autoChangeDirectoryToLeafItem") boolean autoChangeDirectoryToLeafItem,
                                      @QueryParam("force") boolean force,
                                      @QueryParam("prettyPrinter") boolean prettyPrinter) {
         boolean diffMode = StringUtils.isNotBlank(diffArchiveId);
         int maxSize = NumberUtils.toInt(maxResultSize, 50);
         FileSystemFilter filter = diffMode ? new DiffFileSystemFilter() : new FileSystemFilter();
         filter.setSearchString(searchString)
-                .setCurrentDirectory(currentDirectory);
+                .setCurrentDirectory(currentDirectory)
+                .setAutoChangeDirectoryToLeafItem(autoChangeDirectoryToLeafItem);
         List<BorgFilesystemItem> items = null;
         if (diffMode) {
             filter.setMode(FileSystemFilter.Mode.FLAT);
@@ -107,12 +108,15 @@
 
     /**
      * @param archiveId
-     * @param fileNumber The fileNumber of the file or directory in the archive served by BorgButler's
+     * @param openDownloads
+     * @param fileNumber    The fileNumber of the file or directory in the archive served by BorgButler's
      */
     @GET
     @Path("/restore")
     @Produces(MediaType.APPLICATION_OCTET_STREAM)
-    public Response restore(@QueryParam("archiveId") String archiveId, @QueryParam("fileNumber") int fileNumber) {
+    public Response restore(@QueryParam("archiveId") String archiveId,
+                            @QueryParam("openDownloads") boolean openDownloads,
+                            @QueryParam("fileNumber") int fileNumber) {
         log.info("Requesting file #" + fileNumber + " of archive '" + archiveId + "'.");
         FileSystemFilter filter = new FileSystemFilter().setFileNumber(fileNumber);
         List<BorgFilesystemItem> items = ButlerCache.getInstance().getArchiveContent(archiveId, false,
@@ -145,7 +149,8 @@
                 Response.ResponseBuilder builder = Response.status(Response.Status.NOT_FOUND);
                 return builder.build();
             }
-            openFileBrowser(new File(restoreDir, item.getPath()));
+            if (openDownloads)
+                openFileBrowser(new File(restoreDir, item.getPath()));
             Response.ResponseBuilder builder = Response.status(Response.Status.ACCEPTED);
             return builder.build();
         } catch (IOException ex) {

--
Gitblit v1.10.0