fix(folders): enforce videos-only at depth 2 (P1 review fix)

- routes/op.ts: editor / upload / youtube-start reject when folder.parentId === null
- op/folder.ejs: at depth 1 show only "하위 폴더 추가"; at depth 2 show
  "영상 추가" + "플레이리스트 추가". Video grid and sub-folder modal
  rendered conditionally.
- folder.ejs (public): at depth 1 render only sub-folder grid; at depth 2
  render only video grid.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
Claude
2026-05-31 23:43:24 +09:00
parent c5faa8808c
commit 3089af1ad8
3 changed files with 69 additions and 56 deletions

View File

@@ -197,6 +197,11 @@ opRouter.get(
res.status(404).send('폴더를 찾을 수 없습니다.') res.status(404).send('폴더를 찾을 수 없습니다.')
return return
} }
// 영상은 2단계(서브) 폴더에만 둔다. 1단계 폴더는 컨테이너 전용.
if (folder.parentId === null) {
res.status(400).send('영상은 하위 폴더에서만 추가할 수 있습니다.')
return
}
const videoId = typeof req.query.id === 'string' ? req.query.id : null const videoId = typeof req.query.id === 'string' ? req.query.id : null
const video = videoId ? getVideo(videoId) : null const video = videoId ? getVideo(videoId) : null
res.render('op/editor', { res.render('op/editor', {
@@ -239,6 +244,7 @@ opRouter.post(
try { try {
const folder = getFolderByPath(collectFolderSegments(req.params)) const folder = getFolderByPath(collectFolderSegments(req.params))
if (!folder) throw new Error('폴더를 찾을 수 없습니다.') if (!folder) throw new Error('폴더를 찾을 수 없습니다.')
if (folder.parentId === null) throw new Error('영상은 하위 폴더에서만 추가할 수 있습니다.')
const file = req.file const file = req.file
if (!file) throw new Error('파일이 없습니다.') if (!file) throw new Error('파일이 없습니다.')
const title = pickStr(req.body?.title).trim() || file.originalname const title = pickStr(req.body?.title).trim() || file.originalname
@@ -284,6 +290,7 @@ opRouter.post(
try { try {
const folder = getFolderByPath(collectFolderSegments(req.params)) const folder = getFolderByPath(collectFolderSegments(req.params))
if (!folder) throw new Error('폴더를 찾을 수 없습니다.') if (!folder) throw new Error('폴더를 찾을 수 없습니다.')
if (folder.parentId === null) throw new Error('영상은 하위 폴더에서만 추가할 수 있습니다.')
const url = pickStr(req.body.url).trim() const url = pickStr(req.body.url).trim()
const title = pickStr(req.body.title).trim() || undefined const title = pickStr(req.body.title).trim() || undefined
if (!url) throw new Error('URL 을 입력해 주세요.') if (!url) throw new Error('URL 을 입력해 주세요.')

View File

@@ -28,32 +28,34 @@
<h1>📁 <%= breadcrumb.join(' / ') %></h1> <h1>📁 <%= breadcrumb.join(' / ') %></h1>
</section> </section>
<% if (subFolders && subFolders.length > 0) { %> <% if (!isSubFolder) { %>
<section class="folderGrid"> <section class="folderGrid">
<% subFolders.forEach(function (sf) { %> <% if (!subFolders || subFolders.length === 0) { %>
<p class="muted">아직 하위 폴더가 없습니다.</p>
<% } %>
<% (subFolders || []).forEach(function (sf) { %>
<a class="folderCard" href="/folder/<%= folderPathEnc %>/<%= encodeURIComponent(sf.name) %>"> <a class="folderCard" href="/folder/<%= folderPathEnc %>/<%= encodeURIComponent(sf.name) %>">
<span class="folderIcon">📁</span> <span class="folderIcon">📁</span>
<span class="folderName"><%= sf.name %></span> <span class="folderName"><%= sf.name %></span>
</a> </a>
<% }) %> <% }) %>
</section> </section>
<% } %> <% } else { %>
<section class="videoGrid">
<section class="videoGrid"> <% if (videos.length === 0) { %>
<% if (videos.length === 0 && (!subFolders || subFolders.length === 0)) { %> <p class="muted">이 폴더에 영상이 없습니다.</p>
<p class="muted">이 폴더에 영상이 없습니다.</p> <% } %>
<% } %> <% videos.forEach(function (v) {
<% videos.forEach(function (v) { %> var shareUrl = '/video/' + folderPathEnc + '/' + encodeURIComponent(v.id)
<%
var shareUrl = '/video/' + folderPathEnc + '/' + encodeURIComponent(v.id)
%> %>
<a class="videoCard" href="<%= shareUrl %>" <a class="videoCard" href="<%= shareUrl %>"
data-video-id="<%= v.id %>" data-share-url="<%= shareUrl %>"> data-video-id="<%= v.id %>" data-share-url="<%= shareUrl %>">
<div class="videoThumb">▶</div> <div class="videoThumb">▶</div>
<div class="videoTitle"><%= v.title %></div> <div class="videoTitle"><%= v.title %></div>
</a> </a>
<% }) %> <% }) %>
</section> </section>
<% } %>
</main> </main>
<div class="ctxMenu" id="ctxMenu" hidden> <div class="ctxMenu" id="ctxMenu" hidden>

View File

@@ -25,18 +25,20 @@
</div> </div>
<div class="dashboardActions"> <div class="dashboardActions">
<% if (!isSubFolder) { %> <% if (!isSubFolder) { %>
<button type="button" class="secondaryButton" id="addSubFolderBtn">하위 폴더 추가</button> <button type="button" class="primaryButton" id="addSubFolderBtn">하위 폴더 추가</button>
<% } %> <% } else { %>
<a class="primaryButton" href="<%= editorHref %>">영상 추가</a> <a class="primaryButton" href="<%= editorHref %>">영상 추가</a>
<% if (isSubFolder) { %>
<a class="primaryButton" href="<%= playlistHref %>">플레이리스트 추가</a> <a class="primaryButton" href="<%= playlistHref %>">플레이리스트 추가</a>
<% } %> <% } %>
</div> </div>
</section> </section>
<% if (!isSubFolder && subFolders && subFolders.length > 0) { %> <% if (!isSubFolder) { %>
<section class="folderGrid" id="subFolderGrid"> <section class="folderGrid" id="subFolderGrid">
<% subFolders.forEach(function (sf) { %> <% if (!subFolders || subFolders.length === 0) { %>
<p class="muted">아직 하위 폴더가 없습니다. 우측 상단에서 하위 폴더를 추가하세요. (영상은 하위 폴더 안에서만 추가할 수 있습니다.)</p>
<% } %>
<% (subFolders || []).forEach(function (sf) { %>
<div class="folderCard adminFolder" data-folder-id="<%= sf.id %>" data-name="<%= sf.name %>"> <div class="folderCard adminFolder" data-folder-id="<%= sf.id %>" data-name="<%= sf.name %>">
<a class="folderCardLink" href="/op/folder/<%= folderPathEnc %>/<%= encodeURIComponent(sf.name) %>"> <a class="folderCardLink" href="/op/folder/<%= folderPathEnc %>/<%= encodeURIComponent(sf.name) %>">
<span class="folderIcon">📁</span> <span class="folderIcon">📁</span>
@@ -45,28 +47,28 @@
</div> </div>
<% }) %> <% }) %>
</section> </section>
<% } else { %>
<section class="videoGrid" id="videoGrid">
<% if (videos.length === 0) { %>
<p class="muted">이 폴더에 영상이 없습니다. 우측 상단에서 영상을 추가하세요.</p>
<% } %>
<% videos.forEach(function (v) {
var shareUrl = '/video/' + folderPathEnc + '/' + encodeURIComponent(v.id)
%>
<div class="videoCard adminVideo"
data-id="<%= v.id %>"
data-video-id="<%= v.id %>"
data-title="<%= v.title %>"
data-share-url="<%= shareUrl %>">
<div class="videoThumb">▶</div>
<div class="videoTitle"><%= v.title %></div>
<% if (v.sourceType === 'youtube') { %>
<div class="muted">YouTube</div>
<% } %>
</div>
<% }) %>
</section>
<% } %> <% } %>
<section class="videoGrid" id="videoGrid">
<% if (videos.length === 0 && (isSubFolder || !subFolders || subFolders.length === 0)) { %>
<p class="muted">이 폴더에 영상이 없습니다. 우측 상단에서 영상을 추가하세요.</p>
<% } %>
<% videos.forEach(function (v) {
var shareUrl = '/video/' + folderPathEnc + '/' + encodeURIComponent(v.id)
%>
<div class="videoCard adminVideo"
data-id="<%= v.id %>"
data-video-id="<%= v.id %>"
data-title="<%= v.title %>"
data-share-url="<%= shareUrl %>">
<div class="videoThumb">▶</div>
<div class="videoTitle"><%= v.title %></div>
<% if (v.sourceType === 'youtube') { %>
<div class="muted">YouTube</div>
<% } %>
</div>
<% }) %>
</section>
</main> </main>
<div class="ctxMenu" id="ctxMenu" hidden> <div class="ctxMenu" id="ctxMenu" hidden>
@@ -90,19 +92,21 @@
</div> </div>
</div> </div>
<div class="modalOverlay" id="addSubFolderModal" hidden> <% if (!isSubFolder) { %>
<div class="modalCard"> <div class="modalOverlay" id="addSubFolderModal" hidden>
<h2>하위 폴더 추가</h2> <div class="modalCard">
<label> <h2>하위 폴더 추가</h2>
<span>폴더 이름</span> <label>
<input type="text" id="addSubFolderInput" autofocus /> <span>폴더 이름</span>
</label> <input type="text" id="addSubFolderInput" autofocus />
<div class="modalActions"> </label>
<button type="button" class="secondaryButton" id="addSubFolderCancel">취소</button> <div class="modalActions">
<button type="button" class="primaryButton" id="addSubFolderConfirm">생성</button> <button type="button" class="secondaryButton" id="addSubFolderCancel">취소</button>
<button type="button" class="primaryButton" id="addSubFolderConfirm">생성</button>
</div>
</div> </div>
</div> </div>
</div> <% } %>
<script> <script>
window.__OP__ = { window.__OP__ = {