diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx
index b779588..d189aec 100644
--- a/frontend/src/App.jsx
+++ b/frontend/src/App.jsx
@@ -10,7 +10,8 @@ import {
Button,
Toast
} from "react-bootstrap";
-import './App.css'
+import { validateDomain, validateIP } from "./utils";
+import './App.css';
const socket = io(`http://${localStorage.getItem('server-addr') || 'localhost'}:3022`)
@@ -21,6 +22,7 @@ export function App() {
const [halt, setHalt] = useState(false)
const [url, setUrl] = useState('')
const [showToast, setShowToast] = useState(false)
+ const [invalidIP, setInvalidIP] = useState(false)
const [showSettings, setShowSettings] = useState(false)
useEffect(() => {
@@ -58,7 +60,16 @@ export function App() {
}
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 = () => {
@@ -86,22 +97,24 @@ export function App() {
{message}
- {progress ? : null}
+ {progress ? : null}
- {' '}
- {' '}
+ {' '}
+ {' '}
{showSettings ?
<>
Server address
-
+
ws://
:3022
@@ -120,7 +133,7 @@ export function App() {
show={showToast}
onClose={() => setShowToast(false)}
bg={'success'}
- delay={1000}
+ delay={1500}
autohide
className="mt-5"
>
diff --git a/frontend/src/utils.js b/frontend/src/utils.js
new file mode 100644
index 0000000..77ac5ce
--- /dev/null
+++ b/frontend/src/utils.js
@@ -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'
+}
\ No newline at end of file
diff --git a/lib/downloader.js b/lib/downloader.js
index 27a1a7b..90830ae 100644
--- a/lib/downloader.js
+++ b/lib/downloader.js
@@ -1,21 +1,20 @@
-const { spawn } = require('child_process');
-const logger = require('./logger');
-let settings;
+const { spawn } = require('child_process')
+const logger = require('./logger')
+let settings
try {
- settings = require('../settings.json');
+ settings = require('../settings.json')
}
catch (e) {
console.warn("settings.json not found")
}
-const isWindows = process.platform === 'win32';
+const isWindows = process.platform === 'win32'
const download = (socket, url) => {
const ytldp = spawn(`./lib/yt-dlp${isWindows ? '.exe' : ''}`,
['-o', `${settings.download_path || './downloads/'}%(title)s.%(ext)s`, url]
)
-
ytldp.stdout.on('data', data => {
socket.emit('progress', data.toString())
console.log(data.toString())