devbonzai 2.2.209 → 2.2.210

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "devbonzai",
3
- "version": "2.2.209",
3
+ "version": "2.2.210",
4
4
  "description": "Quickly set up a local file server in any repository for browser-based file access",
5
5
  "main": "cli.js",
6
6
  "bin": {
@@ -0,0 +1,42 @@
1
+ // Serves the bonzai capture client script for screenshot functionality
2
+ function bonzaiCaptureClientHandler(req, res) {
3
+ res.set('Content-Type', 'application/javascript');
4
+ res.send(`(function() {
5
+ if (window.__bonzaiCaptureLoaded) return;
6
+ window.__bonzaiCaptureLoaded = true;
7
+ var script = document.createElement('script');
8
+ script.src = 'https://cdn.jsdelivr.net/npm/html2canvas@1.4.1/dist/html2canvas.min.js';
9
+ script.onload = function() {
10
+ window.addEventListener('message', function(e) {
11
+ if (!e.data || e.data.type !== 'BONZAI_CAPTURE_REQUEST') return;
12
+
13
+ var selection = e.data.selection;
14
+
15
+ html2canvas(document.body, {
16
+ x: selection.left + window.scrollX,
17
+ y: selection.top + window.scrollY,
18
+ width: selection.width,
19
+ height: selection.height
20
+ }).then(function(canvas) {
21
+ window.parent.postMessage({
22
+ type: 'BONZAI_SCREENSHOT',
23
+ data: {
24
+ id: String(Date.now()),
25
+ data: canvas.toDataURL('image/png'),
26
+ timestamp: new Date().toISOString()
27
+ }
28
+ }, '*');
29
+ }).catch(function(err) {
30
+ window.parent.postMessage({
31
+ type: 'BONZAI_SCREENSHOT_ERROR',
32
+ error: err.message
33
+ }, '*');
34
+ });
35
+ });
36
+ };
37
+ document.head.appendChild(script);
38
+ })();`);
39
+ }
40
+
41
+ module.exports = bonzaiCaptureClientHandler;
42
+
@@ -0,0 +1,55 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { ROOT } = require('../config');
4
+
5
+ // Serves static files with HTML injection for bonzai capture
6
+ function serveHandler(req, res) {
7
+ try {
8
+ const requestedPath = req.query.path || 'index.html';
9
+ const filePath = path.join(ROOT, requestedPath);
10
+
11
+ // Security check: ensure path is within ROOT
12
+ if (!filePath.startsWith(ROOT)) {
13
+ return res.status(400).send('Invalid path');
14
+ }
15
+
16
+ // Check if file exists
17
+ if (!fs.existsSync(filePath)) {
18
+ return res.status(404).send('File not found');
19
+ }
20
+
21
+ // Read file content
22
+ let content = fs.readFileSync(filePath, 'utf8');
23
+
24
+ // Determine content type based on extension
25
+ const ext = path.extname(filePath).toLowerCase();
26
+ const contentTypes = {
27
+ '.html': 'text/html',
28
+ '.htm': 'text/html',
29
+ '.css': 'text/css',
30
+ '.js': 'application/javascript',
31
+ '.json': 'application/json',
32
+ '.png': 'image/png',
33
+ '.jpg': 'image/jpeg',
34
+ '.jpeg': 'image/jpeg',
35
+ '.gif': 'image/gif',
36
+ '.svg': 'image/svg+xml',
37
+ '.ico': 'image/x-icon'
38
+ };
39
+
40
+ const contentType = contentTypes[ext] || 'text/plain';
41
+
42
+ // Inject bonzai capture script for HTML files
43
+ if (ext === '.html' || ext === '.htm') {
44
+ content = content.replace('</body>', '<script src="/bonzai-capture-client.js"></script></body>');
45
+ }
46
+
47
+ res.set('Content-Type', contentType);
48
+ res.send(content);
49
+ } catch (e) {
50
+ res.status(500).send(e.message);
51
+ }
52
+ }
53
+
54
+ module.exports = serveHandler;
55
+
@@ -20,6 +20,8 @@ const revertJobHandler = require('./handlers/revert_job');
20
20
  const shutdownHandler = require('./handlers/shutdown');
21
21
  const scanCodeQualityHandler = require('./handlers/scan_code_quality');
22
22
  const scanStandardsHandler = require('./handlers/scan_standards');
23
+ const bonzaiCaptureClientHandler = require('./handlers/bonzai-capture-client');
24
+ const serveHandler = require('./handlers/serve');
23
25
 
24
26
  const app = express();
25
27
 
@@ -43,6 +45,8 @@ app.post('/revert_job', revertJobHandler);
43
45
  app.post('/shutdown', shutdownHandler);
44
46
  app.post('/scan_code_quality', scanCodeQualityHandler);
45
47
  app.post('/scan_standards', scanStandardsHandler);
48
+ app.get('/bonzai-capture-client.js', bonzaiCaptureClientHandler);
49
+ app.get('/serve', serveHandler);
46
50
 
47
51
  const port = 3001;
48
52
  app.listen(port, () => {