plaster/app.js

25 lines
798 B
JavaScript
Raw Normal View History

2024-12-18 21:45:39 +00:00
app.get('/fetch-paste', async (req, res) => {
const { url } = req.query;
if (!url) {
return res.status(400).json({ error: 'URL is required' });
}
2024-12-18 21:16:43 +00:00
2024-12-18 21:45:39 +00:00
// Check if the URL is a Pastebin URL and convert to raw format
let rawUrl = url;
if (url.includes('pastebin.com/') && !url.includes('/raw/')) {
const pasteId = url.split('/').pop();
rawUrl = `https://pastebin.com/raw/${pasteId}`;
}
2024-12-18 21:16:43 +00:00
try {
const response = await fetch(rawUrl);
if (!response.ok) {
throw new Error('Failed to fetch data from Pastebin');
}
const text = await response.text();
2024-12-18 21:45:39 +00:00
res.json({ text }); // Always send JSON
2024-12-18 21:16:43 +00:00
} catch (error) {
2024-12-18 21:45:39 +00:00
res.status(500).json({ error: error.message }); // Ensure error is JSON
2024-12-18 21:16:43 +00:00
}
});