devbonzai 2.2.209 → 2.2.211
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
|
@@ -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,34 @@
|
|
|
1
|
+
const http = require('http');
|
|
2
|
+
const { URL } = require('url');
|
|
3
|
+
|
|
4
|
+
function proxyHandler(req, res) {
|
|
5
|
+
// Target dev server (default localhost:3000, or pass ?target=...)
|
|
6
|
+
const target = req.query.target || 'http://localhost:3000';
|
|
7
|
+
// Path to fetch (default /)
|
|
8
|
+
const path = req.query.path || '/';
|
|
9
|
+
|
|
10
|
+
const fullUrl = new URL(path, target);
|
|
11
|
+
|
|
12
|
+
http.get(fullUrl.toString(), (proxyRes) => {
|
|
13
|
+
let body = '';
|
|
14
|
+
|
|
15
|
+
proxyRes.on('data', chunk => body += chunk);
|
|
16
|
+
proxyRes.on('end', () => {
|
|
17
|
+
const contentType = proxyRes.headers['content-type'] || '';
|
|
18
|
+
|
|
19
|
+
// Inject capture script into HTML
|
|
20
|
+
if (contentType.includes('text/html')) {
|
|
21
|
+
body = body.replace('</body>', '<script src="/bonzai-capture-client.js"></script></body>');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Forward content-type
|
|
25
|
+
res.set('Content-Type', contentType);
|
|
26
|
+
res.send(body);
|
|
27
|
+
});
|
|
28
|
+
}).on('error', (err) => {
|
|
29
|
+
res.status(502).send('Proxy error: ' + err.message);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = proxyHandler;
|
|
34
|
+
|
|
@@ -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
|
+
|
package/templates/receiver.js
CHANGED
|
@@ -20,6 +20,9 @@ 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');
|
|
25
|
+
const proxyHandler = require('./handlers/proxy');
|
|
23
26
|
|
|
24
27
|
const app = express();
|
|
25
28
|
|
|
@@ -43,6 +46,9 @@ app.post('/revert_job', revertJobHandler);
|
|
|
43
46
|
app.post('/shutdown', shutdownHandler);
|
|
44
47
|
app.post('/scan_code_quality', scanCodeQualityHandler);
|
|
45
48
|
app.post('/scan_standards', scanStandardsHandler);
|
|
49
|
+
app.get('/bonzai-capture-client.js', bonzaiCaptureClientHandler);
|
|
50
|
+
app.get('/serve', serveHandler);
|
|
51
|
+
app.get('/proxy', proxyHandler);
|
|
46
52
|
|
|
47
53
|
const port = 3001;
|
|
48
54
|
app.listen(port, () => {
|