feat: add cover selection workflow and docker profiles
This commit is contained in:
8
server/.dockerignore
Normal file
8
server/.dockerignore
Normal file
@@ -0,0 +1,8 @@
|
||||
.git
|
||||
node_modules
|
||||
.env
|
||||
.env.*
|
||||
*.log
|
||||
tmp
|
||||
coverage
|
||||
.DS_Store
|
||||
@@ -23,7 +23,7 @@ const sanitizeHtml = (text = '') =>
|
||||
.replace(/\n/g, '<br/>');
|
||||
|
||||
app.post('/generate-epub', async (req, res) => {
|
||||
const { text, meta } = req.body || {};
|
||||
const { text, meta, cover } = req.body || {};
|
||||
if (!text || !text.trim()) {
|
||||
return res.status(400).json({ message: 'text is required' });
|
||||
}
|
||||
@@ -40,12 +40,29 @@ app.post('/generate-epub', async (req, res) => {
|
||||
];
|
||||
|
||||
const outputPath = join(tmpdir(), `imgpub-${uuidV4()}.epub`);
|
||||
let coverPath;
|
||||
|
||||
try {
|
||||
const epub = new Epub({ title, author, content }, outputPath);
|
||||
if (cover?.data) {
|
||||
const coverBuffer = Buffer.from(cover.data, 'base64');
|
||||
const coverExtension =
|
||||
cover?.mimeType?.split('/').pop() || cover?.filename?.split('.').pop() || 'png';
|
||||
coverPath = join(tmpdir(), `imgpub-cover-${uuidV4()}.${coverExtension}`);
|
||||
await fs.writeFile(coverPath, coverBuffer);
|
||||
}
|
||||
|
||||
const epubOptions = { title, author, content };
|
||||
if (coverPath) {
|
||||
epubOptions.cover = coverPath;
|
||||
}
|
||||
|
||||
const epub = new Epub(epubOptions, outputPath);
|
||||
await epub.promise;
|
||||
const buffer = await fs.readFile(outputPath);
|
||||
await fs.unlink(outputPath).catch(() => {});
|
||||
if (coverPath) {
|
||||
await fs.unlink(coverPath).catch(() => {});
|
||||
}
|
||||
res.json({ filename, data: buffer.toString('base64') });
|
||||
} catch (error) {
|
||||
console.error('EPUB generation failed:', error);
|
||||
|
||||
Reference in New Issue
Block a user