This commit is contained in:
Daniel Shleifman
2021-06-02 22:09:01 +03:00
parent 2ea00f041d
commit c87f8f6101
4 changed files with 12 additions and 36 deletions

View File

@@ -6,38 +6,19 @@ import DialogActions from '@material-ui/core/DialogActions'
import DialogContent from '@material-ui/core/DialogContent' import DialogContent from '@material-ui/core/DialogContent'
import DialogTitle from '@material-ui/core/DialogTitle' import DialogTitle from '@material-ui/core/DialogTitle'
import { torrentsHost } from 'utils/Hosts' import { torrentsHost } from 'utils/Hosts'
import axios from 'axios'
export default function AddDialog({ handleClose }) { export default function AddDialog({ handleClose }) {
const [magnet, setMagnet] = useState('') const [link, setLink] = useState('')
const [title, setTitle] = useState('') const [title, setTitle] = useState('')
const [poster, setPoster] = useState('') const [poster, setPoster] = useState('')
const inputMagnet = ({ target: { value } }) => setMagnet(value) const inputMagnet = ({ target: { value } }) => setLink(value)
const inputTitle = ({ target: { value } }) => setTitle(value) const inputTitle = ({ target: { value } }) => setTitle(value)
const inputPoster = ({ target: { value } }) => setPoster(value) const inputPoster = ({ target: { value } }) => setPoster(value)
const handleCloseSave = () => { const handleSave = () => {
try { axios.post(torrentsHost(), { action: 'add', link, title, poster, save_to_db: true }).finally(() => handleClose())
if (!magnet) return
fetch(torrentsHost(), {
method: 'post',
body: JSON.stringify({
action: 'add',
link: magnet,
title,
poster,
save_to_db: true,
}),
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
})
handleClose()
} catch (e) {
console.log(e)
}
} }
return ( return (
@@ -63,7 +44,7 @@ export default function AddDialog({ handleClose }) {
Cancel Cancel
</Button> </Button>
<Button variant='contained' disabled={!magnet} onClick={handleCloseSave} color='primary'> <Button variant='contained' disabled={!link} onClick={handleSave} color='primary'>
Add Add
</Button> </Button>
</DialogActions> </DialogActions>

View File

@@ -11,6 +11,7 @@ import DialogActions from '@material-ui/core/DialogActions'
import Button from '@material-ui/core/Button' import Button from '@material-ui/core/Button'
import { FormControlLabel, InputLabel, Select, Switch } from '@material-ui/core' import { FormControlLabel, InputLabel, Select, Switch } from '@material-ui/core'
import { settingsHost, setTorrServerHost, getTorrServerHost } from 'utils/Hosts' import { settingsHost, setTorrServerHost, getTorrServerHost } from 'utils/Hosts'
import axios from 'axios'
export default function SettingsDialog() { export default function SettingsDialog() {
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
@@ -22,18 +23,11 @@ export default function SettingsDialog() {
const handleClickOpen = () => setOpen(true) const handleClickOpen = () => setOpen(true)
const handleClose = () => setOpen(false) const handleClose = () => setOpen(false)
const handleCloseSave = () => { const handleSave = () => {
setOpen(false) setOpen(false)
const sets = JSON.parse(JSON.stringify(settings)) const sets = JSON.parse(JSON.stringify(settings))
sets.CacheSize *= 1024 * 1024 sets.CacheSize *= 1024 * 1024
fetch(settingsHost(), { axios.post(settingsHost(), { action: 'set', sets })
method: 'post',
body: JSON.stringify({ action: 'set', sets }),
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
})
} }
useEffect(() => { useEffect(() => {
@@ -262,7 +256,7 @@ export default function SettingsDialog() {
Cancel Cancel
</Button> </Button>
<Button onClick={handleCloseSave} color='primary' variant='outlined'> <Button onClick={handleSave} color='primary' variant='outlined'>
Save Save
</Button> </Button>
</DialogActions> </DialogActions>

View File

@@ -9,6 +9,7 @@ export default function UploadDialog() {
const handleCapture = ({ target: { files } }) => { const handleCapture = ({ target: { files } }) => {
const [file] = files const [file] = files
const data = new FormData() const data = new FormData()
data.append('save', 'true')
data.append('file', file) data.append('file', file)
axios.post(torrentUploadHost(), data) axios.post(torrentUploadHost(), data)
} }

View File

@@ -10,4 +10,4 @@ export function getPeerString(torrent) {
} }
export const shortenText = (text, sympolAmount) => export const shortenText = (text, sympolAmount) =>
text.slice(0, sympolAmount) + (text.length > sympolAmount ? '...' : '') text ? text.slice(0, sympolAmount) + (text.length > sympolAmount ? '...' : '') : ''