mirror of
https://github.com/gigirassy/plaster.git
synced 2024-12-24 10:49:07 +00:00
Update app.js
This commit is contained in:
parent
1afe2b27bc
commit
fb6a5554ad
21
app.js
21
app.js
@ -6,19 +6,12 @@ const PORT = process.env.PORT || 3000;
|
|||||||
|
|
||||||
app.use(express.static('public'));
|
app.use(express.static('public'));
|
||||||
|
|
||||||
// Endpoint to fetch Pastebin raw text data
|
// Route to fetch Pastebin raw text data using the Paste ID
|
||||||
app.get('/fetch-paste', async (req, res) => {
|
app.get('/:pasteId', async (req, res) => {
|
||||||
const { url } = req.query;
|
const pasteId = req.params.pasteId;
|
||||||
if (!url) {
|
|
||||||
return res.status(400).json({ error: 'URL is required' });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if the URL is a Pastebin URL and convert to raw format
|
// Construct the raw Pastebin URL
|
||||||
let rawUrl = url;
|
const rawUrl = `https://pastebin.com/raw/${pasteId}`;
|
||||||
if (url.includes('pastebin.com/') && !url.includes('/raw/')) {
|
|
||||||
const pasteId = url.split('/').pop();
|
|
||||||
rawUrl = `https://pastebin.com/raw/${pasteId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(rawUrl);
|
const response = await fetch(rawUrl);
|
||||||
@ -26,9 +19,9 @@ app.get('/fetch-paste', async (req, res) => {
|
|||||||
throw new Error('Failed to fetch data from Pastebin');
|
throw new Error('Failed to fetch data from Pastebin');
|
||||||
}
|
}
|
||||||
const text = await response.text();
|
const text = await response.text();
|
||||||
res.json({ text });
|
res.send(`<pre>${text}</pre>`);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(500).json({ error: error.message });
|
res.status(500).send(`Error: ${error.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user