From 80e3ff05d56044948a1fd6ef9967d7239de68925 Mon Sep 17 00:00:00 2001 From: grimsi <9295182+grimsi@users.noreply.github.com> Date: Sun, 24 Jul 2022 20:52:29 +0200 Subject: [PATCH] WIP: Simplified logic on when to download single file vs when to zip folder --- .../gameyfin/service/FilesystemService.java | 32 +------------------ 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/backend/src/main/java/de/grimsi/gameyfin/service/FilesystemService.java b/backend/src/main/java/de/grimsi/gameyfin/service/FilesystemService.java index aa0d6e8..452f975 100644 --- a/backend/src/main/java/de/grimsi/gameyfin/service/FilesystemService.java +++ b/backend/src/main/java/de/grimsi/gameyfin/service/FilesystemService.java @@ -98,19 +98,6 @@ public class FilesystemService { Path path = Path.of(g.getPath()); if(!path.toFile().isDirectory()) return getFilenameWithExtension(path); - - Optional optionalGameArchive; - try (Stream filesStream = Files.list(path)) { - optionalGameArchive = filesStream.filter(this::hasGameArchiveExtension).findFirst(); - } catch (IOException e) { - log.error("Error while accessing folder:", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Error while accessing folder '%s'.".formatted(path)); - } - - if(optionalGameArchive.isPresent()) { - return getFilenameWithExtension(optionalGameArchive.get()); - } - return getFilenameWithExtension(path) + ".zip"; } @@ -242,7 +229,7 @@ public class FilesystemService { Path path = Path.of(game.getPath()); if(path.toFile().isDirectory()) { - downloadFromFolder(path, outputStream); + downloadFilesAsZip(path, outputStream); } else { downloadFile(path, outputStream); } @@ -260,23 +247,6 @@ public class FilesystemService { } } - private void downloadFromFolder(Path path, OutputStream outputStream) { - Optional optionalGameArchive; - - try (Stream filesStream = Files.list(path)) { - optionalGameArchive = filesStream.filter(this::hasGameArchiveExtension).findFirst(); - } catch (IOException e) { - log.error("Error while accessing folder:", e); - throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "Error while accessing folder '%s'.".formatted(path)); - } - - if(optionalGameArchive.isPresent()) { - downloadFile(optionalGameArchive.get(), outputStream); - } else { - downloadFilesAsZip(path, outputStream); - } - } - private void downloadFilesAsZip(Path path, OutputStream outputStream) { ZipOutputStream zos = new ZipOutputStream(outputStream){{ def.setLevel(Deflater.NO_COMPRESSION);