mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
torrent source regex added
This commit is contained in:
@@ -35,7 +35,7 @@ import {
|
||||
TorrentIconWrapper,
|
||||
RightSideContainer,
|
||||
} from './style'
|
||||
import { checkImageURL, getMoviePosters } from './helpers'
|
||||
import { checkImageURL, getMoviePosters, chechTorrentSource } from './helpers'
|
||||
|
||||
export default function AddDialog({ handleClose }) {
|
||||
const { t } = useTranslation()
|
||||
@@ -44,6 +44,7 @@ export default function AddDialog({ handleClose }) {
|
||||
const [title, setTitle] = useState('')
|
||||
const [posterUrl, setPosterUrl] = useState('')
|
||||
const [isPosterUrlCorrect, setIsPosterUrlCorrect] = useState(false)
|
||||
const [isTorrentSourceCorrect, setIsTorrentSourceCorrect] = useState(false)
|
||||
const [posterList, setPosterList] = useState()
|
||||
const [isUserInteractedWithPoster, setIsUserInteractedWithPoster] = useState(false)
|
||||
const [isUserInteractedWithTitle, setIsUserInteractedWithTitle] = useState(false)
|
||||
@@ -102,6 +103,10 @@ export default function AddDialog({ handleClose }) {
|
||||
})
|
||||
}, [selectedFile, delayedPosterSearch, torrentSource, posterSearchLanguage, isUserInteractedWithTitle])
|
||||
|
||||
useEffect(() => {
|
||||
setIsTorrentSourceCorrect(chechTorrentSource(torrentSource))
|
||||
}, [torrentSource])
|
||||
|
||||
const handleCapture = files => {
|
||||
const [file] = files
|
||||
if (!file) return
|
||||
@@ -214,7 +219,7 @@ export default function AddDialog({ handleClose }) {
|
||||
</LeftSide>
|
||||
|
||||
<RightSide>
|
||||
<RightSideContainer isHidden={!torrentSource}>
|
||||
<RightSideContainer isHidden={!isTorrentSourceCorrect}>
|
||||
<TextField
|
||||
onChange={handleTitleChange}
|
||||
value={title}
|
||||
@@ -279,7 +284,13 @@ export default function AddDialog({ handleClose }) {
|
||||
</PosterWrapper>
|
||||
</RightSideContainer>
|
||||
|
||||
<RightSideContainer notificationMessage={t('AddTorrentSourceNotification')} isHidden={torrentSource} />
|
||||
<RightSideContainer
|
||||
isError={torrentSource && !isTorrentSourceCorrect}
|
||||
notificationMessage={
|
||||
!torrentSource ? t('AddTorrentSourceNotification') : !isTorrentSourceCorrect && t('WrongTorrentSource')
|
||||
}
|
||||
isHidden={isTorrentSourceCorrect}
|
||||
/>
|
||||
</RightSide>
|
||||
</Content>
|
||||
|
||||
|
||||
@@ -21,3 +21,9 @@ export const checkImageURL = async url => {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
const magnetRegex = /magnet:\?xt=urn:[a-z0-9]{20,50}/i
|
||||
const hashRegex = /\b[0-9a-f]{32}\b|\b[0-9a-f]{40}\b|\b[0-9a-f]{64}\b/i
|
||||
const torrentRegex = /^.*\.(torrent)$/i
|
||||
export const chechTorrentSource = source =>
|
||||
source.match(hashRegex) !== null || source.match(magnetRegex) !== null || source.match(torrentRegex) !== null
|
||||
|
||||
@@ -30,7 +30,7 @@ export const RightSide = styled.div`
|
||||
`
|
||||
|
||||
export const RightSideContainer = styled.div`
|
||||
${({ isHidden, notificationMessage }) => css`
|
||||
${({ isHidden, notificationMessage, isError }) => css`
|
||||
height: 455px;
|
||||
|
||||
${notificationMessage &&
|
||||
@@ -44,7 +44,7 @@ export const RightSideContainer = styled.div`
|
||||
content: '${notificationMessage}';
|
||||
display: grid;
|
||||
place-items: center;
|
||||
background: #84cda7;
|
||||
background: ${isError ? '#cda184' : '#84cda7'};
|
||||
padding: 10px 15px;
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
|
||||
@@ -103,5 +103,6 @@
|
||||
},
|
||||
"TorrentSourceOptions": "magnet / hash / .torrent file link",
|
||||
"Clear": "Clear",
|
||||
"AddTorrentSourceNotification": "First add your torrent source"
|
||||
"AddTorrentSourceNotification": "First add your torrent source",
|
||||
"WrongTorrentSource": "Wrong torrent source"
|
||||
}
|
||||
@@ -101,7 +101,8 @@
|
||||
"Or": "ИЛИ",
|
||||
"ClickOrDrag": "НАЖМИТЕ / ПЕРЕТАЩИТЕ ФАЙЛ (.torrent)"
|
||||
},
|
||||
"TorrentSourceOptions": "магнитная ссылка / хеш / ссылка на .torrent файл",
|
||||
"TorrentSourceOptions": "magnet ссылка / хеш / ссылка на .torrent файл",
|
||||
"Clear": "Очистить",
|
||||
"AddTorrentSourceNotification": "Сначала добавьте торрент источник"
|
||||
"AddTorrentSourceNotification": "Сначала добавьте торрент источник",
|
||||
"WrongTorrentSource": "Неправильный torrent источник"
|
||||
}
|
||||
Reference in New Issue
Block a user