🐛 API endpoints not working with multiple widgets
This commit is contained in:
@@ -4,6 +4,7 @@ import Consola from 'consola';
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import { z } from 'zod';
|
||||
import { AppIntegrationType } from '../../../types/app';
|
||||
import { getConfig } from '../../../tools/config/getConfig';
|
||||
|
||||
@@ -18,28 +19,36 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
|
||||
});
|
||||
};
|
||||
|
||||
const getQuerySchema = z.object({
|
||||
month: z
|
||||
.string()
|
||||
.regex(/^\d+$/)
|
||||
.transform((x) => parseInt(x, 10)),
|
||||
year: z
|
||||
.string()
|
||||
.regex(/^\d+$/)
|
||||
.transform((x) => parseInt(x, 10)),
|
||||
widgetId: z.string().uuid(),
|
||||
configName: z.string(),
|
||||
});
|
||||
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
// Parse req.body as a AppItem
|
||||
const {
|
||||
month: monthString,
|
||||
year: yearString,
|
||||
configName,
|
||||
} = req.query as { month: string; year: string; configName: string };
|
||||
const parseResult = getQuerySchema.safeParse(req.query);
|
||||
|
||||
const month = parseInt(monthString, 10);
|
||||
const year = parseInt(yearString, 10);
|
||||
|
||||
if (Number.isNaN(month) || Number.isNaN(year) || !configName) {
|
||||
if (!parseResult.success) {
|
||||
return res.status(400).json({
|
||||
statusCode: 400,
|
||||
message: 'Missing required parameter in url: year, month or configName',
|
||||
message: 'Invalid query parameters, please specify the widgetId, month, year and configName',
|
||||
});
|
||||
}
|
||||
|
||||
// Parse req.body as a AppItem
|
||||
const { month, year, widgetId, configName } = parseResult.data;
|
||||
|
||||
const config = getConfig(configName);
|
||||
|
||||
// Find the calendar widget in the config
|
||||
const calendar = config.widgets.find((w) => w.type === 'calendar');
|
||||
const calendar = config.widgets.find((w) => w.type === 'calendar' && w.id === widgetId);
|
||||
const useSonarrv4 = calendar?.properties.useSonarrv4 ?? false;
|
||||
|
||||
const mediaAppIntegrationTypes: AppIntegrationType['type'][] = [
|
||||
|
||||
@@ -1,20 +1,29 @@
|
||||
import axios from 'axios';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { z } from 'zod';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
import { IDashDotTile } from '../../../../widgets/dashDot/DashDotTile';
|
||||
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { configName } = req.query;
|
||||
const getQuerySchema = z.object({
|
||||
configName: z.string(),
|
||||
widgetId: z.string().uuid(),
|
||||
});
|
||||
|
||||
if (!configName || typeof configName !== 'string') {
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const parseResult = getQuerySchema.safeParse(req.query);
|
||||
|
||||
if (!parseResult.success) {
|
||||
return res.status(400).json({
|
||||
message: 'Missing required configName in url',
|
||||
statusCode: 400,
|
||||
message: 'Invalid query parameters, please specify the widgetId and configName',
|
||||
});
|
||||
}
|
||||
|
||||
const { configName, widgetId } = parseResult.data;
|
||||
|
||||
const config = getConfig(configName);
|
||||
|
||||
const dashDotWidget = config.widgets.find((x) => x.type === 'dashdot');
|
||||
const dashDotWidget = config.widgets.find((x) => x.type === 'dashdot' && x.id === widgetId);
|
||||
|
||||
if (!dashDotWidget) {
|
||||
return res.status(400).json({
|
||||
|
||||
@@ -1,19 +1,28 @@
|
||||
import axios from 'axios';
|
||||
import { NextApiRequest, NextApiResponse } from 'next';
|
||||
import { z } from 'zod';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
import { IDashDotTile } from '../../../../widgets/dashDot/DashDotTile';
|
||||
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { configName } = req.query;
|
||||
const getQuerySchema = z.object({
|
||||
configName: z.string(),
|
||||
widgetId: z.string().uuid(),
|
||||
});
|
||||
|
||||
if (!configName || typeof configName !== 'string') {
|
||||
async function Get(req: NextApiRequest, res: NextApiResponse) {
|
||||
const parseResult = getQuerySchema.safeParse(req.query);
|
||||
|
||||
if (!parseResult.success) {
|
||||
return res.status(400).json({
|
||||
message: 'Missing required configName in url',
|
||||
statusCode: 400,
|
||||
message: 'Invalid query parameters, please specify the widgetId and configName',
|
||||
});
|
||||
}
|
||||
|
||||
const { configName, widgetId } = parseResult.data;
|
||||
|
||||
const config = getConfig(configName);
|
||||
const dashDotWidget = config.widgets.find((x) => x.type === 'dashdot');
|
||||
const dashDotWidget = config.widgets.find((x) => x.type === 'dashdot' && x.id === widgetId);
|
||||
|
||||
if (!dashDotWidget) {
|
||||
return res.status(400).json({
|
||||
|
||||
@@ -8,6 +8,7 @@ import { NextApiRequest, NextApiResponse } from 'next';
|
||||
|
||||
import Parser from 'rss-parser';
|
||||
|
||||
import { z } from 'zod';
|
||||
import { getConfig } from '../../../../tools/config/getConfig';
|
||||
import { IRssWidget } from '../../../../widgets/rss/RssWidgetTile';
|
||||
import { Stopwatch } from '../../../../tools/shared/time/stopwatch.tool';
|
||||
@@ -25,11 +26,24 @@ const parser: Parser<any, CustomItem> = new Parser({
|
||||
},
|
||||
});
|
||||
|
||||
const getQuerySchema = z.object({
|
||||
widgetId: z.string().uuid(),
|
||||
});
|
||||
|
||||
export const Get = async (request: NextApiRequest, response: NextApiResponse) => {
|
||||
const configName = getCookie('config-name', { req: request });
|
||||
const config = getConfig(configName?.toString() ?? 'default');
|
||||
|
||||
const rssWidget = config.widgets.find((x) => x.type === 'rss') as IRssWidget | undefined;
|
||||
const parseResult = getQuerySchema.safeParse(request.query);
|
||||
|
||||
if (!parseResult.success) {
|
||||
response.status(400).json({ message: 'invalid query parameters, please specify the widgetId' });
|
||||
return;
|
||||
}
|
||||
|
||||
const rssWidget = config.widgets.find(
|
||||
(x) => x.type === 'rss' && x.id === parseResult.data.widgetId
|
||||
) as IRssWidget | undefined;
|
||||
|
||||
if (
|
||||
!rssWidget ||
|
||||
|
||||
Reference in New Issue
Block a user