mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
added function to trim redundant {,[,( symbols if there is no closing brackets
This commit is contained in:
@@ -10,7 +10,6 @@ export const settingsHost = () => `${torrserverHost}/settings`
|
||||
export const streamHost = () => `${torrserverHost}/stream`
|
||||
export const shutdownHost = () => `${torrserverHost}/shutdown`
|
||||
export const echoHost = () => `${torrserverHost}/echo`
|
||||
export const playlistAllHost = () => `${torrserverHost}/playlistall/all.m3u`
|
||||
export const playlistTorrHost = () => `${torrserverHost}/stream`
|
||||
|
||||
export const getTorrServerHost = () => torrserverHost
|
||||
|
||||
@@ -11,3 +11,33 @@ export function getPeerString(torrent) {
|
||||
|
||||
export const shortenText = (text, sympolAmount) =>
|
||||
text ? text.slice(0, sympolAmount) + (text.length > sympolAmount ? '…' : '') : ''
|
||||
|
||||
export const removeRedundantCharacters = string => {
|
||||
let newString = string
|
||||
const brackets = [
|
||||
['(', ')'],
|
||||
['[', ']'],
|
||||
['{', '}'],
|
||||
]
|
||||
|
||||
brackets.forEach(el => {
|
||||
const leftBracketRegexFormula = `\\${el[0]}`
|
||||
const leftBracketRegex = new RegExp(leftBracketRegexFormula, 'g')
|
||||
const leftBracketAmount = [...newString.matchAll(leftBracketRegex)].length
|
||||
const rightBracketRegexFormula = `\\${el[1]}`
|
||||
const rightBracketRegex = new RegExp(rightBracketRegexFormula, 'g')
|
||||
const rightBracketAmount = [...newString.matchAll(rightBracketRegex)].length
|
||||
|
||||
if (leftBracketAmount !== rightBracketAmount) {
|
||||
const removeFormula = `(\\${el[0]})(?!.*\\1).*`
|
||||
const removeRegex = new RegExp(removeFormula, 'g')
|
||||
newString = newString.replace(removeRegex, '')
|
||||
}
|
||||
})
|
||||
|
||||
const hasThreeDotsAtTheEnd = !!newString.match(/\.{3}$/g)
|
||||
|
||||
const trimmedString = newString.replace(/[\\.| ]+$/g, '').trim()
|
||||
|
||||
return hasThreeDotsAtTheEnd ? `${trimmedString}..` : trimmedString
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user