diff --git a/src/components/AppShelf/AddAppShelfItem.tsx b/src/components/AppShelf/AddAppShelfItem.tsx index d6b3b9bc3..2d41feaee 100644 --- a/src/components/AppShelf/AddAppShelfItem.tsx +++ b/src/components/AppShelf/AddAppShelfItem.tsx @@ -22,7 +22,7 @@ import { IconApps as Apps } from '@tabler/icons'; import { useEffect, useState } from 'react'; import { v4 as uuidv4 } from 'uuid'; import { useConfig } from '../../tools/state'; -import { ServiceTypeList, StatusCodes } from '../../tools/types'; +import { tryMatchPort, ServiceTypeList, StatusCodes } from '../../tools/types'; import Tip from '../layout/Tip'; export function AddItemShelfButton(props: any) { @@ -77,24 +77,6 @@ function MatchService(name: string, form: any) { } } -function MatchPort(name: string, form: any) { - const portmap = [ - { name: 'qbittorrent', value: '8080' }, - { name: 'sonarr', value: '8989' }, - { name: 'radarr', value: '7878' }, - { name: 'lidarr', value: '8686' }, - { name: 'readarr', value: '8787' }, - { name: 'deluge', value: '8112' }, - { name: 'transmission', value: '9091' }, - { name: 'dash.', value: '3001' }, - ]; - // Match name with portmap key - const port = portmap.find((p) => p.name === name.toLowerCase()); - if (port) { - form.setFieldValue('url', `http://localhost:${port.value}`); - } -} - const DEFAULT_ICON = '/favicon.svg'; export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & any) { @@ -154,7 +136,7 @@ export function AddAppShelfItemForm(props: { setOpened: (b: boolean) => void } & if (form.values.name !== debounced || form.values.icon !== DEFAULT_ICON) return; MatchIcon(form.values.name, form); MatchService(form.values.name, form); - MatchPort(form.values.name, form); + tryMatchPort(form.values.name, form); }, [debounced]); // Try to set const hostname to new URL(form.values.url).hostname) diff --git a/src/tools/addToHomarr.ts b/src/tools/addToHomarr.ts index ec966d4d9..08075683b 100644 --- a/src/tools/addToHomarr.ts +++ b/src/tools/addToHomarr.ts @@ -1,5 +1,5 @@ import Dockerode from 'dockerode'; -import { Config, MatchingImages, ServiceType } from './types'; +import { Config, MatchingImages, ServiceType, tryMatchPort } from './types'; async function MatchIcon(name: string) { const res = await fetch( @@ -23,11 +23,13 @@ function tryMatchType(imageName: string): ServiceType { export function tryMatchService(container: Dockerode.ContainerInfo | undefined) { if (container === undefined) return {}; const name = container.Names[0].substring(1); + const type = tryMatchType(container.Image); + const port = tryMatchPort(type.toLowerCase()); return { name, id: container.Id, type: tryMatchType(container.Image), - url: `${container.Ports.at(0)?.IP}:${container.Ports.at(0)?.PublicPort}`, + url: `localhost${port ? `:${port.value}` : ''}`, icon: `https://cdn.jsdelivr.net/gh/walkxhub/dashboard-icons/png/${name .replace(/\s+/g, '-') .toLowerCase()}.png`,