This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const express = require('express');
|
||||
const { fetchHtml, extractSeo, extractMetaTags } = require('./scraper');
|
||||
const { fetchHtml, extractSeo, extractMetaTags, extractOutgoingCalls, extractResultingUrl } = require('./scraper');
|
||||
const dbOps = require('./database');
|
||||
const { authenticateApiKey } = require('./middleware');
|
||||
const { isBrowserConnected } = require('./browser');
|
||||
@@ -155,4 +155,78 @@ router.get('/meta', authenticateApiKey, async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// Outgoing calls capture endpoint
|
||||
router.get('/outgoing-calls', authenticateApiKey, async (req, res) => {
|
||||
const { url, skipCache } = req.query;
|
||||
|
||||
// Validate URL parameter
|
||||
if (!url) {
|
||||
return res.status(400).json({
|
||||
error: 'Missing required parameter: url',
|
||||
});
|
||||
}
|
||||
|
||||
// Validate URL format
|
||||
let urlObj;
|
||||
try {
|
||||
urlObj = new URL(url);
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
error: 'Invalid URL format',
|
||||
});
|
||||
}
|
||||
|
||||
// Parse skipCache (accept 'true', '1', 'yes', etc.)
|
||||
const shouldSkipCache = skipCache === 'true' || skipCache === '1' || skipCache === 'yes';
|
||||
|
||||
try {
|
||||
const callsData = await extractOutgoingCalls(url, shouldSkipCache);
|
||||
res.json(callsData);
|
||||
} catch (error) {
|
||||
console.error('Outgoing calls capture error:', error);
|
||||
res.status(500).json({
|
||||
status: 'error',
|
||||
url: url,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Resulting URL endpoint
|
||||
router.get('/resulting-url', authenticateApiKey, async (req, res) => {
|
||||
const { url, skipCache } = req.query;
|
||||
|
||||
// Validate URL parameter
|
||||
if (!url) {
|
||||
return res.status(400).json({
|
||||
error: 'Missing required parameter: url',
|
||||
});
|
||||
}
|
||||
|
||||
// Validate URL format
|
||||
let urlObj;
|
||||
try {
|
||||
urlObj = new URL(url);
|
||||
} catch (error) {
|
||||
return res.status(400).json({
|
||||
error: 'Invalid URL format',
|
||||
});
|
||||
}
|
||||
|
||||
// Parse skipCache (accept 'true', '1', 'yes', etc.)
|
||||
const shouldSkipCache = skipCache === 'true' || skipCache === '1' || skipCache === 'yes';
|
||||
|
||||
try {
|
||||
const resultingUrlData = await extractResultingUrl(url, shouldSkipCache);
|
||||
res.json(resultingUrlData);
|
||||
} catch (error) {
|
||||
console.error('Resulting URL error:', error);
|
||||
res.status(500).json({
|
||||
status: 'error',
|
||||
original_url: url,
|
||||
error: error.message,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user