mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 17:01:00 +03:00
Prevent server from crashing when link is empty or invalid
This commit is contained in:
@@ -1150,18 +1150,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 })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
// ----------------------------------------
|
// ----------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user