Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

976 977 993 fix configuration port with custom path #996

Merged
merged 2 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "maintainerr",
"version": "2.0.2",
"private": true,
"packageManager": "yarn@4.0.2",
"packageManager": "yarn@4.1.1",
"repository": {
"type": "git",
"url": "https://github.com/jorenn92/Maintainerr.git"
Expand Down
70 changes: 51 additions & 19 deletions ui/src/components/Settings/Overseerr/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,22 @@
import { SaveIcon } from '@heroicons/react/solid'
import { useContext, useEffect, useRef, useState } from 'react'
import {
useContext,
useEffect,
useRef,
useState,
} from 'react'
import SettingsContext from '../../../contexts/settings-context'
import { PostApiHandler } from '../../../utils/ApiHandler'
import Alert from '../../Common/Alert'
import Button from '../../Common/Button'
import DocsButton from '../../Common/DocsButton'
import TestButton from '../../Common/TestButton'
import {
addPortToUrl,
getPortFromUrl,
handleSettingsInputChange,
removePortFromUrl,
} from '../../../utils/SettingsUtils'

const OverseerrSettings = () => {
const settingsCtx = useContext(SettingsContext)
Expand All @@ -26,36 +37,51 @@ const OverseerrSettings = () => {
}, [])

useEffect(() => {
const url = settingsCtx.settings.overseerr_url?.split(':')
if (url) setHostname(`${url[0]}:${url[1]}`)
}, [settingsCtx])
// hostname
setHostname(removePortFromUrl(settingsCtx.settings.overseerr_url))
// @ts-ignore
hostnameRef.current = {
value: removePortFromUrl(settingsCtx.settings.overseerr_url),
}

useEffect(() => {
const url = settingsCtx.settings.overseerr_url
?.split('')
.reverse()
.join('')
.split(':')[0]
.split('')
.reverse()
.join('')
if (url) setPort(`${url}`)
// port
setPort(getPortFromUrl(settingsCtx.settings.overseerr_url))
// @ts-ignore
portRef.current = {
value: getPortFromUrl(settingsCtx.settings.overseerr_url),
}
}, [settingsCtx])

const submit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()

// if port not specified, but hostname is. Derive the port
if (!portRef.current?.value && hostnameRef.current?.value) {
const derivedPort = hostnameRef.current.value.includes('http://')
? 80
: hostnameRef.current.value.includes('https://')
? 443
: 80

if (derivedPort) {
setPort(derivedPort.toString())
// @ts-ignore
portRef.current = { value: derivedPort.toString() }
}
}

if (
hostnameRef.current?.value &&
apiKeyRef.current?.value &&
portRef.current?.value
) {
const hostnameVal = hostnameRef.current.value.includes('http')
? hostnameRef.current.value
: hostnameRef.current.value.includes('https')
const hostnameVal = hostnameRef.current.value.includes('http://')
? hostnameRef.current.value
: 'http://' + hostnameRef.current.value
: hostnameRef.current.value.includes('https://')
? hostnameRef.current.value
: 'http://' + hostnameRef.current.value
const payload = {
overseerr_url: `${hostnameVal}:${portRef.current.value}`,
overseerr_url: addPortToUrl(hostnameVal, +portRef.current.value),
overseerr_api_key: apiKeyRef.current.value,
}
const resp: { code: 0 | 1; message: string } = await PostApiHandler(
Expand Down Expand Up @@ -122,6 +148,10 @@ const OverseerrSettings = () => {
type="text"
defaultValue={hostname}
ref={hostnameRef}
value={hostnameRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, hostnameRef, setHostname)
}
></input>
</div>
</div>
Expand All @@ -138,7 +168,9 @@ const OverseerrSettings = () => {
id="port"
type="number"
ref={portRef}
value={portRef.current?.value}
defaultValue={port}
onChange={(e) => handleSettingsInputChange(e, portRef, setPort)}
></input>
</div>
</div>
Expand Down
85 changes: 61 additions & 24 deletions ui/src/components/Settings/Radarr/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import Alert from '../../Common/Alert'
import Button from '../../Common/Button'
import DocsButton from '../../Common/DocsButton'
import TestButton from '../../Common/TestButton'
import {
addPortToUrl,
getArrBaseUrl,
getHostname,
getPortFromUrl,
handleSettingsInputChange,
} from '../../../utils/SettingsUtils'

const RadarrSettings = () => {
const settingsCtx = useContext(SettingsContext)
Expand All @@ -27,8 +34,41 @@ const RadarrSettings = () => {
document.title = 'Maintainerr - Settings - Radarr'
}, [])

useEffect(() => {
setHostname(getHostname(settingsCtx.settings.radarr_url))
setBaseUrl(getArrBaseUrl(settingsCtx.settings.radarr_url))
setPort(getPortFromUrl(settingsCtx.settings.radarr_url))

// @ts-ignore
hostnameRef.current = {
value: getHostname(settingsCtx.settings.radarr_url),
}
// @ts-ignore
baseUrlRef.current = {
value: getArrBaseUrl(settingsCtx.settings.radarr_url),
}
// @ts-ignore
portRef.current = { value: getPortFromUrl(settingsCtx.settings.radarr_url) }
}, [settingsCtx])

const submit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()

// if port not specified, but hostname is. Derive the port
if (!portRef.current?.value && hostnameRef.current?.value) {
const derivedPort = hostnameRef.current.value.includes('http://')
? 80
: hostnameRef.current.value.includes('https://')
? 443
: 80

if (derivedPort) {
setPort(derivedPort.toString())
// @ts-ignore
portRef.current = { value: derivedPort.toString() }
}
}

if (
hostnameRef.current?.value &&
portRef.current?.value &&
Expand All @@ -37,10 +77,16 @@ const RadarrSettings = () => {
const hostnameVal = hostnameRef.current.value.includes('http')
? hostnameRef.current.value
: hostnameRef.current.value.includes('https')
? hostnameRef.current.value
: 'http://' + hostnameRef.current.value
? hostnameRef.current.value
: 'http://' + hostnameRef.current.value

let radarr_url = `${addPortToUrl(hostnameVal, +portRef.current.value)}`
radarr_url = radarr_url.endsWith('/')
? radarr_url.slice(0, -1)
: radarr_url

const payload = {
radarr_url: `${hostnameVal}:${portRef.current.value}${
radarr_url: `${radarr_url}${
baseUrlRef.current?.value ? `/${baseUrlRef.current?.value}` : ''
}`,
radarr_api_key: apiKeyRef.current.value,
Expand All @@ -65,27 +111,6 @@ const RadarrSettings = () => {
}
}

useEffect(() => {
const url = settingsCtx.settings.radarr_url?.split(':')
if (url) setHostname(`${url[0]}:${url[1]}`)
}, [settingsCtx])

useEffect(() => {
const url = settingsCtx.settings.radarr_url
?.split('')
.reverse()
.join('')
.split(':')[0]
.split('')
.reverse()
.join('')

const splitted = url?.split('/')

if (splitted?.length > 0) setPort(`${splitted[0]}`)
if (splitted?.length > 1) setBaseUrl(`${splitted[1]}`)
}, [settingsCtx])

const appTest = (result: { status: boolean; version: string }) => {
setTestbanner({ status: result.status, version: result.version })
}
Expand Down Expand Up @@ -131,6 +156,10 @@ const RadarrSettings = () => {
type="text"
ref={hostnameRef}
defaultValue={hostname}
value={hostnameRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, hostnameRef, setHostname)
}
></input>
</div>
</div>
Expand All @@ -148,6 +177,10 @@ const RadarrSettings = () => {
type="number"
ref={portRef}
defaultValue={port}
value={portRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, portRef, setPort)
}
></input>
</div>
</div>
Expand All @@ -165,6 +198,10 @@ const RadarrSettings = () => {
type="text"
ref={baseUrlRef}
defaultValue={baseURl}
value={baseUrlRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, baseUrlRef, setBaseUrl)
}
></input>
</div>
</div>
Expand Down
83 changes: 59 additions & 24 deletions ui/src/components/Settings/Sonarr/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ import Alert from '../../Common/Alert'
import Button from '../../Common/Button'
import DocsButton from '../../Common/DocsButton'
import TestButton from '../../Common/TestButton'
import {
getHostname,
getArrBaseUrl,
getPortFromUrl,
addPortToUrl,
handleSettingsInputChange,
} from '../../../utils/SettingsUtils'

const SonarrSettings = () => {
const settingsCtx = useContext(SettingsContext)
Expand All @@ -27,8 +34,41 @@ const SonarrSettings = () => {
document.title = 'Maintainerr - Settings - Sonarr'
}, [])

useEffect(() => {
setHostname(getHostname(settingsCtx.settings.sonarr_url))
setBaseUrl(getArrBaseUrl(settingsCtx.settings.sonarr_url))
setPort(getPortFromUrl(settingsCtx.settings.sonarr_url))

// @ts-ignore
hostnameRef.current = {
value: getHostname(settingsCtx.settings.sonarr_url),
}
// @ts-ignore
baseUrlRef.current = {
value: getArrBaseUrl(settingsCtx.settings.sonarr_url),
}
// @ts-ignore
portRef.current = { value: getPortFromUrl(settingsCtx.settings.sonarr_url) }
}, [settingsCtx])

const submit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault()

// if port not specified, but hostname is. Derive the port
if (!portRef.current?.value && hostnameRef.current?.value) {
const derivedPort = hostnameRef.current.value.includes('http://')
? 80
: hostnameRef.current.value.includes('https://')
? 443
: 80

if (derivedPort) {
setPort(derivedPort.toString())
// @ts-ignore
portRef.current = { value: derivedPort.toString() }
}
}

if (
hostnameRef.current?.value &&
portRef.current?.value &&
Expand All @@ -37,10 +77,14 @@ const SonarrSettings = () => {
const hostnameVal = hostnameRef.current.value.includes('http')
? hostnameRef.current.value
: hostnameRef.current.value.includes('https')
? hostnameRef.current.value
: 'http://' + hostnameRef.current.value
? hostnameRef.current.value
: 'http://' + hostnameRef.current.value

let url = `${addPortToUrl(hostnameVal, +portRef.current.value)}`
url = url.endsWith('/') ? url.slice(0, -1) : url

const payload = {
sonarr_url: `${hostnameVal}:${portRef.current.value}${
sonarr_url: `${url}${
baseUrlRef.current?.value ? `/${baseUrlRef.current?.value}` : ''
}`,
sonarr_api_key: apiKeyRef.current.value,
Expand All @@ -65,27 +109,6 @@ const SonarrSettings = () => {
}
}

useEffect(() => {
const url = settingsCtx.settings.sonarr_url?.split(':')
if (url) setHostname(`${url[0]}:${url[1]}`)
}, [settingsCtx])

useEffect(() => {
const url = settingsCtx.settings.sonarr_url
?.split('')
.reverse()
.join('')
.split(':')[0]
.split('')
.reverse()
.join('')

const splitted = url?.split('/')

if (splitted?.length > 0) setPort(`${splitted[0]}`)
if (splitted?.length > 1) setBaseUrl(`${splitted[1]}`)
}, [settingsCtx])

const appTest = (result: { status: boolean; version: string }) => {
setTestbanner({ status: result.status, version: result.version })
}
Expand Down Expand Up @@ -131,6 +154,10 @@ const SonarrSettings = () => {
type="text"
ref={hostnameRef}
defaultValue={hostname}
value={hostnameRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, hostnameRef, setHostname)
}
></input>
</div>
</div>
Expand All @@ -148,6 +175,10 @@ const SonarrSettings = () => {
type="number"
ref={portRef}
defaultValue={port}
value={portRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, portRef, setPort)
}
></input>
</div>
</div>
Expand All @@ -165,6 +196,10 @@ const SonarrSettings = () => {
type="text"
ref={baseUrlRef}
defaultValue={baseURl}
value={baseUrlRef.current?.value}
onChange={(e) =>
handleSettingsInputChange(e, baseUrlRef, setBaseUrl)
}
></input>
</div>
</div>
Expand Down
Loading
Loading