mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
refactor
This commit is contained in:
@@ -31,31 +31,13 @@ export default function SettingsDialog() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(settingsHost(), {
|
axios
|
||||||
method: 'post',
|
.post(settingsHost(), { action: 'get' })
|
||||||
body: JSON.stringify({ action: 'get' }),
|
.then(({ data }) => {
|
||||||
headers: {
|
setSets({ ...data, CacheSize: data.CacheSize / (1024 * 1024) })
|
||||||
Accept: 'application/json, text/plain, */*',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
},
|
|
||||||
})
|
|
||||||
.then(res => res.json())
|
|
||||||
.then(
|
|
||||||
json => {
|
|
||||||
// eslint-disable-next-line no-param-reassign
|
|
||||||
json.CacheSize /= 1024 * 1024
|
|
||||||
setSets(json)
|
|
||||||
setShow(true)
|
setShow(true)
|
||||||
},
|
|
||||||
error => {
|
|
||||||
setShow(false)
|
|
||||||
console.log(error)
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.catch(e => {
|
|
||||||
setShow(false)
|
|
||||||
console.log(e)
|
|
||||||
})
|
})
|
||||||
|
.catch(() => setShow(false))
|
||||||
}, [tsHost])
|
}, [tsHost])
|
||||||
|
|
||||||
const onInputHost = event => {
|
const onInputHost = event => {
|
||||||
@@ -64,18 +46,41 @@ export default function SettingsDialog() {
|
|||||||
setTSHost(host)
|
setTSHost(host)
|
||||||
}
|
}
|
||||||
|
|
||||||
const inputForm = event => {
|
const inputForm = ({ target: { type, value, checked, id } }) => {
|
||||||
const sets = JSON.parse(JSON.stringify(settings))
|
const sets = JSON.parse(JSON.stringify(settings))
|
||||||
if (event.target.type === 'number' || event.target.type === 'select-one') {
|
if (type === 'number' || type === 'select-one') {
|
||||||
sets[event.target.id] = Number(event.target.value)
|
sets[id] = Number(value)
|
||||||
} else if (event.target.type === 'checkbox') {
|
} else if (type === 'checkbox') {
|
||||||
sets[event.target.id] = Boolean(event.target.checked)
|
sets[id] = Boolean(checked)
|
||||||
} else if (event.target.type === 'url') {
|
} else if (type === 'url') {
|
||||||
sets[event.target.id] = event.target.value
|
sets[id] = value
|
||||||
}
|
}
|
||||||
setSets(sets)
|
setSets(sets)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const {
|
||||||
|
CacheSize,
|
||||||
|
PreloadBuffer,
|
||||||
|
ReaderReadAHead,
|
||||||
|
RetrackersMode,
|
||||||
|
TorrentDisconnectTimeout,
|
||||||
|
EnableIPv6,
|
||||||
|
ForceEncrypt,
|
||||||
|
DisableTCP,
|
||||||
|
DisableUTP,
|
||||||
|
DisableUPNP,
|
||||||
|
DisableDHT,
|
||||||
|
DisablePEX,
|
||||||
|
DisableUpload,
|
||||||
|
DownloadRateLimit,
|
||||||
|
UploadRateLimit,
|
||||||
|
ConnectionsLimit,
|
||||||
|
DhtConnectionLimit,
|
||||||
|
PeersListenPort,
|
||||||
|
UseDisk,
|
||||||
|
TorrentsSavePath,
|
||||||
|
} = settings
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<ListItem button key='Settings' onClick={handleClickOpen}>
|
<ListItem button key='Settings' onClick={handleClickOpen}>
|
||||||
@@ -104,14 +109,12 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='CacheSize'
|
id='CacheSize'
|
||||||
label='Cache size'
|
label='Cache size'
|
||||||
value={settings.CacheSize}
|
value={CacheSize}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={<Switch checked={PreloadBuffer} onChange={inputForm} id='PreloadBuffer' color='primary' />}
|
||||||
<Switch checked={settings.PreloadBuffer} onChange={inputForm} id='PreloadBuffer' color='primary' />
|
|
||||||
}
|
|
||||||
label='Preload buffer'
|
label='Preload buffer'
|
||||||
/>
|
/>
|
||||||
<TextField
|
<TextField
|
||||||
@@ -119,14 +122,14 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='ReaderReadAHead'
|
id='ReaderReadAHead'
|
||||||
label='Reader readahead'
|
label='Reader readahead'
|
||||||
value={settings.ReaderReadAHead}
|
value={ReaderReadAHead}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<br />
|
<br />
|
||||||
<InputLabel htmlFor='RetrackersMode'>Retracker mode</InputLabel>
|
<InputLabel htmlFor='RetrackersMode'>Retracker mode</InputLabel>
|
||||||
<Select onChange={inputForm} type='number' native id='RetrackersMode' value={settings.RetrackersMode}>
|
<Select onChange={inputForm} type='number' native id='RetrackersMode' value={RetrackersMode}>
|
||||||
<option value={0}>Don't add retrackers</option>
|
<option value={0}>Don't add retrackers</option>
|
||||||
<option value={1}>Add retrackers</option>
|
<option value={1}>Add retrackers</option>
|
||||||
<option value={2}>Remove retrackers</option>
|
<option value={2}>Remove retrackers</option>
|
||||||
@@ -137,53 +140,47 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='TorrentDisconnectTimeout'
|
id='TorrentDisconnectTimeout'
|
||||||
label='Torrent disconnect timeout'
|
label='Torrent disconnect timeout'
|
||||||
value={settings.TorrentDisconnectTimeout}
|
value={TorrentDisconnectTimeout}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={settings.EnableIPv6} onChange={inputForm} id='EnableIPv6' color='primary' />}
|
control={<Switch checked={EnableIPv6} onChange={inputForm} id='EnableIPv6' color='primary' />}
|
||||||
label='Enable IPv6'
|
label='Enable IPv6'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={<Switch checked={ForceEncrypt} onChange={inputForm} id='ForceEncrypt' color='primary' />}
|
||||||
<Switch checked={settings.ForceEncrypt} onChange={inputForm} id='ForceEncrypt' color='primary' />
|
|
||||||
}
|
|
||||||
label='Force encrypt'
|
label='Force encrypt'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={settings.DisableTCP} onChange={inputForm} id='DisableTCP' color='primary' />}
|
control={<Switch checked={DisableTCP} onChange={inputForm} id='DisableTCP' color='primary' />}
|
||||||
label='Disable TCP'
|
label='Disable TCP'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={settings.DisableUTP} onChange={inputForm} id='DisableUTP' color='primary' />}
|
control={<Switch checked={DisableUTP} onChange={inputForm} id='DisableUTP' color='primary' />}
|
||||||
label='Disable UTP'
|
label='Disable UTP'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={<Switch checked={DisableUPNP} onChange={inputForm} id='DisableUPNP' color='primary' />}
|
||||||
<Switch checked={settings.DisableUPNP} onChange={inputForm} id='DisableUPNP' color='primary' />
|
|
||||||
}
|
|
||||||
label='Disable UPNP'
|
label='Disable UPNP'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={settings.DisableDHT} onChange={inputForm} id='DisableDHT' color='primary' />}
|
control={<Switch checked={DisableDHT} onChange={inputForm} id='DisableDHT' color='primary' />}
|
||||||
label='Disable DHT'
|
label='Disable DHT'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={settings.DisablePEX} onChange={inputForm} id='DisablePEX' color='primary' />}
|
control={<Switch checked={DisablePEX} onChange={inputForm} id='DisablePEX' color='primary' />}
|
||||||
label='Disable PEX'
|
label='Disable PEX'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={<Switch checked={DisableUpload} onChange={inputForm} id='DisableUpload' color='primary' />}
|
||||||
<Switch checked={settings.DisableUpload} onChange={inputForm} id='DisableUpload' color='primary' />
|
|
||||||
}
|
|
||||||
label='Disable upload'
|
label='Disable upload'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
@@ -192,7 +189,7 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='DownloadRateLimit'
|
id='DownloadRateLimit'
|
||||||
label='Download rate limit'
|
label='Download rate limit'
|
||||||
value={settings.DownloadRateLimit}
|
value={DownloadRateLimit}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
@@ -201,7 +198,7 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='UploadRateLimit'
|
id='UploadRateLimit'
|
||||||
label='Upload rate limit'
|
label='Upload rate limit'
|
||||||
value={settings.UploadRateLimit}
|
value={UploadRateLimit}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
@@ -210,7 +207,7 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='ConnectionsLimit'
|
id='ConnectionsLimit'
|
||||||
label='Connections limit'
|
label='Connections limit'
|
||||||
value={settings.ConnectionsLimit}
|
value={ConnectionsLimit}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
@@ -219,7 +216,7 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='DhtConnectionLimit'
|
id='DhtConnectionLimit'
|
||||||
label='Dht connection limit'
|
label='Dht connection limit'
|
||||||
value={settings.DhtConnectionLimit}
|
value={DhtConnectionLimit}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
@@ -228,13 +225,13 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='PeersListenPort'
|
id='PeersListenPort'
|
||||||
label='Peers listen port'
|
label='Peers listen port'
|
||||||
value={settings.PeersListenPort}
|
value={PeersListenPort}
|
||||||
type='number'
|
type='number'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={<Switch checked={settings.UseDisk} onChange={inputForm} id='UseDisk' color='primary' />}
|
control={<Switch checked={UseDisk} onChange={inputForm} id='UseDisk' color='primary' />}
|
||||||
label='Use disk'
|
label='Use disk'
|
||||||
/>
|
/>
|
||||||
<br />
|
<br />
|
||||||
@@ -243,7 +240,7 @@ export default function SettingsDialog() {
|
|||||||
margin='dense'
|
margin='dense'
|
||||||
id='TorrentsSavePath'
|
id='TorrentsSavePath'
|
||||||
label='Torrents save path'
|
label='Torrents save path'
|
||||||
value={settings.TorrentsSavePath}
|
value={TorrentsSavePath}
|
||||||
type='url'
|
type='url'
|
||||||
fullWidth
|
fullWidth
|
||||||
/>
|
/>
|
||||||
|
|||||||
Reference in New Issue
Block a user