🐛 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 { BackendConfigType, ConfigType } from '../../../types/config';
import { getConfig } from '../../../tools/config/getConfig'; import { getConfig } from '../../../tools/config/getConfig';
import widgets from '../../../widgets';
import { IRssWidget } from '../../../widgets/rss/RssWidgetTile';
function Put(req: NextApiRequest, res: NextApiResponse) { function Put(req: NextApiRequest, res: NextApiResponse) {
if (process.env.DISABLE_EDIT_MODE === 'true') { if (process.env.DISABLE_EDIT_MODE === 'true') {
@@ -30,16 +32,17 @@ function Put(req: NextApiRequest, res: NextApiResponse) {
const previousConfig = getConfig(slug); const previousConfig = getConfig(slug);
const newConfig: BackendConfigType = { let newConfig: BackendConfigType = {
...config, ...config,
apps: [ apps: [
...config.apps.map((app) => ({ ...config.apps.map((app) => ({
...app, ...app,
network: { network: {
...app.network, ...app.network,
statusCodes: app.network.okStatus === undefined ? statusCodes:
app.network.statusCodes : app.network.okStatus === undefined
app.network.okStatus.map((x) => x.toString()), ? app.network.statusCodes
: app.network.okStatus.map((x) => x.toString()),
okStatus: undefined, okStatus: undefined,
}, },
integration: { 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 // Save the body in the /data/config folder with the slug as filename
const targetPath = path.join('data/configs', `${slug}.json`); const targetPath = path.join('data/configs', `${slug}.json`);
fs.writeFileSync(targetPath, JSON.stringify(newConfig, null, 2), 'utf8'); 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"> <ScrollArea className="scroll-area-w100" w="100%" mt="sm" mb="sm">
{data.map((feed, index) => ( {data.map((feed, index) => (
<Stack w="100%" spacing="xs"> <Stack w="100%" spacing="xs">
{feed.feed && feed.feed.items.map((item: any, index: number) => ( {feed.feed &&
<Card feed.feed.items.map((item: any, index: number) => (
key={index} <Card
withBorder key={index}
component={Link ?? 'div'} withBorder
href={item.link} component={Link ?? 'div'}
radius="md" href={item.link}
target="_blank" radius="md"
w="100%" 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">
{item.enclosure && ( {item.enclosure && (
<MediaQuery query="(max-width: 1200px)" styles={{ display: 'none' }}> // eslint-disable-next-line @next/next/no-img-element
<Image <img
src={item.enclosure?.url ?? undefined} className={classes.backgroundImage}
width={140} src={item.enclosure.url ?? undefined}
height={140} alt="backdrop"
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> <Flex gap="xs">
<Text color="dimmed" size="xs" lineClamp={3}> {item.enclosure && (
{item.content} <MediaQuery query="(max-width: 1200px)" styles={{ display: 'none' }}>
</Text> <Image
src={item.enclosure?.url ?? undefined}
{item.pubDate && ( width={140}
<InfoDisplay title={feed.feed.title} date={formatDate(item.pubDate)} /> 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>
</Flex> </Card>
</Card> ))}
))}
</Stack> </Stack>
))} ))}
</ScrollArea> </ScrollArea>