mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Merge pull request #1821 from 0xi4o/bug/web-scrapper-ui
Fix: Error Handling in Web Scraper
This commit is contained in:
@@ -1245,18 +1245,22 @@ export class App {
|
|||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|
||||||
this.app.get('/api/v1/fetch-links', async (req: Request, res: Response) => {
|
this.app.get('/api/v1/fetch-links', async (req: Request, res: Response) => {
|
||||||
const url = decodeURIComponent(req.query.url as string)
|
try {
|
||||||
const relativeLinksMethod = req.query.relativeLinksMethod as string
|
const url = decodeURIComponent(req.query.url as string)
|
||||||
if (!relativeLinksMethod) {
|
const relativeLinksMethod = req.query.relativeLinksMethod as string
|
||||||
return res.status(500).send('Please choose a Relative Links Method in Additional Parameters.')
|
if (!relativeLinksMethod) {
|
||||||
|
return res.status(500).send('Please choose a Relative Links Method in Additional Parameters.')
|
||||||
|
}
|
||||||
|
|
||||||
|
const limit = parseInt(req.query.limit as string)
|
||||||
|
if (process.env.DEBUG === 'true') console.info(`Start ${relativeLinksMethod}`)
|
||||||
|
const links: string[] = relativeLinksMethod === 'webCrawl' ? await webCrawl(url, limit) : await xmlScrape(url, limit)
|
||||||
|
if (process.env.DEBUG === 'true') console.info(`Finish ${relativeLinksMethod}`)
|
||||||
|
|
||||||
|
res.json({ status: 'OK', links })
|
||||||
|
} catch (e: any) {
|
||||||
|
return res.status(500).send('Could not fetch links from the URL.')
|
||||||
}
|
}
|
||||||
|
|
||||||
const limit = parseInt(req.query.limit as string)
|
|
||||||
if (process.env.DEBUG === 'true') console.info(`Start ${relativeLinksMethod}`)
|
|
||||||
const links: string[] = relativeLinksMethod === 'webCrawl' ? await webCrawl(url, limit) : await xmlScrape(url, limit)
|
|
||||||
if (process.env.DEBUG === 'true') console.info(`Finish ${relativeLinksMethod}`)
|
|
||||||
|
|
||||||
res.json({ status: 'OK', links })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import {
|
|||||||
Stack,
|
Stack,
|
||||||
Typography
|
Typography
|
||||||
} from '@mui/material'
|
} from '@mui/material'
|
||||||
import { IconTrash, IconX } from '@tabler/icons'
|
import { IconEraser, IconTrash, IconX } from '@tabler/icons'
|
||||||
import PerfectScrollbar from 'react-perfect-scrollbar'
|
import PerfectScrollbar from 'react-perfect-scrollbar'
|
||||||
|
|
||||||
import { BackdropLoader } from 'ui-component/loading/BackdropLoader'
|
import { BackdropLoader } from 'ui-component/loading/BackdropLoader'
|
||||||
@@ -113,6 +113,10 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
|
|||||||
setSelectedLinks(links)
|
setSelectedLinks(links)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleRemoveAllLinks = () => {
|
||||||
|
setSelectedLinks([])
|
||||||
|
}
|
||||||
|
|
||||||
const handleSaveLinks = () => {
|
const handleSaveLinks = () => {
|
||||||
onSave(url, selectedLinks)
|
onSave(url, selectedLinks)
|
||||||
}
|
}
|
||||||
@@ -145,6 +149,7 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
|
|||||||
/>
|
/>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<Button
|
<Button
|
||||||
|
disabled={!url}
|
||||||
sx={{ borderRadius: '12px', mt: 1, display: 'flex', flexShrink: 0 }}
|
sx={{ borderRadius: '12px', mt: 1, display: 'flex', flexShrink: 0 }}
|
||||||
size='small'
|
size='small'
|
||||||
variant='contained'
|
variant='contained'
|
||||||
@@ -154,7 +159,21 @@ const ManageScrapedLinksDialog = ({ show, dialogProps, onCancel, onSave }) => {
|
|||||||
</Button>
|
</Button>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
<Typography sx={{ mb: 2, fontWeight: 500 }}>Scraped Links</Typography>
|
<Box sx={{ display: 'flex', alignItems: 'center', justifyContent: 'space-between', mb: 1.5 }}>
|
||||||
|
<Typography sx={{ fontWeight: 500 }}>Scraped Links</Typography>
|
||||||
|
{selectedLinks.length > 0 ? (
|
||||||
|
<StyledButton
|
||||||
|
sx={{ height: 'max-content', width: 'max-content' }}
|
||||||
|
variant='outlined'
|
||||||
|
color='error'
|
||||||
|
title='Clear All Links'
|
||||||
|
onClick={handleRemoveAllLinks}
|
||||||
|
startIcon={<IconEraser />}
|
||||||
|
>
|
||||||
|
Clear All
|
||||||
|
</StyledButton>
|
||||||
|
) : null}
|
||||||
|
</Box>
|
||||||
<>
|
<>
|
||||||
{loading && <BackdropLoader open={loading} />}
|
{loading && <BackdropLoader open={loading} />}
|
||||||
{selectedLinks.length > 0 ? (
|
{selectedLinks.length > 0 ? (
|
||||||
|
|||||||
Reference in New Issue
Block a user