Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hbam1/dizzycode
Browse files Browse the repository at this point in the history
  • Loading branch information
hbam1 committed Aug 17, 2024
2 parents 2408983 + 71d0105 commit 4a070ce
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 11 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

# 구조도

![](../../../Downloads/image.png)
<img width="880" alt="image" src="https://github.com/user-attachments/assets/9019fb6e-0a36-453c-a23a-8e1453ae2965">


# 기술 스택

Expand All @@ -21,7 +22,7 @@
# 주요 서비스 및 기능

- JWT 기반 인증
- WebSocket과 STOMP를 통한 실시간 채팅
- WebSocket과 STOMP를 통한 실시간 채팅 (파일 업로드 가능)
- Openvidu를 사용한 실시간 음성 및 화상 통화
- Redis와 Websocket을 활용한 실시간 유저 상태 체크
- 서버 scale out에 따른 로드밸런서(Nginx)와 Message Queue(RabbitMQ) 도입
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dizzycode.dizzycode.common.FileUpload;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.StringUtils;
Expand All @@ -18,6 +20,7 @@
@Service
public class FileUploadService {

private static final Logger log = LoggerFactory.getLogger(FileUploadService.class);
private final Path fileStorageLocation;

public FileUploadService(@Value("${file.upload-dir}") String uploadDir) {
Expand All @@ -30,9 +33,14 @@ public FileUploadService(@Value("${file.upload-dir}") String uploadDir) {
}

public String storeFile(MultipartFile file) throws IOException {

String originalFileName = StringUtils.cleanPath(file.getOriginalFilename());
String fileExtension = StringUtils.getFilenameExtension(originalFileName);
String fileName = UUID.randomUUID().toString() + (fileExtension != null ? "." + fileExtension : "");
String baseFileName = StringUtils.stripFilenameExtension(originalFileName);

String fileName = baseFileName + "_" + UUID.randomUUID().toString() +
(fileExtension != null ? "." + fileExtension : "");

Path targetLocation = this.fileStorageLocation.resolve(fileName);
Files.copy(file.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
return fileName;
Expand All @@ -48,9 +56,14 @@ public List<String> storeFiles(List<MultipartFile> files) throws IOException {
}

public String storeBinaryData(FileCreateDTO fileCreateDTO) throws IOException {

String originalFileName = StringUtils.cleanPath(fileCreateDTO.getFileName());
String fileExtension = StringUtils.getFilenameExtension(originalFileName);
String fileName = UUID.randomUUID().toString() + (fileExtension != null ? "." + fileExtension : "");
String baseFileName = StringUtils.stripFilenameExtension(originalFileName);

String fileName = baseFileName + "_" + UUID.randomUUID().toString() +
(fileExtension != null ? "." + fileExtension : "");

byte[] decodedBytes = Base64.getDecoder().decode(fileCreateDTO.getEncodedFile());
Path targetLocation = this.fileStorageLocation.resolve(fileName);
Files.write(targetLocation, decodedBytes);
Expand All @@ -65,4 +78,4 @@ public List<String> storeBinaryDatas(List<FileCreateDTO> fileCreateDTOs) throws
}
return fileNames;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.time.LocalDateTime;
import java.util.UUID;
import java.util.List;

@Getter
@Setter
Expand All @@ -29,7 +29,7 @@ public class DirectMessage {
private String content;

@Field("url")
private String url;
private List<String> url;

@Field("created_at")
private LocalDateTime createdAt = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;
import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
Expand Down Expand Up @@ -34,7 +35,7 @@ public class RoomMessage {
private String content;

@Field("url")
private String url;
private List<String> url;

@Field("created_at")
private LocalDateTime createdAt = LocalDateTime.now();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@
import lombok.Getter;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
public class MessageCreateDTO {

private Long senderId;
private String content;
private String url;
private List<String> url;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.Setter;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@Setter
Expand All @@ -12,6 +13,6 @@ public class MessageDetailDTO {
private String messageId;
private String senderUsername;
private String content;
private String url;
private List<String> url;
private LocalDateTime timestamp; // 메시지 생성 시간 추가
}
5 changes: 4 additions & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ spring.datasource.url=${SPRING_DATASOURCE_URL}
spring.datasource.username=${SPRING_DATASOURCE_USERNAME}
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD}
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.jpa.hibernate.ddl-auto=create
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL8Dialect

# JWT settings
Expand Down Expand Up @@ -35,6 +35,9 @@ spring.rabbitmq.port=5672
file.upload-dir=${FILE_UPLOAD_DIR}
spring.servlet.multipart.location=${SPRING_SERVLET_MULTIPART_LOCATION}
spring.resources.static-locations=${SPRING_RESOURCES_STATIC_LOCATIONS}
spring.servlet.multipart.max-file-size=30MB
spring.servlet.multipart.max-request-size=300MB
server.tomcat.max-swallow-size=300MB

spring.jdk.compiler.parameters=true
springdoc.api-docs.path=/api-docs
Expand Down
Binary file added uploads/4acaa5a0-4f6e-4580-b02e-b0b2a0a0c568.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added uploads/98031c89-0fbd-4349-9e6a-9f6b3f508c22
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4a070ce

Please sign in to comment.