mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-11 16:05:47 +01:00
Merge pull request #1152 from Malong11-007/fix/pi-hole-integration-field
✏️ fix pi-hole integration field from password to apiKey
This commit is contained in:
@@ -57,7 +57,7 @@ const processAdGuard = async (app: ConfigAppType, enable: boolean) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const processPiHole = async (app: ConfigAppType, enable: boolean) => {
|
const processPiHole = async (app: ConfigAppType, enable: boolean) => {
|
||||||
const pihole = new PiHoleClient(app.url, findAppProperty(app, 'password'));
|
const pihole = new PiHoleClient(app.url, findAppProperty(app, 'apiKey'));
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
await pihole.enable();
|
await pihole.enable();
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ describe('DNS hole', () => {
|
|||||||
type: 'pihole',
|
type: 'pihole',
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'apiKey',
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: 'hf3829fj238g8',
|
value: 'hf3829fj238g8',
|
||||||
},
|
},
|
||||||
@@ -130,7 +130,7 @@ describe('DNS hole', () => {
|
|||||||
type: 'pihole',
|
type: 'pihole',
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'apiKey',
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: 'hf3829fj238g8',
|
value: 'hf3829fj238g8',
|
||||||
},
|
},
|
||||||
@@ -144,7 +144,7 @@ describe('DNS hole', () => {
|
|||||||
type: 'pihole',
|
type: 'pihole',
|
||||||
properties: [
|
properties: [
|
||||||
{
|
{
|
||||||
field: 'password',
|
field: 'apiKey',
|
||||||
type: 'private',
|
type: 'private',
|
||||||
value: 'ayaka',
|
value: 'ayaka',
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export const Get = async (request: NextApiRequest, response: NextApiResponse) =>
|
|||||||
try {
|
try {
|
||||||
switch (app.integration?.type) {
|
switch (app.integration?.type) {
|
||||||
case 'pihole': {
|
case 'pihole': {
|
||||||
const piHole = new PiHoleClient(app.url, findAppProperty(app, 'password'));
|
const piHole = new PiHoleClient(app.url, findAppProperty(app, 'apiKey'));
|
||||||
const summary = await piHole.getSummary();
|
const summary = await piHole.getSummary();
|
||||||
|
|
||||||
data.domainsBeingBlocked += summary.domains_being_blocked;
|
data.domainsBeingBlocked += summary.domains_being_blocked;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ const processAdGuard = async (app: ConfigAppType, enable: boolean) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const processPiHole = async (app: ConfigAppType, enable: boolean) => {
|
const processPiHole = async (app: ConfigAppType, enable: boolean) => {
|
||||||
const pihole = new PiHoleClient(app.url, findAppProperty(app, 'password'));
|
const pihole = new PiHoleClient(app.url, findAppProperty(app, 'apiKey'));
|
||||||
|
|
||||||
if (enable) {
|
if (enable) {
|
||||||
await pihole.enable();
|
await pihole.enable();
|
||||||
@@ -108,7 +108,7 @@ const processPiHole = async (app: ConfigAppType, enable: boolean) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const collectPiHoleSummary = async (app: ConfigAppType) => {
|
const collectPiHoleSummary = async (app: ConfigAppType) => {
|
||||||
const piHole = new PiHoleClient(app.url, findAppProperty(app, 'password'));
|
const piHole = new PiHoleClient(app.url, findAppProperty(app, 'apiKey'));
|
||||||
const summary = await piHole.getSummary();
|
const summary = await piHole.getSummary();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
import Consola from 'consola';
|
import Consola from 'consola';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
|
import { IntegrationField } from '~/types/app';
|
||||||
import { BackendConfigType, ConfigType } from '../../types/config';
|
import { BackendConfigType, ConfigType } from '../../types/config';
|
||||||
import { getConfig } from './getConfig';
|
import { getConfig } from './getConfig';
|
||||||
import { fetchCity } from '~/server/api/routers/weather';
|
import { fetchCity } from '~/server/api/routers/weather';
|
||||||
|
|
||||||
export const getFrontendConfig = async (name: string): Promise<ConfigType> => {
|
export const getFrontendConfig = async (name: string): Promise<ConfigType> => {
|
||||||
let config = getConfig(name);
|
let config = getConfig(name);
|
||||||
|
let shouldMigrateConfig = false;
|
||||||
|
|
||||||
const anyWeatherWidgetWithStringLocation = config.widgets.some(
|
const anyWeatherWidgetWithStringLocation = config.widgets.some(
|
||||||
(widget) => widget.type === 'weather' && typeof widget.properties.location === 'string'
|
(widget) => widget.type === 'weather' && typeof widget.properties.location === 'string'
|
||||||
@@ -13,6 +15,27 @@ export const getFrontendConfig = async (name: string): Promise<ConfigType> => {
|
|||||||
|
|
||||||
if (anyWeatherWidgetWithStringLocation) {
|
if (anyWeatherWidgetWithStringLocation) {
|
||||||
config = await migrateLocation(config);
|
config = await migrateLocation(config);
|
||||||
|
shouldMigrateConfig = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
const anyPiholeIntegrationWithPassword = config.apps.some(
|
||||||
|
(app) =>
|
||||||
|
app?.integration?.type === 'pihole' &&
|
||||||
|
app?.integration?.properties.length &&
|
||||||
|
app.integration.properties.some((property) => property.field === 'password')
|
||||||
|
);
|
||||||
|
|
||||||
|
if (anyPiholeIntegrationWithPassword) {
|
||||||
|
config = migratePiholeIntegrationField(config);
|
||||||
|
shouldMigrateConfig = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (shouldMigrateConfig) {
|
||||||
|
Consola.info(`Migrating config ${config.configProperties.name}`);
|
||||||
|
fs.writeFileSync(
|
||||||
|
`./data/configs/${config.configProperties.name}.json`,
|
||||||
|
JSON.stringify(config, null, 2)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Consola.info(`Requested frontend content of configuration '${name}'`);
|
Consola.info(`Requested frontend content of configuration '${name}'`);
|
||||||
@@ -54,7 +77,6 @@ export const getFrontendConfig = async (name: string): Promise<ConfigType> => {
|
|||||||
const migrateLocation = async (config: BackendConfigType) => {
|
const migrateLocation = async (config: BackendConfigType) => {
|
||||||
Consola.log('Migrating config file to new location schema...', config.configProperties.name);
|
Consola.log('Migrating config file to new location schema...', config.configProperties.name);
|
||||||
|
|
||||||
const configName = config.configProperties.name;
|
|
||||||
const migratedConfig = {
|
const migratedConfig = {
|
||||||
...config,
|
...config,
|
||||||
widgets: await Promise.all(
|
widgets: await Promise.all(
|
||||||
@@ -82,7 +104,27 @@ const migrateLocation = async (config: BackendConfigType) => {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
fs.writeFileSync(`./data/configs/${configName}.json`, JSON.stringify(migratedConfig, null, 2));
|
|
||||||
|
|
||||||
return migratedConfig;
|
return migratedConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const migratePiholeIntegrationField = (config: BackendConfigType) => {
|
||||||
|
Consola.log('Migrating pihole integration field to apiKey...', config.configProperties.name);
|
||||||
|
return {
|
||||||
|
...config,
|
||||||
|
apps: config.apps.map((app) => {
|
||||||
|
if (app?.integration?.type === 'pihole' && Array.isArray(app?.integration?.properties)) {
|
||||||
|
const migratedProperties = app.integration.properties.map((property) => {
|
||||||
|
if (property.field === 'password') {
|
||||||
|
return {
|
||||||
|
...property,
|
||||||
|
field: 'apiKey' as IntegrationField,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return property;
|
||||||
|
});
|
||||||
|
return { ...app, integration: { ...app.integration, properties: migratedProperties } };
|
||||||
|
}
|
||||||
|
return app;
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ export const integrationFieldProperties: {
|
|||||||
transmission: ['username', 'password'],
|
transmission: ['username', 'password'],
|
||||||
jellyfin: ['username', 'password'],
|
jellyfin: ['username', 'password'],
|
||||||
plex: ['apiKey'],
|
plex: ['apiKey'],
|
||||||
pihole: ['password'],
|
pihole: ['apiKey'],
|
||||||
adGuardHome: ['username', 'password'],
|
adGuardHome: ['username', 'password'],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user