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

View File

@@ -28,23 +28,24 @@
<h1>📁 <%= breadcrumb.join(' / ') %></h1>
</section>
<% if (subFolders && subFolders.length > 0) { %>
<% if (!isSubFolder) { %>
<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) %>">
<span class="folderIcon">📁</span>
<span class="folderName"><%= sf.name %></span>
</a>
<% }) %>
</section>
<% } %>
<% } else { %>
<section class="videoGrid">
<% if (videos.length === 0 && (!subFolders || subFolders.length === 0)) { %>
<% if (videos.length === 0) { %>
<p class="muted">이 폴더에 영상이 없습니다.</p>
<% } %>
<% videos.forEach(function (v) { %>
<%
<% videos.forEach(function (v) {
var shareUrl = '/video/' + folderPathEnc + '/' + encodeURIComponent(v.id)
%>
<a class="videoCard" href="<%= shareUrl %>"
@@ -54,6 +55,7 @@
</a>
<% }) %>
</section>
<% } %>
</main>
<div class="ctxMenu" id="ctxMenu" hidden>

View File

@@ -25,18 +25,20 @@
</div>
<div class="dashboardActions">
<% 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>
<% if (isSubFolder) { %>
<a class="primaryButton" href="<%= playlistHref %>">플레이리스트 추가</a>
<% } %>
</div>
</section>
<% if (!isSubFolder && subFolders && subFolders.length > 0) { %>
<% if (!isSubFolder) { %>
<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 %>">
<a class="folderCardLink" href="/op/folder/<%= folderPathEnc %>/<%= encodeURIComponent(sf.name) %>">
<span class="folderIcon">📁</span>
@@ -45,10 +47,9 @@
</div>
<% }) %>
</section>
<% } %>
<% } else { %>
<section class="videoGrid" id="videoGrid">
<% if (videos.length === 0 && (isSubFolder || !subFolders || subFolders.length === 0)) { %>
<% if (videos.length === 0) { %>
<p class="muted">이 폴더에 영상이 없습니다. 우측 상단에서 영상을 추가하세요.</p>
<% } %>
<% videos.forEach(function (v) {
@@ -67,6 +68,7 @@
</div>
<% }) %>
</section>
<% } %>
</main>
<div class="ctxMenu" id="ctxMenu" hidden>
@@ -90,6 +92,7 @@
</div>
</div>
<% if (!isSubFolder) { %>
<div class="modalOverlay" id="addSubFolderModal" hidden>
<div class="modalCard">
<h2>하위 폴더 추가</h2>
@@ -103,6 +106,7 @@
</div>
</div>
</div>
<% } %>
<script>
window.__OP__ = {