squidclaw 2.2.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/channels/telegram/bot.js +12 -0
- package/lib/engine.js +6 -0
- package/lib/features/cron.js +217 -0
- package/lib/features/reminders.js +2 -1
- package/lib/middleware/commands.js +53 -15
- package/lib/middleware/response-sender.js +3 -12
- package/lib/tools/excel.js +136 -0
- package/lib/tools/html.js +148 -0
- package/lib/tools/pdf.js +133 -0
- package/lib/tools/pptx.js +681 -83
- package/lib/tools/router.js +162 -19
- package/package.json +3 -1
package/lib/tools/pdf.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 🦑 PDF Generator
|
|
3
|
+
* Create .pdf documents
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { logger } from '../core/logger.js';
|
|
7
|
+
import { mkdirSync, createWriteStream } from 'fs';
|
|
8
|
+
import { join } from 'path';
|
|
9
|
+
|
|
10
|
+
export class PdfGenerator {
|
|
11
|
+
constructor() {
|
|
12
|
+
this.outputDir = '/tmp/squidclaw-files';
|
|
13
|
+
mkdirSync(this.outputDir, { recursive: true });
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async create(title, content, options = {}) {
|
|
17
|
+
const PDFDocument = (await import('pdfkit')).default;
|
|
18
|
+
|
|
19
|
+
const filename = title.replace(/[^a-zA-Z0-9\u0600-\u06FF ]/g, '').replace(/\s+/g, '_').slice(0, 50) + '.pdf';
|
|
20
|
+
const filepath = join(this.outputDir, filename);
|
|
21
|
+
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const doc = new PDFDocument({
|
|
24
|
+
size: 'A4',
|
|
25
|
+
margins: { top: 60, bottom: 60, left: 60, right: 60 },
|
|
26
|
+
info: { Title: title, Author: 'Squidclaw AI 🦑', Creator: 'Squidclaw' },
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const stream = createWriteStream(filepath);
|
|
30
|
+
doc.pipe(stream);
|
|
31
|
+
|
|
32
|
+
const colors = {
|
|
33
|
+
title: '#1a1a2e',
|
|
34
|
+
heading: '#2563eb',
|
|
35
|
+
text: '#374151',
|
|
36
|
+
accent: '#2563eb',
|
|
37
|
+
light: '#6b7280',
|
|
38
|
+
bg: '#f8fafc',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// Header accent bar
|
|
42
|
+
doc.rect(0, 0, doc.page.width, 8).fill(colors.accent);
|
|
43
|
+
|
|
44
|
+
// Title
|
|
45
|
+
doc.moveDown(1);
|
|
46
|
+
doc.fontSize(28).fillColor(colors.title).font('Helvetica-Bold').text(title, { align: 'left' });
|
|
47
|
+
|
|
48
|
+
// Subtitle line
|
|
49
|
+
doc.moveDown(0.3);
|
|
50
|
+
doc.moveTo(60, doc.y).lineTo(200, doc.y).strokeColor(colors.accent).lineWidth(2).stroke();
|
|
51
|
+
doc.moveDown(0.5);
|
|
52
|
+
|
|
53
|
+
// Date
|
|
54
|
+
const date = new Date().toLocaleDateString('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
|
|
55
|
+
doc.fontSize(10).fillColor(colors.light).font('Helvetica').text(date);
|
|
56
|
+
doc.moveDown(1.5);
|
|
57
|
+
|
|
58
|
+
// Parse and render content
|
|
59
|
+
const lines = content.split('\n');
|
|
60
|
+
for (const line of lines) {
|
|
61
|
+
const trimmed = line.trim();
|
|
62
|
+
if (!trimmed) { doc.moveDown(0.5); continue; }
|
|
63
|
+
|
|
64
|
+
// Check for page overflow
|
|
65
|
+
if (doc.y > doc.page.height - 100) {
|
|
66
|
+
doc.addPage();
|
|
67
|
+
doc.rect(0, 0, doc.page.width, 4).fill(colors.accent);
|
|
68
|
+
doc.moveDown(1);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// ## Heading
|
|
72
|
+
if (trimmed.startsWith('## ')) {
|
|
73
|
+
doc.moveDown(0.8);
|
|
74
|
+
doc.fontSize(18).fillColor(colors.heading).font('Helvetica-Bold').text(trimmed.slice(3));
|
|
75
|
+
doc.moveDown(0.2);
|
|
76
|
+
doc.moveTo(60, doc.y).lineTo(160, doc.y).strokeColor(colors.accent).lineWidth(1).stroke();
|
|
77
|
+
doc.moveDown(0.5);
|
|
78
|
+
}
|
|
79
|
+
// ### Subheading
|
|
80
|
+
else if (trimmed.startsWith('### ')) {
|
|
81
|
+
doc.moveDown(0.5);
|
|
82
|
+
doc.fontSize(14).fillColor(colors.title).font('Helvetica-Bold').text(trimmed.slice(4));
|
|
83
|
+
doc.moveDown(0.3);
|
|
84
|
+
}
|
|
85
|
+
// - Bullet
|
|
86
|
+
else if (trimmed.startsWith('- ') || trimmed.startsWith('• ') || trimmed.startsWith('* ')) {
|
|
87
|
+
const bullet = trimmed.replace(/^[-•*]\s*/, '');
|
|
88
|
+
doc.fontSize(11).fillColor(colors.text).font('Helvetica');
|
|
89
|
+
doc.text('● ' + bullet, { indent: 15, lineGap: 4 });
|
|
90
|
+
}
|
|
91
|
+
// **Bold**
|
|
92
|
+
else if (trimmed.startsWith('**') && trimmed.endsWith('**')) {
|
|
93
|
+
doc.fontSize(12).fillColor(colors.title).font('Helvetica-Bold').text(trimmed.replace(/\*\*/g, ''));
|
|
94
|
+
}
|
|
95
|
+
// > Quote
|
|
96
|
+
else if (trimmed.startsWith('> ')) {
|
|
97
|
+
doc.moveDown(0.3);
|
|
98
|
+
const quoteText = trimmed.slice(2);
|
|
99
|
+
const qx = doc.x;
|
|
100
|
+
doc.rect(qx, doc.y, 3, 40).fill(colors.accent);
|
|
101
|
+
doc.fontSize(11).fillColor(colors.light).font('Helvetica-Oblique').text(quoteText, qx + 15, doc.y - 40 + 5, { width: 420 });
|
|
102
|
+
doc.moveDown(0.5);
|
|
103
|
+
}
|
|
104
|
+
// --- Divider
|
|
105
|
+
else if (trimmed === '---' || trimmed === '***') {
|
|
106
|
+
doc.moveDown(0.5);
|
|
107
|
+
doc.moveTo(60, doc.y).lineTo(doc.page.width - 60, doc.y).strokeColor('#e5e7eb').lineWidth(0.5).stroke();
|
|
108
|
+
doc.moveDown(0.5);
|
|
109
|
+
}
|
|
110
|
+
// Normal text
|
|
111
|
+
else {
|
|
112
|
+
doc.fontSize(11).fillColor(colors.text).font('Helvetica').text(trimmed, { lineGap: 4 });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Footer
|
|
117
|
+
const pages = doc.bufferedPageRange();
|
|
118
|
+
for (let i = 0; i < pages.count; i++) {
|
|
119
|
+
doc.switchToPage(i);
|
|
120
|
+
doc.fontSize(8).fillColor(colors.light).font('Helvetica');
|
|
121
|
+
doc.text('Created with Squidclaw AI 🦑', 60, doc.page.height - 40, { width: doc.page.width - 120, align: 'center' });
|
|
122
|
+
doc.text(String(i + 1), 60, doc.page.height - 40, { width: doc.page.width - 120, align: 'right' });
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
doc.end();
|
|
126
|
+
stream.on('finish', () => {
|
|
127
|
+
logger.info('pdf', `Created: ${filepath}`);
|
|
128
|
+
resolve({ filepath, filename });
|
|
129
|
+
});
|
|
130
|
+
stream.on('error', reject);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|