영상 파일 스트림 정규 주소를 재생 페이지와 동일한 폴더 경로 규칙으로 변경: /api/video/:topName[/:subName]/:videoId 경로의 폴더 부분이 영상 위치와 일치할 때만 200, 불일치 시 404. 재생 페이지(/video/...)와 ID 기반 레거시 스트림(/file/video/:id, /api/video/:id/file)은 그대로 유지(외부 공유 호환). Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>
60 lines
2.3 KiB
JavaScript
60 lines
2.3 KiB
JavaScript
(function () {
|
|
var overlay = document.getElementById('playerOverlay')
|
|
if (!overlay) return
|
|
var closeBtn = document.getElementById('playerClose')
|
|
var video = document.getElementById('playerVideo')
|
|
var titleEl = document.getElementById('playerTitle')
|
|
|
|
function openPlayer(videoId, title, shareUrl) {
|
|
// 사이트 내 재생도 share URL 을 주소창에 보이도록 pushState.
|
|
// share URL 이 없으면 단순한 /file/video/:id 로 폴백.
|
|
var url = shareUrl || ('/file/video/' + encodeURIComponent(videoId))
|
|
history.pushState({ player: true, videoId: videoId }, '', url)
|
|
titleEl.textContent = title || ''
|
|
// 파일 스트림 URL 은 공유 URL(/video/폴더/.../아이디)의 /video/ 를
|
|
// /api/video/ 로 바꾼 폴더 경로 기반 주소. shareUrl 이 없으면 레거시 폴백.
|
|
video.src = shareUrl
|
|
? shareUrl.replace(/^\/video\//, '/api/video/')
|
|
: ('/file/video/' + encodeURIComponent(videoId))
|
|
overlay.hidden = false
|
|
video.play().catch(function () { /* 자동재생 막힘 무시 */ })
|
|
}
|
|
|
|
function closePlayer() {
|
|
overlay.hidden = true
|
|
video.pause()
|
|
video.removeAttribute('src')
|
|
video.load()
|
|
if (history.state && history.state.player) {
|
|
history.back()
|
|
}
|
|
}
|
|
|
|
document.querySelectorAll('.videoCard').forEach(function (card) {
|
|
// <a> 태그면 클릭 시 share URL 로 풀 페이지 이동하도록 두고, 모달은 띄우지 않는다.
|
|
if (card.tagName && card.tagName.toLowerCase() === 'a') return
|
|
card.addEventListener('click', function () {
|
|
var id = card.getAttribute('data-video-id')
|
|
var titleNode = card.querySelector('.videoTitle')
|
|
var shareUrl = card.getAttribute('data-share-url')
|
|
openPlayer(id, titleNode ? titleNode.textContent : '', shareUrl)
|
|
})
|
|
})
|
|
|
|
if (closeBtn) closeBtn.addEventListener('click', closePlayer)
|
|
if (overlay) overlay.addEventListener('click', function (e) {
|
|
if (e.target === overlay) closePlayer()
|
|
})
|
|
window.addEventListener('popstate', function () {
|
|
if (!overlay.hidden) {
|
|
overlay.hidden = true
|
|
video.pause()
|
|
video.removeAttribute('src')
|
|
video.load()
|
|
}
|
|
})
|
|
document.addEventListener('keydown', function (e) {
|
|
if (e.key === 'Escape' && !overlay.hidden) closePlayer()
|
|
})
|
|
})()
|