app.get('/download/:id', async (req, res) => { try { const eBook = await eBookModel.findById(req.params.id); if (!eBook) return res.status(404).send('Not Found'); const filePath = path.join(__dirname, eBook.path); if (!fs.existsSync(filePath)) return res.status(404).send('File Not Found'); res.download(filePath, `${eBook.title}.epub`); } catch (error) { res.status(500).send('Internal Server Error'); } });
const eBookSchema = new mongoose.Schema({ title: String, author: String, path: String }); if (!eBook) return res.status(404).send('Not Found')
const eBookModel = mongoose.model('eBook', eBookSchema); const filePath = path.join(__dirname
app.get('/download/:id', async (req, res) => { try { const eBook = await eBookModel.findById(req.params.id); if (!eBook) return res.status(404).send('Not Found'); const filePath = path.join(__dirname, eBook.path); if (!fs.existsSync(filePath)) return res.status(404).send('File Not Found'); res.download(filePath, `${eBook.title}.epub`); } catch (error) { res.status(500).send('Internal Server Error'); } }); const eBookSchema = new mongoose.Schema({ title: String, author: String, path: String }); const eBookModel = mongoose.model('eBook', eBookSchema); |
Advertisements
|