🐛 Fix rss widget crash with legacy string (#848)

This commit is contained in:
Manuel
2023-04-23 22:09:29 +02:00
committed by GitHub
parent f308e64788
commit cd9fa354ec
2 changed files with 79 additions and 51 deletions

View File

@@ -8,6 +8,8 @@ import { NextApiRequest, NextApiResponse } from 'next';
import { BackendConfigType, ConfigType } from '../../../types/config';
import { getConfig } from '../../../tools/config/getConfig';
import widgets from '../../../widgets';
import { IRssWidget } from '../../../widgets/rss/RssWidgetTile';
function Put(req: NextApiRequest, res: NextApiResponse) {
if (process.env.DISABLE_EDIT_MODE === 'true') {
@@ -30,16 +32,17 @@ function Put(req: NextApiRequest, res: NextApiResponse) {
const previousConfig = getConfig(slug);
const newConfig: BackendConfigType = {
let newConfig: BackendConfigType = {
...config,
apps: [
...config.apps.map((app) => ({
...app,
network: {
...app.network,
statusCodes: app.network.okStatus === undefined ?
app.network.statusCodes :
app.network.okStatus.map((x) => x.toString()),
statusCodes:
app.network.okStatus === undefined
? app.network.statusCodes
: app.network.okStatus.map((x) => x.toString()),
okStatus: undefined,
},
integration: {
@@ -83,6 +86,30 @@ function Put(req: NextApiRequest, res: NextApiResponse) {
],
};
newConfig = {
...newConfig,
widgets: [
...newConfig.widgets.map((x) => {
if (x.type !== 'rss') {
return x;
}
const rssWidget = x as IRssWidget;
return {
...rssWidget,
properties: {
...rssWidget.properties,
rssFeedUrl:
typeof rssWidget.properties.rssFeedUrl === 'string'
? [rssWidget.properties.rssFeedUrl]
: rssWidget.properties.rssFeedUrl,
},
} as IRssWidget;
}),
],
};
// Save the body in the /data/config folder with the slug as filename
const targetPath = path.join('data/configs', `${slug}.json`);
fs.writeFileSync(targetPath, JSON.stringify(newConfig, null, 2), 'utf8');

View File

@@ -120,7 +120,8 @@ function RssTile({ widget }: RssTileProps) {
<ScrollArea className="scroll-area-w100" w="100%" mt="sm" mb="sm">
{data.map((feed, index) => (
<Stack w="100%" spacing="xs">
{feed.feed && feed.feed.items.map((item: any, index: number) => (
{feed.feed &&
feed.feed.items.map((item: any, index: number) => (
<Card
key={index}
withBorder