mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 23:45:48 +01:00
✨ Use tryMatchPort
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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`,
|
||||
|
||||
Reference in New Issue
Block a user