Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2fa1173b8e | |||
| 7b532d6520 |
35
electron-builder-dev.yml
Normal file
35
electron-builder-dev.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
appId: kr.tkrmagid.musicquiz.installer.dev
|
||||||
|
productName: MusicQuizInstaller
|
||||||
|
# 개발자용 빌드: manifest 의 public===false 인 pack 만 노출한다.
|
||||||
|
# musicQuizAudience 를 package.json 에 박아 런타임에서 대상(audience)을 판별.
|
||||||
|
extraMetadata:
|
||||||
|
main: dist/installer/main.js
|
||||||
|
musicQuizAudience: developer
|
||||||
|
directories:
|
||||||
|
output: release
|
||||||
|
buildResources: build
|
||||||
|
files:
|
||||||
|
- dist/installer/**
|
||||||
|
- dist/shared/**
|
||||||
|
- installer/**
|
||||||
|
- build/icon.*
|
||||||
|
- package.json
|
||||||
|
- "!node_modules/@img/sharp-linux-*"
|
||||||
|
- "!node_modules/@img/sharp-linuxmusl-*"
|
||||||
|
- "!node_modules/@img/sharp-libvips-linux-*"
|
||||||
|
- "!node_modules/@img/sharp-libvips-linuxmusl-*"
|
||||||
|
extraResources:
|
||||||
|
- from: .
|
||||||
|
to: .
|
||||||
|
filter:
|
||||||
|
- .env.build
|
||||||
|
- from: locales
|
||||||
|
to: locales
|
||||||
|
filter:
|
||||||
|
- "**/*"
|
||||||
|
win:
|
||||||
|
target: portable
|
||||||
|
artifactName: MusicQuizInstaller-Dev-${version}-Portable.${ext}
|
||||||
|
icon: build/icon.ico
|
||||||
|
portable:
|
||||||
|
artifactName: MusicQuizInstaller-Dev-${version}-Portable.${ext}
|
||||||
35
electron-builder-rp-dev.yml
Normal file
35
electron-builder-rp-dev.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
appId: kr.tkrmagid.musicquiz.installer-rp.dev
|
||||||
|
productName: MusicQuizResourcepackInstaller
|
||||||
|
# 개발자용 리소스팩 설치기: manifest 의 public===false 인 pack 만 노출.
|
||||||
|
extraMetadata:
|
||||||
|
main: dist/installer-rp/main.js
|
||||||
|
musicQuizAudience: developer
|
||||||
|
directories:
|
||||||
|
output: release
|
||||||
|
buildResources: build
|
||||||
|
files:
|
||||||
|
- dist/installer-rp/**
|
||||||
|
- dist/shared/**
|
||||||
|
- installer-rp/**
|
||||||
|
- installer/styles.css
|
||||||
|
- build/icon.*
|
||||||
|
- package.json
|
||||||
|
- "!node_modules/@img/sharp-linux-*"
|
||||||
|
- "!node_modules/@img/sharp-linuxmusl-*"
|
||||||
|
- "!node_modules/@img/sharp-libvips-linux-*"
|
||||||
|
- "!node_modules/@img/sharp-libvips-linuxmusl-*"
|
||||||
|
extraResources:
|
||||||
|
- from: .
|
||||||
|
to: .
|
||||||
|
filter:
|
||||||
|
- .env.build
|
||||||
|
- from: locales
|
||||||
|
to: locales
|
||||||
|
filter:
|
||||||
|
- "**/*"
|
||||||
|
win:
|
||||||
|
target: portable
|
||||||
|
artifactName: MusicQuizResourcepackInstaller-Dev-${version}-Portable.${ext}
|
||||||
|
icon: build/icon.ico
|
||||||
|
portable:
|
||||||
|
artifactName: MusicQuizResourcepackInstaller-Dev-${version}-Portable.${ext}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "minecraft-music-quiz-installer",
|
"name": "minecraft-music-quiz-installer",
|
||||||
"version": "0.3.19",
|
"version": "0.3.21",
|
||||||
"description": "마인크래프트 음악퀴즈 간편설치기 + 관리 사이트",
|
"description": "마인크래프트 음악퀴즈 간편설치기 + 관리 사이트",
|
||||||
"main": "dist/installer/main.js",
|
"main": "dist/installer/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -14,7 +14,9 @@
|
|||||||
"build:launcher-icon": "node scripts/build-launcher-icon.cjs",
|
"build:launcher-icon": "node scripts/build-launcher-icon.cjs",
|
||||||
"dist:win": "npm run preinstall:sharp-win32 && npm run build:launcher-icon && tsc -p tsconfig.installer.json && electron-builder --win --config electron-builder.yml",
|
"dist:win": "npm run preinstall:sharp-win32 && npm run build:launcher-icon && tsc -p tsconfig.installer.json && electron-builder --win --config electron-builder.yml",
|
||||||
"dist:win:rp": "npm run preinstall:sharp-win32 && tsc -p tsconfig.installer-rp.json && electron-builder --win --config electron-builder-rp.yml",
|
"dist:win:rp": "npm run preinstall:sharp-win32 && tsc -p tsconfig.installer-rp.json && electron-builder --win --config electron-builder-rp.yml",
|
||||||
"dist:win:pf": "tsc -p tsconfig.installer-pf.json && electron-builder --win --config electron-builder-pf.yml"
|
"dist:win:pf": "tsc -p tsconfig.installer-pf.json && electron-builder --win --config electron-builder-pf.yml",
|
||||||
|
"dist:win:dev": "npm run preinstall:sharp-win32 && npm run build:launcher-icon && tsc -p tsconfig.installer.json && electron-builder --win --config electron-builder-dev.yml",
|
||||||
|
"dist:win:rp:dev": "npm run preinstall:sharp-win32 && tsc -p tsconfig.installer-rp.json && electron-builder --win --config electron-builder-rp-dev.yml"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/archiver": "^7.0.0",
|
"@types/archiver": "^7.0.0",
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import { normalizePackDefinition } from '../shared/store.js'
|
|||||||
import { getAppDataDir, getMcCustomDir } from '../shared/paths.js'
|
import { getAppDataDir, getMcCustomDir } from '../shared/paths.js'
|
||||||
import { loadEnv, getManifestUrl } from '../shared/env.js'
|
import { loadEnv, getManifestUrl } from '../shared/env.js'
|
||||||
import { loadComponentI18n } from '../shared/i18n.js'
|
import { loadComponentI18n } from '../shared/i18n.js'
|
||||||
|
import { resolveAudience, isPackVisibleForAudience, type Audience } from '../shared/audience.js'
|
||||||
import type { RpFetchedPack } from './types.js'
|
import type { RpFetchedPack } from './types.js'
|
||||||
import { ensureYtDlpExe } from './ytdlp.js'
|
import { ensureYtDlpExe } from './ytdlp.js'
|
||||||
import { ensureFfmpegExe } from './ffmpeg.js'
|
import { ensureFfmpegExe } from './ffmpeg.js'
|
||||||
@@ -112,6 +113,16 @@ const state: RpInstallerState = {
|
|||||||
|
|
||||||
let mainWindow: BrowserWindow | null = null
|
let mainWindow: BrowserWindow | null = null
|
||||||
|
|
||||||
|
// 이 빌드의 대상(일반/개발자용). package.json 의 musicQuizAudience 로 결정.
|
||||||
|
function getAudience(): Audience {
|
||||||
|
try {
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(path.join(app.getAppPath(), 'package.json'), 'utf8'))
|
||||||
|
return resolveAudience(pkg.musicQuizAudience)
|
||||||
|
} catch {
|
||||||
|
return resolveAudience(undefined)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function deriveBaseUrl(manifestUrl: string): string {
|
function deriveBaseUrl(manifestUrl: string): string {
|
||||||
try {
|
try {
|
||||||
const parsed = new URL(manifestUrl)
|
const parsed = new URL(manifestUrl)
|
||||||
@@ -202,9 +213,12 @@ ipcMain.handle('rp:packs:load', async (_event, manifestUrlInput?: string): Promi
|
|||||||
}
|
}
|
||||||
sendLog(t('log.manifestDownload', { url: state.manifestUrl }))
|
sendLog(t('log.manifestDownload', { url: state.manifestUrl }))
|
||||||
const manifest = await fetchJson<Manifest>(state.manifestUrl)
|
const manifest = await fetchJson<Manifest>(state.manifestUrl)
|
||||||
|
const audience = getAudience()
|
||||||
const results: RpFetchedPack[] = []
|
const results: RpFetchedPack[] = []
|
||||||
for (const entry of manifest.packs ?? []) {
|
for (const entry of manifest.packs ?? []) {
|
||||||
if (typeof entry?.file !== 'string') continue
|
if (typeof entry?.file !== 'string') continue
|
||||||
|
// 대상(audience)에 맞지 않는 pack 은 건너뛴다(일반=public, 개발자용=non-public).
|
||||||
|
if (!isPackVisibleForAudience(entry.public, audience)) continue
|
||||||
const listUrl = `${state.baseUrl}/file/list/${encodeURIComponent(entry.file)}.json`
|
const listUrl = `${state.baseUrl}/file/list/${encodeURIComponent(entry.file)}.json`
|
||||||
const packUrl = `${state.baseUrl}/manifest/${encodeURIComponent(entry.file)}.json`
|
const packUrl = `${state.baseUrl}/manifest/${encodeURIComponent(entry.file)}.json`
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -22,10 +22,21 @@ import type { Manifest, PackDefinition } from '../shared/types.js'
|
|||||||
import { normalizePackDefinition } from '../shared/store.js'
|
import { normalizePackDefinition } from '../shared/store.js'
|
||||||
import { loadEnv, getManifestUrl } from '../shared/env.js'
|
import { loadEnv, getManifestUrl } from '../shared/env.js'
|
||||||
import { loadComponentI18n } from '../shared/i18n.js'
|
import { loadComponentI18n } from '../shared/i18n.js'
|
||||||
|
import { resolveAudience, isPackVisibleForAudience, type Audience } from '../shared/audience.js'
|
||||||
import { LAUNCHER_PROFILE_ICON } from './launcherIcon.js'
|
import { LAUNCHER_PROFILE_ICON } from './launcherIcon.js'
|
||||||
|
|
||||||
loadEnv()
|
loadEnv()
|
||||||
|
|
||||||
|
// 이 빌드의 대상(일반/개발자용). package.json 의 musicQuizAudience 로 결정.
|
||||||
|
function getAudience(): Audience {
|
||||||
|
try {
|
||||||
|
const pkg = JSON.parse(fs.readFileSync(path.join(app.getAppPath(), 'package.json'), 'utf8'))
|
||||||
|
return resolveAudience(pkg.musicQuizAudience)
|
||||||
|
} catch {
|
||||||
|
return resolveAudience(undefined)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const i18n = loadComponentI18n('installer')
|
const i18n = loadComponentI18n('installer')
|
||||||
const t = i18n.t
|
const t = i18n.t
|
||||||
export const localeDict = i18n.dict
|
export const localeDict = i18n.dict
|
||||||
@@ -136,9 +147,12 @@ ipcMain.handle('packs:load', async (_event, manifestUrlInput?: string): Promise<
|
|||||||
}
|
}
|
||||||
sendLog(t('log.manifestDownload', { url: state.manifestUrl }))
|
sendLog(t('log.manifestDownload', { url: state.manifestUrl }))
|
||||||
const manifest = await fetchJson<Manifest>(state.manifestUrl)
|
const manifest = await fetchJson<Manifest>(state.manifestUrl)
|
||||||
|
const audience = getAudience()
|
||||||
const results: FetchedPack[] = []
|
const results: FetchedPack[] = []
|
||||||
for (const entry of manifest.packs ?? []) {
|
for (const entry of manifest.packs ?? []) {
|
||||||
if (typeof entry?.file !== 'string') continue
|
if (typeof entry?.file !== 'string') continue
|
||||||
|
// 대상(audience)에 맞지 않는 pack 은 건너뛴다(일반=public, 개발자용=non-public).
|
||||||
|
if (!isPackVisibleForAudience(entry.public, audience)) continue
|
||||||
const packUrl = `${state.baseUrl}/manifest.json`.replace(/manifest\.json$/, `manifest/${entry.file}.json`)
|
const packUrl = `${state.baseUrl}/manifest.json`.replace(/manifest\.json$/, `manifest/${entry.file}.json`)
|
||||||
try {
|
try {
|
||||||
const raw = await fetchJson<Partial<PackDefinition>>(packUrl)
|
const raw = await fetchJson<Partial<PackDefinition>>(packUrl)
|
||||||
@@ -603,83 +617,10 @@ ipcMain.handle('server:install', async (_event, payload: ServerInstallPayload) =
|
|||||||
await downloadServerZip(pack.pack, installPath)
|
await downloadServerZip(pack.pack, installPath)
|
||||||
// 다운로드한 zip에 들어있을 수 있는 eula.txt를 그대로 보존한다.
|
// 다운로드한 zip에 들어있을 수 있는 eula.txt를 그대로 보존한다.
|
||||||
// 동의 흐름은 renderer가 별도 IPC로 읽고 동의 시 덮어쓴다.
|
// 동의 흐름은 renderer가 별도 IPC로 읽고 동의 시 덮어쓴다.
|
||||||
|
// 설치기는 포트를 직접 열지 않는다(요청). run.bat 에 UPnP 자동 개방을 주입하지
|
||||||
// run.bat 에 서버 기동/종료시 UPnP 자동 등록/해제 로직 주입.
|
// 않으며, 사용자가 라우터에서 수동 포워딩을 하고 포트포워딩 페이지에서 확인만 한다.
|
||||||
// 이렇게 해야 서버가 안 떠 있는 동안에는 포트가 닫혀 있게 된다.
|
|
||||||
await injectUpnpToRunBat(installPath)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* 추출된 서버 zip 의 run.bat 에 UPnP 자동 등록(서버 시작 시) / 자동 해제(서버 종료 후)
|
|
||||||
* 스크립트를 끼워 넣는다. 이미 우리가 주입했던 마커가 있으면 다시 건드리지 않는다.
|
|
||||||
*
|
|
||||||
* 동작:
|
|
||||||
* 1) 서버 시작 직전: server.properties 의 server-port 값(없으면 25565) 으로 PowerShell
|
|
||||||
* 을 통해 HNetCfg.NATUPnP.1 COM 객체를 이용해 정적 포트 매핑 추가.
|
|
||||||
* 2) 서버 프로세스 종료 후(=pause 직전 또는 파일 끝): 동일한 포트의 매핑 제거.
|
|
||||||
*
|
|
||||||
* 제한: 사용자가 콘솔 창을 X 버튼으로 강제 종료하면 teardown 이 실행되지 않는다.
|
|
||||||
* 이 경우 라우터의 UPnP TTL 에 의해 자동 만료되며, 다음 실행 시 Add 전에 Remove 를
|
|
||||||
* 시도하므로 idempotent.
|
|
||||||
*/
|
|
||||||
async function injectUpnpToRunBat(installPath: string): Promise<void> {
|
|
||||||
const runBat = path.join(installPath, 'run.bat')
|
|
||||||
if (!fs.existsSync(runBat)) {
|
|
||||||
sendLog(t('log.runBatMissing'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const MARKER = 'REM === UPNP MANAGED BY MUSICQUIZ INSTALLER ==='
|
|
||||||
const original = await fsp.readFile(runBat, 'utf8')
|
|
||||||
if (original.includes(MARKER)) {
|
|
||||||
sendLog(t('log.runBatAlreadyInjected'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const lines = original.split(/\r?\n/)
|
|
||||||
const javaIdx = lines.findIndex((line) => /^\s*java(\.exe)?[\s"]/i.test(line))
|
|
||||||
if (javaIdx === -1) {
|
|
||||||
sendLog(t('log.runBatNoJava'))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
let pauseIdx = -1
|
|
||||||
for (let i = javaIdx + 1; i < lines.length; i++) {
|
|
||||||
if (/^\s*pause\b/i.test(lines[i])) { pauseIdx = i; break }
|
|
||||||
}
|
|
||||||
if (pauseIdx === -1) pauseIdx = lines.length
|
|
||||||
|
|
||||||
|
|
||||||
// PowerShell 한 줄로 처리: server.properties 의 server-port 우선, 없으면 25565.
|
|
||||||
// Add 전에 같은 포트의 매핑이 남아 있으면 먼저 Remove 하여 idempotent 하게 만든다.
|
|
||||||
const addBlock = [
|
|
||||||
MARKER,
|
|
||||||
'REM 서버 시작 직전: server-port 추출 후 UPnP 매핑 등록.',
|
|
||||||
'set "_MQ_PORT=25565"',
|
|
||||||
'for /f "tokens=2 delims==" %%a in (\'findstr /b /c:"server-port=" server.properties 2^>nul\') do set "_MQ_PORT=%%a"',
|
|
||||||
'set "_MQ_PORT=%_MQ_PORT: =%"',
|
|
||||||
'echo [MusicQuiz] UPnP 등록 시도: TCP %_MQ_PORT%',
|
|
||||||
'powershell -NoProfile -Command "$port=[int]$env:_MQ_PORT; $ip=(Get-NetIPAddress -AddressFamily IPv4 -PrefixOrigin Dhcp,Manual -ErrorAction SilentlyContinue | Where-Object {$_.IPAddress -notlike \'169.254.*\' -and $_.IPAddress -ne \'127.0.0.1\'} | Select-Object -First 1).IPAddress; if (-not $ip) { Write-Host \'[MusicQuiz] 로컬 IPv4 검색 실패\'; exit 1 }; try { $u = New-Object -ComObject HNetCfg.NATUPnP.1; $c=$u.StaticPortMappingCollection; if ($c) { try { $c.Remove($port,\'TCP\') | Out-Null } catch {}; $c.Add($port,\'TCP\',$port,$ip,$true,\'MusicQuiz Minecraft Server\') | Out-Null; Write-Host (\'[MusicQuiz] UPnP 등록 성공: \' + $ip + \':\' + $port + \' TCP\') } else { Write-Host \'[MusicQuiz] UPnP 컬렉션 사용 불가(라우터 UPnP 꺼짐?)\' } } catch { Write-Host (\'[MusicQuiz] UPnP 등록 실패: \' + $_.Exception.Message) }"'
|
|
||||||
]
|
|
||||||
|
|
||||||
const removeBlock = [
|
|
||||||
'REM 서버 종료 후: UPnP 매핑 해제.',
|
|
||||||
'echo [MusicQuiz] UPnP 해제 시도: TCP %_MQ_PORT%',
|
|
||||||
'powershell -NoProfile -Command "$port=[int]$env:_MQ_PORT; try { $u = New-Object -ComObject HNetCfg.NATUPnP.1; $c=$u.StaticPortMappingCollection; if ($c) { $c.Remove($port,\'TCP\') | Out-Null; Write-Host (\'[MusicQuiz] UPnP 해제 완료: TCP \' + $port) } } catch { Write-Host (\'[MusicQuiz] UPnP 해제 실패: \' + $_.Exception.Message) }"'
|
|
||||||
]
|
|
||||||
|
|
||||||
const merged: string[] = []
|
|
||||||
merged.push(...lines.slice(0, javaIdx))
|
|
||||||
merged.push(...addBlock)
|
|
||||||
merged.push(lines[javaIdx])
|
|
||||||
merged.push(...lines.slice(javaIdx + 1, pauseIdx))
|
|
||||||
merged.push(...removeBlock)
|
|
||||||
merged.push(...lines.slice(pauseIdx))
|
|
||||||
|
|
||||||
// bat 파일은 CRLF 가 안전.
|
|
||||||
const output = merged.join('\r\n')
|
|
||||||
await fsp.writeFile(runBat, output, 'utf8')
|
|
||||||
sendLog(t('log.runBatInjected'))
|
|
||||||
}
|
|
||||||
|
|
||||||
ipcMain.handle('server:readEula', async (_event, installPath: string): Promise<{ exists: boolean; content: string }> => {
|
ipcMain.handle('server:readEula', async (_event, installPath: string): Promise<{ exists: boolean; content: string }> => {
|
||||||
if (!installPath) return { exists: false, content: '' }
|
if (!installPath) return { exists: false, content: '' }
|
||||||
const target = path.join(path.resolve(installPath), 'eula.txt')
|
const target = path.join(path.resolve(installPath), 'eula.txt')
|
||||||
|
|||||||
@@ -16,10 +16,12 @@ import {
|
|||||||
normalizePackDefinition,
|
normalizePackDefinition,
|
||||||
normalizePackList,
|
normalizePackList,
|
||||||
readAccounts,
|
readAccounts,
|
||||||
|
readManifest,
|
||||||
renamePack,
|
renamePack,
|
||||||
sanitizePackKey,
|
sanitizePackKey,
|
||||||
saveTerm,
|
saveTerm,
|
||||||
savePackList,
|
savePackList,
|
||||||
|
setPackPublic,
|
||||||
setTermVisibility
|
setTermVisibility
|
||||||
} from '../../shared/store.js'
|
} from '../../shared/store.js'
|
||||||
import { fetchReleaseVersions } from '../../shared/mojang.js'
|
import { fetchReleaseVersions } from '../../shared/mojang.js'
|
||||||
@@ -122,11 +124,15 @@ opRouter.get('/op/dashboard/:packName', requireAuth, async (req, res, next) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const releases = await fetchReleaseVersions()
|
const releases = await fetchReleaseVersions()
|
||||||
|
const manifest = await readManifest()
|
||||||
|
const entry = manifest.packs.find((e) => e.file === packKey)
|
||||||
|
const isPublic = entry ? entry.public !== false : true
|
||||||
res.render('op/editor', {
|
res.render('op/editor', {
|
||||||
userId: req.session.userId,
|
userId: req.session.userId,
|
||||||
packKey,
|
packKey,
|
||||||
pack: definition,
|
pack: definition,
|
||||||
releases
|
releases,
|
||||||
|
isPublic
|
||||||
})
|
})
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error)
|
next(error)
|
||||||
@@ -519,6 +525,9 @@ opRouter.post('/op/dashboard/:packName', requireAuth, async (req, res, next) =>
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
const finalKey = await renamePack(packKey, requestedKey, normalized)
|
const finalKey = await renamePack(packKey, requestedKey, normalized)
|
||||||
|
// 체크박스는 체크됐을 때만 전송되므로, 없으면 비공개(개발자용).
|
||||||
|
const isPublic = pickFirstValue(req.body.isPublic) === 'on' || pickFirstValue(req.body.isPublic) === 'true'
|
||||||
|
await setPackPublic(finalKey, isPublic)
|
||||||
res.redirect(`/op/dashboard/${finalKey}`)
|
res.redirect(`/op/dashboard/${finalKey}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error)
|
next(error)
|
||||||
|
|||||||
20
src/shared/audience.ts
Normal file
20
src/shared/audience.ts
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
// 설치기 "대상(audience)" 구분. 빌드 시 package.json 에 박히는 musicQuizAudience
|
||||||
|
// 값으로 결정한다(electron-builder extraMetadata).
|
||||||
|
// - 'public' : 일반 설치기. manifest 의 public!==false 인 pack 만 노출.
|
||||||
|
// - 'developer' : 개발자용 설치기. public===false 인 pack 만 노출.
|
||||||
|
// 이 모듈은 electron 에 의존하지 않는 순수 로직만 둔다(server 빌드에도 포함되므로).
|
||||||
|
|
||||||
|
export type Audience = 'public' | 'developer'
|
||||||
|
|
||||||
|
export function resolveAudience(raw: unknown): Audience {
|
||||||
|
return raw === 'developer' ? 'developer' : 'public'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 주어진 pack 의 public 플래그가 현재 audience 에게 보여야 하는지.
|
||||||
|
* public 미지정(undefined)은 공개로 간주한다(하위호환).
|
||||||
|
*/
|
||||||
|
export function isPackVisibleForAudience(isPublic: boolean | undefined, audience: Audience): boolean {
|
||||||
|
const isPublicPack = isPublic !== false
|
||||||
|
return audience === 'developer' ? !isPublicPack : isPublicPack
|
||||||
|
}
|
||||||
@@ -18,8 +18,15 @@ export async function readManifest(): Promise<Manifest> {
|
|||||||
return { packs: [] }
|
return { packs: [] }
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
packs: parsed.packs.filter((entry): entry is ManifestEntry =>
|
packs: parsed.packs
|
||||||
|
.filter((entry): entry is ManifestEntry =>
|
||||||
typeof entry?.name === 'string' && typeof entry?.file === 'string')
|
typeof entry?.name === 'string' && typeof entry?.file === 'string')
|
||||||
|
.map((entry) => ({
|
||||||
|
name: entry.name,
|
||||||
|
file: entry.file,
|
||||||
|
// public 은 명시적 boolean 만 보존. 미지정은 그대로 undefined(=공개 취급).
|
||||||
|
...(typeof entry.public === 'boolean' ? { public: entry.public } : {})
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
if ((error as NodeJS.ErrnoException).code === 'ENOENT') {
|
||||||
@@ -245,15 +252,32 @@ type ManifestSyncAction = 'add' | 'remove' | 'upsert'
|
|||||||
|
|
||||||
async function syncManifestWith(key: string, name: string, action: ManifestSyncAction): Promise<void> {
|
async function syncManifestWith(key: string, name: string, action: ManifestSyncAction): Promise<void> {
|
||||||
const manifest = await readManifest()
|
const manifest = await readManifest()
|
||||||
|
const existing = manifest.packs.find((entry) => entry.file === key)
|
||||||
const filtered = manifest.packs.filter((entry) => entry.file !== key)
|
const filtered = manifest.packs.filter((entry) => entry.file !== key)
|
||||||
if (action === 'remove') {
|
if (action === 'remove') {
|
||||||
await writeManifest({ packs: filtered })
|
await writeManifest({ packs: filtered })
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
filtered.push({ name: name || key, file: key })
|
const entry: ManifestEntry = { name: name || key, file: key }
|
||||||
|
// 기존 public 값은 이름 변경/수정(upsert) 시에도 보존. 신규(add)는 기본 공개(true).
|
||||||
|
entry.public = existing && typeof existing.public === 'boolean' ? existing.public : true
|
||||||
|
filtered.push(entry)
|
||||||
await writeManifest({ packs: filtered })
|
await writeManifest({ packs: filtered })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** manifest 엔트리의 public(공개 여부) 플래그를 설정한다. */
|
||||||
|
export async function setPackPublic(key: string, isPublic: boolean): Promise<void> {
|
||||||
|
const manifest = await readManifest()
|
||||||
|
let changed = false
|
||||||
|
for (const entry of manifest.packs) {
|
||||||
|
if (entry.file === key) {
|
||||||
|
entry.public = isPublic
|
||||||
|
changed = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (changed) await writeManifest(manifest)
|
||||||
|
}
|
||||||
|
|
||||||
function defaultPackList(): PackList {
|
function defaultPackList(): PackList {
|
||||||
return { musicPlaylistUrl: '', imagePlaylistUrl: '', music: [], images: [] }
|
return { musicPlaylistUrl: '', imagePlaylistUrl: '', music: [], images: [] }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,6 +37,11 @@ export interface PackDefinition {
|
|||||||
export interface ManifestEntry {
|
export interface ManifestEntry {
|
||||||
name: string
|
name: string
|
||||||
file: string
|
file: string
|
||||||
|
/**
|
||||||
|
* 공개 여부. true(또는 미지정)면 일반 설치기(간편/리소스팩)에 노출,
|
||||||
|
* false 면 개발자용 설치기에만 노출된다. 하위호환: 값이 없으면 공개로 간주.
|
||||||
|
*/
|
||||||
|
public?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Manifest {
|
export interface Manifest {
|
||||||
|
|||||||
@@ -30,6 +30,11 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label style="display:flex;align-items:center;gap:10px;margin:8px 0;">
|
||||||
|
<input type="checkbox" name="isPublic" <%= (typeof isPublic === 'undefined' || isPublic) ? 'checked' : '' %> style="width:auto;" />
|
||||||
|
<span>공개 (체크 시 일반 설치기에 표시 / 해제 시 개발자용 설치기에만 표시)</span>
|
||||||
|
</label>
|
||||||
|
|
||||||
<div class="gridTwo">
|
<div class="gridTwo">
|
||||||
<label>
|
<label>
|
||||||
<span><%= t('editor.mcVersion') %></span>
|
<span><%= t('editor.mcVersion') %></span>
|
||||||
|
|||||||
Reference in New Issue
Block a user