small fixes
This commit is contained in:
@@ -10,7 +10,8 @@ import {
|
|||||||
Button,
|
Button,
|
||||||
Toast
|
Toast
|
||||||
} from "react-bootstrap";
|
} from "react-bootstrap";
|
||||||
import './App.css'
|
import { validateDomain, validateIP } from "./utils";
|
||||||
|
import './App.css';
|
||||||
|
|
||||||
const socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`)
|
const socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`)
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ export function App() {
|
|||||||
const [halt, setHalt] = useState(false)
|
const [halt, setHalt] = useState(false)
|
||||||
const [url, setUrl] = useState('')
|
const [url, setUrl] = useState('')
|
||||||
const [showToast, setShowToast] = useState(false)
|
const [showToast, setShowToast] = useState(false)
|
||||||
|
const [invalidIP, setInvalidIP] = useState(false)
|
||||||
const [showSettings, setShowSettings] = useState(false)
|
const [showSettings, setShowSettings] = useState(false)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -58,7 +60,16 @@ export function App() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const handleAddrChange = (e) => {
|
const handleAddrChange = (e) => {
|
||||||
localStorage.setItem('server-addr', e.target.value)
|
const input = e.target.value;
|
||||||
|
if (validateIP(input)) {
|
||||||
|
setInvalidIP(false)
|
||||||
|
localStorage.setItem('server-addr', input)
|
||||||
|
} else if (validateDomain(input)) {
|
||||||
|
setInvalidIP(false)
|
||||||
|
localStorage.setItem('server-addr', input)
|
||||||
|
} else {
|
||||||
|
setInvalidIP(true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const abort = () => {
|
const abort = () => {
|
||||||
@@ -86,22 +97,24 @@ export function App() {
|
|||||||
<pre id='status'>{message}</pre>
|
<pre id='status'>{message}</pre>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{progress ? <ProgressBar className="container-padding" now={progress} variant="success" /> : null}
|
{progress ? <ProgressBar className="container-padding" now={progress} variant="danger" /> : null}
|
||||||
|
|
||||||
<Button className="my-5" variant="success" onClick={() => sendUrl()} disabled={halt}>Go!</Button>{' '}
|
<Button className="my-5" variant="danger" onClick={() => sendUrl()} disabled={halt}>Go!</Button>{' '}
|
||||||
<Button variant="danger" onClick={() => abort()}>Abort</Button>{' '}
|
<Button variant="danger" active onClick={() => abort()}>Abort</Button>{' '}
|
||||||
<Button variant="secondary" onClick={() => setShowSettings(!showSettings)}>Settings</Button>
|
<Button variant="secondary" onClick={() => setShowSettings(!showSettings)}>Settings</Button>
|
||||||
|
|
||||||
{showSettings ?
|
{showSettings ?
|
||||||
<>
|
<>
|
||||||
<h6>Server address</h6>
|
<h6>Server address</h6>
|
||||||
<InputGroup className="mb-3 url-input">
|
<InputGroup className="mb-3 url-input" hasValidation>
|
||||||
<InputGroup.Text>ws://</InputGroup.Text>
|
<InputGroup.Text>ws://</InputGroup.Text>
|
||||||
<FormControl
|
<FormControl
|
||||||
defaultValue={localStorage.getItem('server-addr')}
|
defaultValue={localStorage.getItem('server-addr')}
|
||||||
placeholder="Server address"
|
placeholder="Server address"
|
||||||
aria-label="Server address"
|
aria-label="Server address"
|
||||||
onChange={handleAddrChange}
|
onChange={handleAddrChange}
|
||||||
|
isInvalid={invalidIP}
|
||||||
|
isValid={!invalidIP}
|
||||||
/>
|
/>
|
||||||
<InputGroup.Text>:3022</InputGroup.Text>
|
<InputGroup.Text>:3022</InputGroup.Text>
|
||||||
</InputGroup>
|
</InputGroup>
|
||||||
@@ -120,7 +133,7 @@ export function App() {
|
|||||||
show={showToast}
|
show={showToast}
|
||||||
onClose={() => setShowToast(false)}
|
onClose={() => setShowToast(false)}
|
||||||
bg={'success'}
|
bg={'success'}
|
||||||
delay={1000}
|
delay={1500}
|
||||||
autohide
|
autohide
|
||||||
className="mt-5"
|
className="mt-5"
|
||||||
>
|
>
|
||||||
|
|||||||
9
frontend/src/utils.js
Normal file
9
frontend/src/utils.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
export function validateIP(ipAddr) {
|
||||||
|
let ipRegex = /^(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)(?:\.(?:25[0-5]|2[0-4]\d|1\d\d|[1-9]\d|\d)){3}$/gm
|
||||||
|
return ipRegex.test(ipAddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function validateDomain(domainName) {
|
||||||
|
let domainRegex = /[^@ \t\r\n]+.[^@ \t\r\n]+\.[^@ \t\r\n]+/
|
||||||
|
return domainRegex.test(domainName) || domainName === 'localhost'
|
||||||
|
}
|
||||||
@@ -1,21 +1,20 @@
|
|||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process')
|
||||||
const logger = require('./logger');
|
const logger = require('./logger')
|
||||||
let settings;
|
let settings
|
||||||
|
|
||||||
try {
|
try {
|
||||||
settings = require('../settings.json');
|
settings = require('../settings.json')
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
console.warn("settings.json not found")
|
console.warn("settings.json not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
const isWindows = process.platform === 'win32';
|
const isWindows = process.platform === 'win32'
|
||||||
|
|
||||||
const download = (socket, url) => {
|
const download = (socket, url) => {
|
||||||
const ytldp = spawn(`./lib/yt-dlp${isWindows ? '.exe' : ''}`,
|
const ytldp = spawn(`./lib/yt-dlp${isWindows ? '.exe' : ''}`,
|
||||||
['-o', `${settings.download_path || './downloads/'}%(title)s.%(ext)s`, url]
|
['-o', `${settings.download_path || './downloads/'}%(title)s.%(ext)s`, url]
|
||||||
)
|
)
|
||||||
|
|
||||||
ytldp.stdout.on('data', data => {
|
ytldp.stdout.on('data', data => {
|
||||||
socket.emit('progress', data.toString())
|
socket.emit('progress', data.toString())
|
||||||
console.log(data.toString())
|
console.log(data.toString())
|
||||||
|
|||||||
Reference in New Issue
Block a user