Compare commits

..
3 Commits
Author SHA1 Message Date
headporterandClaude Opus 5.5 25f583608d fix : 봇 오류를 502 대신 500으로 (Worker가 502를 '서버 쉬는 중'으로 바꿔 버림)
SpecialSource Backend CI/CD / build-and-deploy (push) Successful in 55s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 09:53:53 +09:00
headporterandClaude Opus 5.5 c0090048c8 revert : 주크박스 API·음악 폴더 마운트 삭제 (서버 부하)
SpecialSource Backend CI/CD / build-and-deploy (push) Successful in 1m27s
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-01 10:28:02 +09:00
headporterandClaude Opus 5.5 659644d7e8 test : 주크박스 파일 받기 경로 탈출(../, 절대 경로)·RAR 아닌 파일 거절 확인
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-30 17:20:58 +09:00
4 changed files with 3 additions and 82 deletions

No files matched your search

-2
View File
@@ -41,8 +41,6 @@ jobs:
-v /volume1/docker/app/specialsource-backend/logs:/app/logs \
-v /volume2/data/media:/media \
-e MEDIA_DIR=/media \
-v /home/sungjin.choi/Music/1001-albums-you-must-hear-before-you-die-collections:/music:ro \
-e JUKEBOX_DIR=/music \
-e DOWNLOADER_URL=http://192.168.0.215:18090 \
-e DOWNLOADER_API_KEY=${{ secrets.DOWNLOADER_API_KEY }} \
-e MEDIA_CALLBACK_URL=http://192.168.0.215:18080/api/media-posts/callback \
@@ -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));
}
}
@@ -121,12 +121,13 @@ public class MediaPostController {
} catch (RestClientResponseException e) {
repository.delete(post);
// 봇의 {"error": "..."} 를 그대로 전달 (예: 지원하지 않는 링크)
return ResponseEntity.status(e.getStatusCode().is4xxClientError() ? 400 : 502)
// ※ 502~504 금지: Cloudflare Worker가 "NAS 꺼짐"으로 보고 "서버가 쉬는 중" 화면으로 바꿔 버림 → 500
return ResponseEntity.status(e.getStatusCode().is4xxClientError() ? 400 : 500)
.contentType(MediaType.APPLICATION_JSON)
.body(e.getResponseBodyAsString());
} catch (RestClientException e) {
repository.delete(post);
return ResponseEntity.status(502).body(Map.of("error", "다운로드 봇에 연결할 수 없습니다"));
return ResponseEntity.status(500).body(Map.of("error", "다운로드 봇에 연결할 수 없습니다")); // 502 금지 (위 참고)
}
return ResponseEntity.ok(toResponse(post, false));
}
-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 창구