diff --git a/build.gradle b/build.gradle index 08a5c5b..1298c60 100644 --- a/build.gradle +++ b/build.gradle @@ -54,8 +54,10 @@ dependencies { runtimeOnly 'io.jsonwebtoken:jjwt-jackson:0.11.5' // Redis implementation 'org.springframework.boot:spring-boot-starter-data-redis:2.7.14' - // spring cache + // Spring cache implementation 'org.springframework.boot:spring-boot-starter-cache:2.7.14' + // Snappy Java + implementation 'org.xerial.snappy:snappy-java:1.1.10.5' } tasks.named('test') { diff --git a/src/main/java/server/inuappcenter/kr/data/domain/board/Image.java b/src/main/java/server/inuappcenter/kr/data/domain/board/Image.java index 43c6f50..ff56dfa 100644 --- a/src/main/java/server/inuappcenter/kr/data/domain/board/Image.java +++ b/src/main/java/server/inuappcenter/kr/data/domain/board/Image.java @@ -8,7 +8,6 @@ import server.inuappcenter.kr.data.utils.ImageUtils; import javax.persistence.*; -import javax.servlet.http.HttpServletRequest; import java.io.IOException; @Entity @Getter @@ -73,11 +72,6 @@ public void isThumbnail() { this.isThumbnail = true; } - // 자원의 현재 위치를 반환하는 메소드 - public String getLocation(HttpServletRequest request, Image image) { - return request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + "/image/photo/" + image.getId().toString(); - } - public Image returnMultipartToEntity(MultipartFile multipartFile) throws IOException { return new Image(multipartFile.getOriginalFilename(), ImageUtils.compressImage(multipartFile.getBytes()), multipartFile.getSize()); } diff --git a/src/main/java/server/inuappcenter/kr/data/utils/ImageUtils.java b/src/main/java/server/inuappcenter/kr/data/utils/ImageUtils.java index d37a136..377f65b 100644 --- a/src/main/java/server/inuappcenter/kr/data/utils/ImageUtils.java +++ b/src/main/java/server/inuappcenter/kr/data/utils/ImageUtils.java @@ -1,48 +1,21 @@ package server.inuappcenter.kr.data.utils; -import java.io.ByteArrayOutputStream; -import java.util.zip.Deflater; -import java.util.zip.Inflater; +import org.xerial.snappy.Snappy; +import java.io.IOException; -public class ImageUtils { - - public static byte[] compressImage(byte[] data) { - Deflater deflater = new Deflater(); - deflater.setLevel(Deflater.BEST_COMPRESSION); - deflater.setInput(data); - deflater.finish(); - - ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length); - byte[] tmp = new byte[4*1024]; - while (!deflater.finished()) { - int size = deflater.deflate(tmp); - outputStream.write(tmp, 0, size); - } - - try { - outputStream.close(); - } catch (Exception ignored) { - - } +public class ImageUtils { - return outputStream.toByteArray(); + public static byte[] compressImage(byte[] data) throws IOException { + return Snappy.compress(data); } public static byte[] decompressImage(byte[] data) { - Inflater inflater = new Inflater(); - inflater.setInput(data); - ByteArrayOutputStream outputSteam = new ByteArrayOutputStream(data.length); - byte[] tmp = new byte[4*1024]; - try { - while (!inflater.finished()) { - int count = inflater.inflate(tmp); - outputSteam.write(tmp, 0, count); - } - outputSteam.close(); - } catch (Exception ignored) { + return Snappy.uncompress(data); + } catch(Exception e) { + throw new RuntimeException(e.getMessage()); } - return outputSteam.toByteArray(); } + } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index a0448d6..cd4b16a 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,11 +1,11 @@ spring: redis: - port: 5379 - host: na2ru2.me + port: 6379 + host: 192.168.55.22 datasource: driver-class-name: com.mysql.cj.jdbc.Driver username: dev - url: jdbc:mysql://na2ru2.me:6306/appcenter + url: jdbc:mysql://192.168.55.22/appcenter password: test1234 jpa: hibernate: @@ -20,5 +20,5 @@ spring: mode: always servlet: multipart: - maxFileSize: 50MB - maxRequestSize: 50MB + maxFileSize: 15MB + maxRequestSize: 15MB