revert : 주크박스 API·음악 폴더 마운트 삭제 (서버 부하)
SpecialSource Backend CI/CD / build-and-deploy (push) Successful in 1m27s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
headporterandClaude Opus 5.5 committed 2026-12-01 10:28:02 +09:00
1 parent 659644d7e8
commit c0090048c8
4 files changed
-111

No files matched your search

@@ -1,75 +0,0 @@
package company.specialsource.controller;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.regex.Pattern;
import java.util.stream.Stream;
/**
* 주크박스: 음악 폴더(NAS의 1001 앨범 RAR들, 읽기 전용 마운트)의 RAR 목록과 파일을 그대로 내려줌.
* 압축은 브라우저가 풂(node-unrar-js). 로그인한 회원만 (SecurityConfig의 anyRequest().authenticated()).
*/
@RestController
@RequestMapping("/api/jukebox")
public class JukeboxController {
// 분할 압축의 2번째 조각부터(xxx.part2.rar ...)는 목록에서 뺌 → 브라우저에서 이어 붙일 수 없음
private static final Pattern LATER_PART = Pattern.compile("(?i).*\\.part0*([2-9]|\\d{2,})\\.rar$");
private static final Duration CACHE_TTL = Duration.ofMinutes(10);
private final Path dir;
private List<Album> cached = List.of();
private Instant scannedAt = Instant.EPOCH;
public JukeboxController(@Value("${jukebox.dir}") String dir) {
this.dir = Paths.get(dir).toAbsolutePath().normalize();
}
/** path = 음악 폴더 기준 상대 경로 (파일 받을 때 그대로 돌려줌) */
public record Album(String path, String name, long size) {}
// 앨범(RAR) 목록, 이름순. 10분 동안 메모리에 보관
@GetMapping("/albums")
public synchronized List<Album> albums() throws IOException {
if (Instant.now().isBefore(scannedAt.plus(CACHE_TTL))) return cached;
if (!Files.isDirectory(dir)) return List.of();
try (Stream<Path> files = Files.walk(dir)) {
cached = files
.filter(p -> Files.isRegularFile(p) && p.getFileName().toString().toLowerCase().endsWith(".rar"))
.filter(p -> !LATER_PART.matcher(p.getFileName().toString()).matches())
.map(p -> {
String name = p.getFileName().toString().replaceAll("(?i)(\\.part0*1)?\\.rar$", "");
return new Album(dir.relativize(p).toString().replace('\\', '/'), name, p.toFile().length());
})
.sorted((a, b) -> a.path().compareToIgnoreCase(b.path()))
.toList();
}
scannedAt = Instant.now();
return cached;
}
// RAR 파일 그대로 (Range 요청 지원은 스프링이 처리). 음악 폴더 밖·RAR 아닌 파일은 거절
@GetMapping("/file")
public ResponseEntity<FileSystemResource> file(@RequestParam String path) {
Path file = dir.resolve(path).normalize();
if (!file.startsWith(dir) || !file.getFileName().toString().toLowerCase().endsWith(".rar") || !Files.isRegularFile(file)) {
return ResponseEntity.notFound().build();
}
return ResponseEntity.ok().contentType(MediaType.APPLICATION_OCTET_STREAM).body(new FileSystemResource(file));
}
}
-3
View File
@@ -48,9 +48,6 @@ scraping:
cleanup-initial-delay-ms: 60000 # 앱 기동 후 첫 정리 작업까지 대기 시간
cleanup-interval-ms: 86400000 # 정리 작업 주기 (24시간)
jukebox:
dir: ${JUKEBOX_DIR:./music} # 주크박스 음악 폴더 (1001 앨범 RAR, NAS 폴더를 읽기 전용 마운트)
media:
dir: ${MEDIA_DIR:./media} # 다운로드 게시판 파일 폴더 (봇 컨테이너와 같은 NAS 폴더를 마운트)
downloader-url: ${DOWNLOADER_URL:http://localhost:8090} # 디스코드 다운로드 봇 HTTP 창구