🐛 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,58 +120,59 @@ 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) => (
<Card
key={index}
withBorder
component={Link ?? 'div'}
href={item.link}
radius="md"
target="_blank"
w="100%"
>
{item.enclosure && (
// eslint-disable-next-line @next/next/no-img-element
<img
className={classes.backgroundImage}
src={item.enclosure.url ?? undefined}
alt="backdrop"
/>
)}
<Flex gap="xs">
{feed.feed &&
feed.feed.items.map((item: any, index: number) => (
<Card
key={index}
withBorder
component={Link ?? 'div'}
href={item.link}
radius="md"
target="_blank"
w="100%"
>
{item.enclosure && (
<MediaQuery query="(max-width: 1200px)" styles={{ display: 'none' }}>
<Image
src={item.enclosure?.url ?? undefined}
width={140}
height={140}
radius="md"
withPlaceholder
/>
</MediaQuery>
// eslint-disable-next-line @next/next/no-img-element
<img
className={classes.backgroundImage}
src={item.enclosure.url ?? undefined}
alt="backdrop"
/>
)}
<Flex gap={2} direction="column" w="100%">
{item.categories && (
<Flex gap="xs" wrap="wrap" h={20} style={{ overflow: 'hidden' }}>
{item.categories.map((category: any, categoryIndex: number) => (
<Badge key={categoryIndex}>{category}</Badge>
))}
</Flex>
)}
<Text lineClamp={2}>{item.title}</Text>
<Text color="dimmed" size="xs" lineClamp={3}>
{item.content}
</Text>
{item.pubDate && (
<InfoDisplay title={feed.feed.title} date={formatDate(item.pubDate)} />
<Flex gap="xs">
{item.enclosure && (
<MediaQuery query="(max-width: 1200px)" styles={{ display: 'none' }}>
<Image
src={item.enclosure?.url ?? undefined}
width={140}
height={140}
radius="md"
withPlaceholder
/>
</MediaQuery>
)}
<Flex gap={2} direction="column" w="100%">
{item.categories && (
<Flex gap="xs" wrap="wrap" h={20} style={{ overflow: 'hidden' }}>
{item.categories.map((category: any, categoryIndex: number) => (
<Badge key={categoryIndex}>{category}</Badge>
))}
</Flex>
)}
<Text lineClamp={2}>{item.title}</Text>
<Text color="dimmed" size="xs" lineClamp={3}>
{item.content}
</Text>
{item.pubDate && (
<InfoDisplay title={feed.feed.title} date={formatDate(item.pubDate)} />
)}
</Flex>
</Flex>
</Flex>
</Card>
))}
</Card>
))}
</Stack>
))}
</ScrollArea>