feat(packs): pack types (resourcepack/datapack/modpack), URL /pack/<type>.zip?domain=<domain>
Files move to <NEXTCLOUD_DIR>/<domain>/<type>.zip; packs.json is {domain: {type: meta}}.
Only resourcepack shows the server.properties snippet; datapack/modpack show the URL.
modpack skips the pack.mcmeta check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -15,7 +15,7 @@ export default function App() {
|
||||
<nav>
|
||||
<NavLink to="/" end>대시보드</NavLink>
|
||||
<NavLink to="/domains">허용 도메인</NavLink>
|
||||
<NavLink to="/packs">리소스팩</NavLink>
|
||||
<NavLink to="/packs">팩</NavLink>
|
||||
<NavLink to="/logs">접속 로그</NavLink>
|
||||
<NavLink to="/settings">설정</NavLink>
|
||||
</nav>
|
||||
|
||||
@@ -39,7 +39,7 @@ export const api = {
|
||||
return req('/logs' + (q ? `?${q}` : ''), { method: 'DELETE' })
|
||||
},
|
||||
packs: () => req('/packs'),
|
||||
deletePack: (name) =>
|
||||
req(`/packs/${encodeURIComponent(name)}`, { method: 'DELETE' }),
|
||||
deletePack: (name, kind) =>
|
||||
req(`/packs/${encodeURIComponent(name)}/${kind}`, { method: 'DELETE' }),
|
||||
restart: () => req('/proxy/restart', { method: 'POST' }),
|
||||
}
|
||||
|
||||
@@ -7,6 +7,17 @@ function fmtSize(n) {
|
||||
return `${n} B`
|
||||
}
|
||||
|
||||
// 종류별로 복사할 텍스트와 안내 문구
|
||||
const HINTS = {
|
||||
resourcepack: '접속하는 클라이언트가 자동으로 받습니다. 아래 줄을 MC 서버 server.properties 에 붙여 넣고 재시작하세요. 팩을 바꾸면 SHA1 도 바뀝니다.',
|
||||
datapack: '클라이언트가 자동으로 받지 않습니다. 받아서 서버 월드의 datapacks 폴더에 넣으세요.',
|
||||
modpack: '플레이어에게 이 주소를 알려 주세요.',
|
||||
}
|
||||
|
||||
function copyText(kind, pack) {
|
||||
return kind === 'resourcepack' ? propsSnippet(pack) : pack.url
|
||||
}
|
||||
|
||||
function propsSnippet(pack) {
|
||||
return [
|
||||
`resource-pack=${pack.url}`,
|
||||
@@ -16,10 +27,10 @@ function propsSnippet(pack) {
|
||||
}
|
||||
|
||||
// fetch 는 업로드 진행률을 못 주므로 XHR 사용
|
||||
function uploadPack(domain, file, onProgress) {
|
||||
function uploadPack(domain, kind, file, onProgress) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.open('PUT', `/api/packs/${encodeURIComponent(domain)}`)
|
||||
xhr.open('PUT', `/api/packs/${encodeURIComponent(domain)}/${kind}`)
|
||||
xhr.upload.onprogress = (e) => {
|
||||
if (e.lengthComputable) onProgress(Math.round((e.loaded / e.total) * 100))
|
||||
}
|
||||
@@ -39,7 +50,7 @@ function uploadPack(domain, file, onProgress) {
|
||||
export default function Packs() {
|
||||
const [data, setData] = useState(null)
|
||||
const [error, setError] = useState(null)
|
||||
const [progress, setProgress] = useState({}) // domain -> %
|
||||
const [progress, setProgress] = useState({}) // "domain/kind" -> %
|
||||
const [copied, setCopied] = useState(null)
|
||||
|
||||
async function load() {
|
||||
@@ -53,38 +64,39 @@ export default function Packs() {
|
||||
|
||||
useEffect(() => { load() }, [])
|
||||
|
||||
async function onFile(domain, e) {
|
||||
async function onFile(domain, kind, e) {
|
||||
const file = e.target.files?.[0]
|
||||
e.target.value = ''
|
||||
if (!file) return
|
||||
setProgress((p) => ({ ...p, [domain]: 0 }))
|
||||
const key = `${domain}/${kind}`
|
||||
setProgress((p) => ({ ...p, [key]: 0 }))
|
||||
try {
|
||||
await uploadPack(domain, file, (pct) => setProgress((p) => ({ ...p, [domain]: pct })))
|
||||
await uploadPack(domain, kind, file, (pct) => setProgress((p) => ({ ...p, [key]: pct })))
|
||||
await load()
|
||||
} catch (err) {
|
||||
setError(err.message)
|
||||
} finally {
|
||||
setProgress((p) => { const n = { ...p }; delete n[domain]; return n })
|
||||
setProgress((p) => { const n = { ...p }; delete n[key]; return n })
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(domain) {
|
||||
if (!confirm(`${domain} 의 리소스팩을 삭제할까요?`)) return
|
||||
async function remove(domain, kind) {
|
||||
if (!confirm(`${domain} 의 ${data.types[kind]}을(를) 삭제할까요?`)) return
|
||||
try {
|
||||
await api.deletePack(domain)
|
||||
await api.deletePack(domain, kind)
|
||||
await load()
|
||||
} catch (e) { setError(e.message) }
|
||||
}
|
||||
|
||||
async function copy(domain, text) {
|
||||
async function copy(key, text) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
setCopied(domain)
|
||||
setCopied(key)
|
||||
setTimeout(() => setCopied(null), 1500)
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1>리소스팩</h1>
|
||||
<h1>팩</h1>
|
||||
{error && <div className="error">{error}</div>}
|
||||
{data && !data.storage_configured && (
|
||||
<div className="error">
|
||||
@@ -92,56 +104,69 @@ export default function Packs() {
|
||||
</div>
|
||||
)}
|
||||
<p className="muted">
|
||||
팩은 share.tkrmagid.kr 에 저장되고 아래 URL 로 공개됩니다. 해당 도메인이 연결된 MC 서버의
|
||||
server.properties 에 설정 줄을 붙여 넣고 서버를 재시작하세요. 팩을 바꾸면 SHA1 이 바뀌므로
|
||||
다시 붙여 넣어야 합니다.
|
||||
팩은 share.tkrmagid.kr 에 저장되고 https://mc.tkrmagid.kr/pack/<종류>.zip?domain=<도메인> 주소로 공개됩니다.
|
||||
</p>
|
||||
|
||||
{data && data.packs.length === 0 && (
|
||||
{data && data.domains.length === 0 && (
|
||||
<div className="card muted">등록된 도메인이 없습니다. 허용 도메인 페이지에서 먼저 추가하세요.</div>
|
||||
)}
|
||||
|
||||
{data?.packs.map(({ domain, pack }) => {
|
||||
const busy = domain in progress
|
||||
return (
|
||||
<section className="card" key={domain}>
|
||||
<h2><code>{domain}</code></h2>
|
||||
{pack ? (
|
||||
<>
|
||||
<div className="muted">
|
||||
{pack.original_name} · {fmtSize(pack.size)} ·{' '}
|
||||
{new Date(pack.uploaded_at * 1000).toLocaleString()}
|
||||
{data?.domains.map(({ domain, packs }) => (
|
||||
<section className="card" key={domain}>
|
||||
<h2><code>{domain}</code></h2>
|
||||
{Object.entries(data.types).map(([kind, label]) => {
|
||||
const pack = packs[kind]
|
||||
const key = `${domain}/${kind}`
|
||||
const busy = key in progress
|
||||
return (
|
||||
<div key={kind} style={{ marginTop: 16 }}>
|
||||
<strong>{label}</strong>{' '}
|
||||
{pack ? (
|
||||
<span className="muted">
|
||||
{pack.original_name} · {fmtSize(pack.size)} ·{' '}
|
||||
{new Date(pack.uploaded_at * 1000).toLocaleString()}
|
||||
</span>
|
||||
) : (
|
||||
<span className="muted">없음</span>
|
||||
)}
|
||||
{pack && (
|
||||
<>
|
||||
<div className="muted">{HINTS[kind]}</div>
|
||||
<textarea
|
||||
readOnly
|
||||
rows={kind === 'resourcepack' ? 3 : 1}
|
||||
value={copyText(kind, pack)}
|
||||
style={{ maxWidth: '100%', fontFamily: 'ui-monospace, Consolas, monospace' }}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<div className="actions">
|
||||
<label>
|
||||
<input
|
||||
type="file"
|
||||
accept=".zip,application/zip"
|
||||
disabled={busy || !data.storage_configured}
|
||||
onChange={(e) => onFile(domain, kind, e)}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
<span className={`btn${busy || !data.storage_configured ? ' disabled' : ''}`}>
|
||||
{busy ? `업로드 중… ${progress[key]}%` : pack ? '교체 업로드' : '업로드'}
|
||||
</span>
|
||||
</label>
|
||||
{pack && (
|
||||
<>
|
||||
<button className="ghost" onClick={() => copy(key, copyText(kind, pack))}>
|
||||
{copied === key ? '복사됨' : kind === 'resourcepack' ? '설정 복사' : '주소 복사'}
|
||||
</button>
|
||||
<button className="danger" onClick={() => remove(domain, kind)} disabled={busy}>삭제</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
<textarea readOnly rows={3} value={propsSnippet(pack)} style={{ maxWidth: '100%', fontFamily: 'ui-monospace, Consolas, monospace' }} />
|
||||
</>
|
||||
) : (
|
||||
<div className="muted">리소스팩 없음</div>
|
||||
)}
|
||||
<div className="actions">
|
||||
<label>
|
||||
<input
|
||||
type="file"
|
||||
accept=".zip,application/zip"
|
||||
disabled={busy || !data.storage_configured}
|
||||
onChange={(e) => onFile(domain, e)}
|
||||
style={{ display: 'none' }}
|
||||
/>
|
||||
<span className={`btn${busy || !data.storage_configured ? ' disabled' : ''}`}>
|
||||
{busy ? `업로드 중… ${progress[domain]}%` : pack ? '교체 업로드' : '업로드'}
|
||||
</span>
|
||||
</label>
|
||||
{pack && (
|
||||
<>
|
||||
<button className="ghost" onClick={() => copy(domain, propsSnippet(pack))}>
|
||||
{copied === domain ? '복사됨' : '설정 복사'}
|
||||
</button>
|
||||
<button className="danger" onClick={() => remove(domain)} disabled={busy}>삭제</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
</section>
|
||||
))}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user