From 04506f4b421effe55c385709642fde7865790a09 Mon Sep 17 00:00:00 2001 From: backdev-1 Date: Thu, 23 Apr 2026 13:10:24 +0700 Subject: [PATCH] dev add cold storage --- .../soune/nocopy/service/file/ZipService.java | 57 ++++++------------- 1 file changed, 16 insertions(+), 41 deletions(-) diff --git a/src/main/java/ru/soune/nocopy/service/file/ZipService.java b/src/main/java/ru/soune/nocopy/service/file/ZipService.java index 772bfbd..a11f673 100644 --- a/src/main/java/ru/soune/nocopy/service/file/ZipService.java +++ b/src/main/java/ru/soune/nocopy/service/file/ZipService.java @@ -26,13 +26,10 @@ import java.util.zip.ZipOutputStream; public class ZipService { private final ModerationFileService moderationFileService; - private final CloudStorageService cloudStorageService; private static final int MAX_SIZE_MB = 20; - private static final int FIRST_PART = 1; - private static final int SECOND_PART = 2; @Value("${yandex.cloud.bucket-cold}") @@ -63,20 +60,22 @@ public class ZipService { throw new IOException("Missing part 1 or part 2 for user: " + userId); } - String part1Content = cloudStorageService.downloadPartFromBucket(bucketCold, part1Key); - String part2Content = cloudStorageService.downloadPartFromBucket(bucketCold, part2Key); + String part1Base64 = cloudStorageService.downloadPartFromBucket(bucketCold, part1Key); + String part2Base64 = cloudStorageService.downloadPartFromBucket(bucketCold, part2Key); - String fullBase64 = part1Content + part2Content; + String fullBase64 = part1Base64 + part2Base64; + + log.debug("Part1 length: {}, Part2 length: {}, Combined length: {}", + part1Base64.length(), part2Base64.length(), fullBase64.length()); return Base64.getDecoder().decode(fullBase64); } - private byte[] createZip(List files) throws IOException { + private byte[] createZip(List files) throws IOException { long totalSize = files.stream() .map(FileEntity::getFileSize) .reduce(0L, Long::sum); - if (totalSize > MAX_SIZE_MB * 1024 * 1024) { throw new IllegalArgumentException( String.format("Total size %.2f MB exceeds %d MB limit", @@ -86,8 +85,7 @@ public class ZipService { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ZipOutputStream zos = new ZipOutputStream(baos)) { - - for (FileEntity file: files) { + for (FileEntity file : files) { String filePath = file.getFilePath(); String fileName = file.getStoredFileName(); @@ -105,18 +103,11 @@ public class ZipService { } private String[] splitBase64(String base64) { - StringBuilder part1 = new StringBuilder(); - StringBuilder part2 = new StringBuilder(); - - for (int i = 0; i < base64.length(); i++) { - if (i % 2 == 0) { - part1.append(base64.charAt(i)); - } else { - part2.append(base64.charAt(i)); - } - } - - return new String[]{part1.toString(), part2.toString()}; + int half = base64.length() / 2; + return new String[]{ + base64.substring(0, half), + base64.substring(half) + }; } private void saveSplitFiles(Long userId, String part1, String part2) throws IOException { @@ -136,23 +127,7 @@ public class ZipService { moderationFileService.addFiles(userId, files); - log.info("Saved split files to cold storage for userId: {}", userId); + log.info("Saved split files to cold storage for userId: {}, Base64 length: {}", + userId, part1.length() + part2.length()); } - - private String mergeBase64(String part1, String part2) { - StringBuilder merged = new StringBuilder(); - - int maxLength = Math.max(part1.length(), part2.length()); - - for (int i = 0; i < maxLength; i++) { - if (i < part1.length()) { - merged.append(part1.charAt(i)); - } - if (i < part2.length()) { - merged.append(part2.charAt(i)); - } - } - - return merged.toString(); - } -} +} \ No newline at end of file