mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-10 15:35:55 +01:00
🐛 Fix wrong access on properties of widgets and apps in api
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { getConfig } from '../../../../tools/config/getConfig';
|
import { getConfig } from '../../../../tools/config/getConfig';
|
||||||
|
import { IDashDotTile } from '../../../../widgets/dashDot/DashDotTile';
|
||||||
|
|
||||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { configName } = req.query;
|
const { configName } = req.query;
|
||||||
@@ -13,7 +14,15 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
|
|
||||||
const config = getConfig(configName);
|
const config = getConfig(configName);
|
||||||
|
|
||||||
const dashDotUrl = config.widgets.dashdot?.properties.url;
|
const dashDotWidget = config.widgets.find((x) => x.id === 'dashdot');
|
||||||
|
|
||||||
|
if (!dashDotWidget) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: 'There is no dashdot widget defined',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const dashDotUrl = (dashDotWidget as IDashDotTile).properties.url;
|
||||||
|
|
||||||
if (!dashDotUrl) {
|
if (!dashDotUrl) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { getConfig } from '../../../../tools/config/getConfig';
|
import { getConfig } from '../../../../tools/config/getConfig';
|
||||||
|
import { IDashDotTile } from '../../../../widgets/dashDot/DashDotTile';
|
||||||
|
|
||||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const { configName } = req.query;
|
const { configName } = req.query;
|
||||||
@@ -12,8 +13,15 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const config = getConfig(configName);
|
const config = getConfig(configName);
|
||||||
|
const dashDotWidget = config.widgets.find((x) => x.id === 'dashdot');
|
||||||
|
|
||||||
const dashDotUrl = config.widgets.dashdot?.properties.url;
|
if (!dashDotWidget) {
|
||||||
|
return res.status(400).json({
|
||||||
|
message: 'There is no dashdot widget defined',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const dashDotUrl = (dashDotWidget as IDashDotTile).properties.url;
|
||||||
|
|
||||||
if (!dashDotUrl) {
|
if (!dashDotUrl) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
|
|||||||
import { getCookie } from 'cookies-next';
|
import { getCookie } from 'cookies-next';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import Consola from 'consola';
|
import Consola from 'consola';
|
||||||
import { getConfig } from '../../../../tools/getConfig';
|
import { getConfig } from '../../../../tools/config/getConfig';
|
||||||
import { Config } from '../../../../tools/types';
|
import { Config } from '../../../../tools/types';
|
||||||
import { MediaType } from '../../../../modules/overseerr/SearchResult';
|
import { MediaType } from '../../../../modules/overseerr/SearchResult';
|
||||||
|
|
||||||
@@ -10,9 +10,9 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
// Get the slug of the request
|
// Get the slug of the request
|
||||||
const { id, type } = req.query as { id: string; type: string };
|
const { id, type } = req.query as { id: string; type: string };
|
||||||
const configName = getCookie('config-name', { req });
|
const configName = getCookie('config-name', { req });
|
||||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
const config = getConfig(configName?.toString() ?? 'default');
|
||||||
const app = config.apps.find(
|
const app = config.apps.find(
|
||||||
(app) => app.type === 'Overseerr' || app.type === 'Jellyseerr'
|
(app) => app.integration?.type === 'overseerr' || app.integration?.type === 'jellyseerr'
|
||||||
);
|
);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return res.status(400).json({ error: 'No id provided' });
|
return res.status(400).json({ error: 'No id provided' });
|
||||||
@@ -20,7 +20,8 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
if (!type) {
|
if (!type) {
|
||||||
return res.status(400).json({ error: 'No type provided' });
|
return res.status(400).json({ error: 'No type provided' });
|
||||||
}
|
}
|
||||||
if (!app?.apiKey) {
|
const apiKey = app?.integration?.properties.find((x) => x.field === 'apiKey')?.value;
|
||||||
|
if (!apiKey) {
|
||||||
return res.status(400).json({ error: 'No apps found' });
|
return res.status(400).json({ error: 'No apps found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +32,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
.get(`${appUrl.origin}/api/v1/movie/${id}`, {
|
.get(`${appUrl.origin}/api/v1/movie/${id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
// Set X-Api-Key to the value of the API key
|
// Set X-Api-Key to the value of the API key
|
||||||
'X-Api-Key': app.apiKey,
|
'X-Api-Key': apiKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((axiosres) => res.status(200).json(axiosres.data))
|
.then((axiosres) => res.status(200).json(axiosres.data))
|
||||||
@@ -48,7 +49,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
.get(`${appUrl.origin}/api/v1/tv/${id}`, {
|
.get(`${appUrl.origin}/api/v1/tv/${id}`, {
|
||||||
headers: {
|
headers: {
|
||||||
// Set X-Api-Key to the value of the API key
|
// Set X-Api-Key to the value of the API key
|
||||||
'X-Api-Key': app.apiKey,
|
'X-Api-Key': apiKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((axiosres) => res.status(200).json(axiosres.data))
|
.then((axiosres) => res.status(200).json(axiosres.data))
|
||||||
@@ -71,9 +72,9 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const { id } = req.query as { id: string };
|
const { id } = req.query as { id: string };
|
||||||
const { seasons, type } = req.body as { seasons?: number[]; type: MediaType };
|
const { seasons, type } = req.body as { seasons?: number[]; type: MediaType };
|
||||||
const configName = getCookie('config-name', { req });
|
const configName = getCookie('config-name', { req });
|
||||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
const config = getConfig(configName?.toString() ?? 'default');
|
||||||
const app = config.apps.find(
|
const app = config.apps.find(
|
||||||
(app) => app.type === 'Overseerr' || app.type === 'Jellyseerr'
|
(app) => app.integration?.type === 'overseerr' || app.integration?.type === 'jellyseerr'
|
||||||
);
|
);
|
||||||
if (!id) {
|
if (!id) {
|
||||||
return res.status(400).json({ error: 'No id provided' });
|
return res.status(400).json({ error: 'No id provided' });
|
||||||
@@ -81,7 +82,9 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
if (!type) {
|
if (!type) {
|
||||||
return res.status(400).json({ error: 'No type provided' });
|
return res.status(400).json({ error: 'No type provided' });
|
||||||
}
|
}
|
||||||
if (!app?.apiKey) {
|
|
||||||
|
const apiKey = app?.integration?.properties.find((x) => x.field === 'apiKey')?.value;
|
||||||
|
if (!apiKey) {
|
||||||
return res.status(400).json({ error: 'No app found' });
|
return res.status(400).json({ error: 'No app found' });
|
||||||
}
|
}
|
||||||
if (type === 'movie' && !seasons) {
|
if (type === 'movie' && !seasons) {
|
||||||
@@ -104,7 +107,7 @@ async function Post(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
// Set X-Api-Key to the value of the API key
|
// Set X-Api-Key to the value of the API key
|
||||||
'X-Api-Key': app.apiKey,
|
'X-Api-Key': apiKey,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,21 +1,23 @@
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { getCookie } from 'cookies-next';
|
import { getCookie } from 'cookies-next';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { getConfig } from '../../../../tools/getConfig';
|
import { getConfig } from '../../../../tools/config/getConfig';
|
||||||
import { Config } from '../../../../tools/types';
|
import { Config } from '../../../../tools/types';
|
||||||
|
|
||||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||||
const configName = getCookie('config-name', { req });
|
const configName = getCookie('config-name', { req });
|
||||||
const { config }: { config: Config } = getConfig(configName?.toString() ?? 'default').props;
|
const config = getConfig(configName?.toString() ?? 'default');
|
||||||
const { query } = req.query;
|
const { query } = req.query;
|
||||||
const app = config.apps.find(
|
const app = config.apps.find(
|
||||||
(app) => app.type === 'Overseerr' || app.type === 'Jellyseerr'
|
(app) => app.integration?.type === 'overseerr' || app.integration?.type === 'jellyseerr'
|
||||||
);
|
);
|
||||||
// If query is an empty string, return an empty array
|
// If query is an empty string, return an empty array
|
||||||
if (query === '' || query === undefined) {
|
if (query === '' || query === undefined) {
|
||||||
return res.status(200).json([]);
|
return res.status(200).json([]);
|
||||||
}
|
}
|
||||||
if (!app || !query || app === undefined || !app.apiKey) {
|
|
||||||
|
const apiKey = app?.integration?.properties.find((x) => x.field === 'apiKey')?.value;
|
||||||
|
if (!app || !query || !apiKey) {
|
||||||
return res.status(400).json({
|
return res.status(400).json({
|
||||||
error: 'Wrong request',
|
error: 'Wrong request',
|
||||||
});
|
});
|
||||||
@@ -25,7 +27,7 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
.get(`${appUrl.origin}/api/v1/search?query=${query}`, {
|
.get(`${appUrl.origin}/api/v1/search?query=${query}`, {
|
||||||
headers: {
|
headers: {
|
||||||
// Set X-Api-Key to the value of the API key
|
// Set X-Api-Key to the value of the API key
|
||||||
'X-Api-Key': app.apiKey,
|
'X-Api-Key': apiKey,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then((res) => res.data);
|
.then((res) => res.data);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { Client } from 'sabnzbd-api';
|
|||||||
import { NzbgetHistoryItem } from './nzbget/types';
|
import { NzbgetHistoryItem } from './nzbget/types';
|
||||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||||
import { getConfig } from '../../../../tools/config/getConfig';
|
import { getConfig } from '../../../../tools/config/getConfig';
|
||||||
import { UsenetHistoryItem } from '../../../../components/Dashboard/Tiles/UseNet/types';
|
import { UsenetHistoryItem } from '../../../../widgets/useNet/types';
|
||||||
|
|
||||||
dayjs.extend(duration);
|
dayjs.extend(duration);
|
||||||
|
|
||||||
@@ -40,10 +40,8 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const options = {
|
const options = {
|
||||||
host: url.hostname,
|
host: url.hostname,
|
||||||
port: url.port,
|
port: url.port,
|
||||||
login:
|
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||||
app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||||
hash:
|
|
||||||
app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const nzbGet = NzbgetClient(options);
|
const nzbGet = NzbgetClient(options);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import dayjs from 'dayjs';
|
|||||||
import duration from 'dayjs/plugin/duration';
|
import duration from 'dayjs/plugin/duration';
|
||||||
import { NextApiRequest, NextApiResponse } from 'next';
|
import { NextApiRequest, NextApiResponse } from 'next';
|
||||||
import { Client } from 'sabnzbd-api';
|
import { Client } from 'sabnzbd-api';
|
||||||
import { UsenetQueueItem } from '../../../../components/Dashboard/Tiles/UseNet/types';
|
|
||||||
import { getConfig } from '../../../../tools/config/getConfig';
|
import { getConfig } from '../../../../tools/config/getConfig';
|
||||||
|
import { UsenetQueueItem } from '../../../../widgets/useNet/types';
|
||||||
import { NzbgetClient } from './nzbget/nzbget-client';
|
import { NzbgetClient } from './nzbget/nzbget-client';
|
||||||
import { NzbgetQueueItem, NzbgetStatus } from './nzbget/types';
|
import { NzbgetQueueItem, NzbgetStatus } from './nzbget/types';
|
||||||
|
|
||||||
@@ -40,10 +40,8 @@ async function Get(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
const options = {
|
const options = {
|
||||||
host: url.hostname,
|
host: url.hostname,
|
||||||
port: url.port,
|
port: url.port,
|
||||||
login:
|
login: app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
||||||
app.integration.properties.find((x) => x.field === 'username')?.value ?? undefined,
|
hash: app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
||||||
hash:
|
|
||||||
app.integration.properties.find((x) => x.field === 'password')?.value ?? undefined,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const nzbGet = NzbgetClient(options);
|
const nzbGet = NzbgetClient(options);
|
||||||
|
|||||||
@@ -8,9 +8,7 @@ import { Dashboard } from '../components/Dashboard/Dashboard';
|
|||||||
import Layout from '../components/layout/Layout';
|
import Layout from '../components/layout/Layout';
|
||||||
import { useInitConfig } from '../config/init';
|
import { useInitConfig } from '../config/init';
|
||||||
import { getFrontendConfig } from '../tools/config/getFrontendConfig';
|
import { getFrontendConfig } from '../tools/config/getFrontendConfig';
|
||||||
import { getConfig } from '../tools/getConfig';
|
|
||||||
import { dashboardNamespaces } from '../tools/translation-namespaces';
|
import { dashboardNamespaces } from '../tools/translation-namespaces';
|
||||||
import { Config } from '../tools/types';
|
|
||||||
import { ConfigType } from '../types/config';
|
import { ConfigType } from '../types/config';
|
||||||
|
|
||||||
type ServerSideProps = {
|
type ServerSideProps = {
|
||||||
|
|||||||
Reference in New Issue
Block a user