Files
make_video_site/public/folder.js
claude-bot 59f96a12a6 feat(routes): add short /file/video/:id alias for video stream
외부 공유용으로 더 짧은 영상 파일 URL 을 제공:
  /file/video/:videoId   ← 신규 (영상 주소 복사 결과)
  /api/video/:videoId/file ← 호환용 alias 로 유지 (기존 링크 안 깨지게)
  /api/video/:videoId     ← 메타 JSON (변경 없음)

핸들러는 한 함수를 두 라우트에 공유. 우클릭 "영상 주소 복사" 가
이제 새 짧은 경로를 클립보드에 넣음.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-15 21:58:37 +09:00

102 lines
3.5 KiB
JavaScript

(function () {
var folder = (window.__OP__ || {}).folder
var ctxMenu = document.getElementById('ctxMenu')
var targetId = null
var targetTitle = null
function showCtx(x, y) {
ctxMenu.style.left = x + 'px'
ctxMenu.style.top = y + 'px'
ctxMenu.hidden = false
}
function hideCtx() { ctxMenu.hidden = true }
document.querySelectorAll('.adminVideo').forEach(function (card) {
card.addEventListener('contextmenu', function (e) {
e.preventDefault()
targetId = card.getAttribute('data-id')
targetTitle = card.getAttribute('data-title')
showCtx(e.clientX, e.clientY)
})
})
document.addEventListener('click', function (e) {
if (!ctxMenu.contains(e.target)) hideCtx()
})
ctxMenu.addEventListener('click', function (e) {
var btn = e.target.closest('button')
if (!btn) return
var action = btn.getAttribute('data-action')
if (action === 'edit') {
location.href = '/op/folder/' + encodeURIComponent(folder) + '/video/editor?id=' + encodeURIComponent(targetId)
} else if (action === 'copyUrl') {
copyVideoUrl(targetId)
} else if (action === 'rename') {
var t = window.prompt('새 영상 제목', targetTitle)
if (t && t !== targetTitle) {
fetch('/op/folder/' + encodeURIComponent(folder) + '/video/rename', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ id: targetId, title: t })
}).then(function (r) { return r.json() }).then(function (j) {
if (j.ok) location.reload()
else alert(j.message || '이름 변경 실패')
})
}
} else if (action === 'delete') {
if (window.confirm('"' + targetTitle + '" 영상을 정말 삭제할까요?')) {
fetch('/op/folder/' + encodeURIComponent(folder) + '/video/delete', {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify({ id: targetId })
}).then(function (r) { return r.json() }).then(function (j) {
if (j.ok) location.reload()
else alert(j.message || '삭제 실패')
})
}
}
hideCtx()
})
function copyVideoUrl(id) {
var url = location.origin + '/file/video/' + encodeURIComponent(id)
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(url).then(function () {
flashToast('주소가 복사되었습니다.')
}, function () {
fallbackCopy(url)
})
} else {
fallbackCopy(url)
}
}
function fallbackCopy(text) {
try {
var ta = document.createElement('textarea')
ta.value = text
ta.style.position = 'fixed'
ta.style.left = '-9999px'
document.body.appendChild(ta)
ta.focus(); ta.select()
var ok = document.execCommand && document.execCommand('copy')
document.body.removeChild(ta)
if (ok) flashToast('주소가 복사되었습니다.')
else window.prompt('주소를 복사하세요:', text)
} catch (e) {
window.prompt('주소를 복사하세요:', text)
}
}
function flashToast(msg) {
var el = document.createElement('div')
el.className = 'flashToast'
el.textContent = msg
document.body.appendChild(el)
requestAnimationFrame(function () { el.classList.add('show') })
setTimeout(function () {
el.classList.remove('show')
setTimeout(function () { el.parentNode && el.parentNode.removeChild(el) }, 200)
}, 1500)
}
})()