45 lines
2.3 KiB
TypeScript
45 lines
2.3 KiB
TypeScript
import { Router } from 'express'
|
|
import { requireAuth } from '../auth.js'
|
|
import { readSettings, writeSettings } from '../settings.js'
|
|
import { logger } from '../logger.js'
|
|
import { readOnboarding, advanceOnboarding, isOnboardingStep } from '../onboarding.js'
|
|
|
|
const router = Router()
|
|
|
|
router.get('/settings/onboarding', requireAuth, (_req, res) => {
|
|
res.json(readOnboarding())
|
|
})
|
|
|
|
router.post('/settings/onboarding', requireAuth, (req, res) => {
|
|
const { step, complete } = req.body ?? {}
|
|
if (step !== undefined && !isOnboardingStep(step)) {
|
|
res.status(400).json({ error: 'Étape inconnue' }); return
|
|
}
|
|
res.json(advanceOnboarding(step, complete === true))
|
|
})
|
|
|
|
router.get('/settings', requireAuth, (_req, res) => {
|
|
res.json(readSettings())
|
|
})
|
|
|
|
router.post('/settings', requireAuth, (req, res) => {
|
|
const { mediaPath, completePath, organizeMode, category, nfoSupport, autoImport, devMode, deleteTorrentOnMove, autoUnimportMissing, requestAutoDownloadUsers, englishDirectory } = req.body
|
|
const patch: Record<string, any> = {}
|
|
if (mediaPath !== undefined) patch.mediaPath = mediaPath
|
|
if (completePath !== undefined) patch.completePath = completePath
|
|
if (organizeMode !== undefined) patch.organizeMode = organizeMode
|
|
if (category !== undefined) patch.category = category
|
|
if (nfoSupport !== undefined) patch.nfoSupport = nfoSupport
|
|
if (autoImport !== undefined) patch.autoImport = autoImport
|
|
if (devMode !== undefined) patch.devMode = devMode
|
|
if (deleteTorrentOnMove !== undefined) patch.deleteTorrentOnMove = deleteTorrentOnMove
|
|
if (autoUnimportMissing !== undefined) patch.autoUnimportMissing = autoUnimportMissing
|
|
if (requestAutoDownloadUsers !== undefined) patch.requestAutoDownloadUsers = requestAutoDownloadUsers
|
|
if (englishDirectory !== undefined) patch.englishDirectory = englishDirectory
|
|
const updated = writeSettings(patch)
|
|
logger.info('api', 'Paramètres mis à jour')
|
|
res.json(updated)
|
|
})
|
|
|
|
export default router
|