Skip to content

Commit

Permalink
Merge pull request #222 from Kernel360/develop
Browse files Browse the repository at this point in the history
branch resotre
  • Loading branch information
km2535 authored Aug 30, 2024
2 parents 3b7f437 + 0d97fb2 commit 18b0162
Show file tree
Hide file tree
Showing 32 changed files with 544 additions and 218 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ jobs:
sudo docker pull ${{ secrets.DOCKERHUB_CONTAINERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
# Stop and remove the existing container if it exists
sudo docker ps -q -f name=speech2 | xargs -r sudo docker stop
sudo docker ps -q -f name=speechup-spring | xargs -r sudo docker stop
sudo docker images --filter "dangling=true" -q | xargs sudo docker rmi
sudo docker ps -a -q -f name=speech2 | xargs -r sudo docker rm
sudo docker ps -a -q -f name=speechup-spring | xargs -r sudo docker rm
# Run the new container with environment variables
sudo docker run -d \
-p 8080:8080 \
--name speech2 \
--name speechup-spring -v /root/logs/:/root/logs/ \
${{ secrets.DOCKERHUB_CONTAINERNAME }}/${{ secrets.DOCKERHUB_REPOSITORY }}:latest
# Clean up old Docker images on the server
Expand Down
509 changes: 352 additions & 157 deletions README.md

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ protected SecurityFilterChain configure(HttpSecurity httpSecurity) throws Except
"/boards", "/boards/**", "/api/upload",
"/.well-known/**", "/api/open/data/*", "/banned-page",
"/report", "/scripts", "/script-write", "/scripts-list", "/replies/**",
"/admin/view", "/page/me", "/speech-record", "reports/**", "/").permitAll()
"/admin/view", "/page/me", "reports/**", "/", "/speech-record").permitAll()
.requestMatchers("/api/boards").hasAnyRole("ADMIN_USER", "GENERAL_USER")
.requestMatchers("/users/me").hasAnyRole("ADMIN_USER", "GENERAL_USER","BAN_USER")
.requestMatchers("/speech-record").hasAnyRole("ADMIN_USER", "GENERAL_USER")
Expand Down Expand Up @@ -108,7 +108,7 @@ class FailedAuthenticationEntryPoint implements AuthenticationEntryPoint {
@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
AuthenticationException authException) throws
IOException, ServletException {
IOException {
response.setContentType("application/json");
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
response.getWriter().write("{\"code\" : \"NP\", \"message\" : \"No Permission\"}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected void doFilterInternal(@Nullable HttpServletRequest request, @Nullable
SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
AbstractAuthenticationToken authenticationToken = new UsernamePasswordAuthenticationToken(socialId, token, authorities);

authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
securityContext.setAuthentication(authenticationToken);
SecurityContextHolder.setContext(securityContext);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ public ResponseEntity<RecordAddDto.Response> addRecord(
/**
* 특정 녹음을 삭제합니다. 실제로 데이터를 삭제하지 않고, 삭제 상태로 표시합니다.
*
* @param recordIsUseRequestDto 삭제할 녹음의 ID와 관련 정보를 포함하는 요청 객체
* @param recordId 삭제할 녹음의 ID
* @return 삭제 상태로 변경된 녹음의 세부 정보
*/
@PatchMapping("")
@PatchMapping("/{recordId}")
@PreAuthorize("hasAnyRole('GENERAL_USER', 'ADMIN_USER')")
public ResponseEntity<RecordIsUseDto.Response> deleteRecord(
@RequestBody RecordIsUseDto.Request recordIsUseRequestDto
@PathVariable Long recordId
) {
return ResponseEntity.ok(recordService.deleteRecord(recordIsUseRequestDto));
return ResponseEntity.ok(recordService.deleteRecord(recordId));
}

/**
Expand Down
18 changes: 10 additions & 8 deletions src/main/java/com/speech/up/record/entity/RecordEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,14 @@ private RecordEntity(byte[] audio, RecordAddDto.Request request, ScriptEntity sc
this(audio, request.getLanguageCode(), scriptEntity, true, false);
}

private RecordEntity(RecordIsUseDto.Request recordIsUseRequestDto) {
this(recordIsUseRequestDto.getRecordEntity().getAudio(),
recordIsUseRequestDto.getRecordEntity()
.getLanguageCode(),
recordIsUseRequestDto.getRecordEntity().getScript(), true, false);
this.recordId = recordIsUseRequestDto.getRecordEntity().getRecordId();
private RecordEntity(Long recordId, RecordEntity recordEntity) {
this.recordId = recordId;
this.script = recordEntity.getScript();
this.languageCode = recordEntity.getLanguageCode();
this.isUse = false;
this.isAnalyzed = recordEntity.isAnalyzed();
this.report = recordEntity.getReport();
this.audio = recordEntity.getAudio();
}

private RecordEntity(RecordEntity recordEntity) {
Expand All @@ -78,8 +80,8 @@ public static RecordEntity create(byte[] audio, RecordAddDto.Request request, Sc
return new RecordEntity(audio, request, scriptEntity);
}

public static RecordEntity delete(RecordIsUseDto.Request recordIsUseRequestDto) {
return new RecordEntity(recordIsUseRequestDto);
public static RecordEntity delete(Long recordId, RecordEntity recordEntity) {
return new RecordEntity(recordId, recordEntity);
}

public static RecordEntity analyze(RecordEntity recordEntity) {
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/com/speech/up/record/service/RecordService.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ public RecordAddDto.Response addRecord(MultipartFile file, String languageCode,
return RecordAddDto.toResponse(recordRepository.save(recordEntity));
}

public RecordIsUseDto.Response deleteRecord(RecordIsUseDto.Request recordIsUseRequestDto) {
RecordEntity recordEntity = RecordEntity.delete(recordIsUseRequestDto);
@Transactional
public RecordIsUseDto.Response deleteRecord(Long recordId) {
RecordEntity record = recordRepository.findById(recordId).get();
RecordEntity recordEntity = RecordEntity.delete(recordId, record);
return RecordIsUseDto.toResponse(recordRepository.save(recordEntity));
}

Expand Down
31 changes: 28 additions & 3 deletions src/main/java/com/speech/up/record/service/dto/RecordIsUseDto.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.speech.up.record.service.dto;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.databind.PropertyNamingStrategies;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import com.speech.up.record.entity.RecordEntity;
import com.speech.up.report.entity.ReportEntity;
import com.speech.up.script.entity.ScriptEntity;

import jakarta.persistence.CascadeType;
import jakarta.persistence.FetchType;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import lombok.Getter;
import lombok.ToString;

Expand All @@ -13,12 +21,29 @@
public class RecordIsUseDto {
@Getter
@ToString
@JsonNaming(PropertyNamingStrategies.SnakeCaseStrategy.class)
public static class Request {
private final RecordEntity recordEntity;
private final Long recordId;

private final byte[] audio;

private final String languageCode;

private final boolean isAnalyzed;

private final ScriptEntity script;

private final boolean isUse;

private final ReportEntity report;

public Request(RecordEntity recordEntity) {
this.recordEntity = recordEntity;
this.recordId = recordEntity.getRecordId();
this.audio = recordEntity.getAudio();
this.languageCode = recordEntity.getLanguageCode();
this.isAnalyzed = recordEntity.isAnalyzed();
this.script = recordEntity.getScript();
this.isUse = recordEntity.isUse();
this.report = recordEntity.getReport();
}
}

Expand Down
12 changes: 10 additions & 2 deletions src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<!-- Console 레벨 로깅 -->
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>

<!-- DEBUG 레벨 로깅 -->
<appender name="DEBUG_FILE" class="ch.qos.logback.core.FileAppender">
<file>/root/logs/debug.log</file>
Expand Down Expand Up @@ -52,9 +59,10 @@
</appender>

<!-- 로깅 레벨 설정 -->
<root level="INFO">
<root level="CONSOLE">
<appender-ref ref="CONSOLE" />
<appender-ref ref="DEBUG_FILE" />
<appender-ref ref="INFO_FILE" />
<appender-ref ref="ERROR_FILE" />
</root>
</configuration>
</configuration>
4 changes: 4 additions & 0 deletions src/main/resources/static/css/board-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,8 @@
padding: 0;
margin: 0;
list-style: none;
}

.container {
margin-bottom: 100px;
}
2 changes: 1 addition & 1 deletion src/main/resources/static/css/script-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ strong {
background-color: #000000;
color: white;
border-radius: 5%;
width: 180px;
width: 200px;
height: 20px;
text-align: center;
line-height: 20px;
Expand Down
Binary file added src/main/resources/static/images/speechup.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 modified src/main/resources/static/images/tooltip-image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions src/main/resources/static/js/addRecordingToList.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ function addRecordingToList(url, recordId) {
audio.src = url;
li.appendChild(audio);

const deleteButton = document.createElement('button');

deleteButton.setAttribute('id', 'delete-button');
deleteButton.setAttribute('style', 'background-color: darkred')
deleteButton.textContent = '삭제하기';
deleteButton.addEventListener('click', () => deleteRecord(recordId));
console.log(recordId);
const analyzeButton = document.createElement('button');

analyzeButton.setAttribute('id', 'analyze-button');
analyzeButton.textContent = '분석하기';
analyzeButton.addEventListener('click', () => saveRecord(recordId));

li.appendChild(analyzeButton);
li.appendChild(deleteButton);
list.appendChild(li);

}
4 changes: 3 additions & 1 deletion src/main/resources/static/js/analyticRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ function displayRecords(records) {
const url = URL.createObjectURL(blob);

const li = document.createElement('li');

console.log(record.record_id);
li.innerHTML = `
<div class="recording-item">
<audio controls src="${url}"></audio>
<button onclick="deleteRecord('${record.record_id}')" style="background-color: darkred">삭제하기</button>
<button onclick="navigate('${btoa(JSON.stringify(record))}')">
${record.analyzed ? '분석결과' : '분석하기'}
</button>
Expand All @@ -60,7 +63,6 @@ function displayRecords(records) {

list.appendChild(li);

// URL을 해제하여 메모리 누수 방지
li.querySelector('audio').onended = () => {
URL.revokeObjectURL(url);
};
Expand Down
16 changes: 16 additions & 0 deletions src/main/resources/static/js/reply.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,20 @@ async function deleteReply(replyId, userId, name, boardId){
window.location.reload();
}
).catch((e) => console.error(e))
}


function checkButton(){
const commentTextArea = document.getElementById('comment-text');
const submitButton = document.getElementById('submit_button');

// 입력값이 변경될 때마다 호출되는 함수
commentTextArea.addEventListener('input', () => {
// 텍스트 영역의 값이 비어 있으면 버튼 비활성화, 아니면 활성화
if (commentTextArea.value.trim() === '') {
submitButton.disabled = true;
} else {
submitButton.disabled = false;
}
});
}
39 changes: 35 additions & 4 deletions src/main/resources/static/js/saveRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,53 @@ function saveRecord(listItemId) {
}

function isAnalyze(recordId) {
// 로딩바 표시
const jwtToken = getItemWithExpiry("jwtToken");
const loadingBar = document.getElementById('loading-bar');
fetch(`/speech-record/${recordId}/analyze`, {
method: 'PATCH',
headers: {
'Authorization' : `${jwtToken}`
},
}).then(data => {
console.log('Analysis status updated:', data);
})
.then(data => {
console.log('Analysis status updated:', data);
})
.catch(error => {
console.error('Error:', error);
})
.finally(() => {
loadingBar.style.display = 'none';
window.location.reload();
});
}

function deleteRecord(recordId) {
const jwtToken = getItemWithExpiry("jwtToken");
const request = {
recordId: recordId
};

fetch(`/speech-record/${recordId}`, {
method: 'PATCH',
headers: {
'Authorization': `${jwtToken}`
},
body: JSON.stringify(request)
})
.then(response => {
if (!response.ok) {
return response.json().then(data => {
throw new Error(`삭제 요청 실패: ${data.message || response.statusText}`);
});
} else {
alert('삭제가 완료되었습니다.');
}
})
.catch(error => {
console.error('Error:', error);
alert('삭제 중 오류가 발생했습니다.');
})
.finally(() => {
loadingBar.style.display = 'none';
window.location.reload();
});
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/admin-page.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/header-style.css">
<link rel="stylesheet" type="text/css" href="/css/admin-view.css">

<link rel="icon" href="/images/speechup.png">
</head>
<body>
<header>
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/templates/banned.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
text-decoration: underline;
}
</style>
<link rel="icon" href="/images/speechup.png">
</head>
<body>
<div class="container">
Expand Down
Loading

0 comments on commit 18b0162

Please sign in to comment.