buddy-workbench 0.1.34 → 0.1.36
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 +1 -1
- package/server/middleware/compression.js +43 -0
- package/server/routes/clipboard.js +5 -2
- package/server.js +2 -0
- package/ui/dist/assets/index-B6AAdOoQ.js +534 -0
- package/ui/dist/assets/{index-B0npoG1F.css → index-BEE8irw_.css} +1 -1
- package/ui/dist/index.html +75 -2
- package/ui/dist/assets/index-MvbbPuFE.js +0 -534
package/package.json
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { gzipSync } from 'node:zlib';
|
|
2
|
+
|
|
3
|
+
const COMPRESSIBLE_TYPES = /^(text\/|application\/(javascript|json|xml|wasm)|image\/svg\+xml)/i;
|
|
4
|
+
const MIN_SIZE = 1024;
|
|
5
|
+
|
|
6
|
+
// Express static sends the bundled assets in one response. Buffering only those
|
|
7
|
+
// responses lets us compress them without adding another runtime dependency.
|
|
8
|
+
export function compression(req, res, next) {
|
|
9
|
+
const isUiAsset = req.path === '/' || req.path === '/index.html' || req.path.startsWith('/assets/');
|
|
10
|
+
if (!isUiAsset) return next();
|
|
11
|
+
|
|
12
|
+
const chunks = [];
|
|
13
|
+
const originalEnd = res.end;
|
|
14
|
+
|
|
15
|
+
res.write = function write(chunk, encoding) {
|
|
16
|
+
if (chunk) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding));
|
|
17
|
+
return true;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
res.end = function end(chunk, encoding) {
|
|
21
|
+
if (chunk) chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding));
|
|
22
|
+
const body = Buffer.concat(chunks);
|
|
23
|
+
const contentType = String(res.getHeader('content-type') || '');
|
|
24
|
+
const acceptsGzip = /\bgzip\b/i.test(req.headers['accept-encoding'] || '');
|
|
25
|
+
const shouldCompress = acceptsGzip
|
|
26
|
+
&& body.length >= MIN_SIZE
|
|
27
|
+
&& COMPRESSIBLE_TYPES.test(contentType)
|
|
28
|
+
&& !res.getHeader('content-encoding')
|
|
29
|
+
&& req.method !== 'HEAD';
|
|
30
|
+
|
|
31
|
+
if (shouldCompress) {
|
|
32
|
+
const compressed = gzipSync(body, { level: 6 });
|
|
33
|
+
res.removeHeader('content-length');
|
|
34
|
+
res.setHeader('Content-Encoding', 'gzip');
|
|
35
|
+
res.setHeader('Vary', 'Accept-Encoding');
|
|
36
|
+
return originalEnd.call(res, compressed);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return originalEnd.call(res, body);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
next();
|
|
43
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import express, { Router } from 'express';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
3
|
import { clipboardDates, clipboardItems, clipboardOriginal, deleteClipboardItem, saveClipboardImage, clipboardImagePath, allTaggedClipboardItems, updateClipboardItemTags, markClipboardCopied } from '../services/clipboard-history.js';
|
|
3
4
|
|
|
4
5
|
const router = Router();
|
|
@@ -23,7 +24,10 @@ router.post('/image', express.raw({ type: 'image/*', limit: '10mb' }), (req, res
|
|
|
23
24
|
router.get('/image/:filename', (req, res) => {
|
|
24
25
|
try {
|
|
25
26
|
const filePath = clipboardImagePath(req.params.filename);
|
|
26
|
-
|
|
27
|
+
if (!existsSync(filePath)) {
|
|
28
|
+
return res.status(404).json({ error: 'Image not found.' });
|
|
29
|
+
}
|
|
30
|
+
res.type(filePath).send(readFileSync(filePath));
|
|
27
31
|
} catch (error) {
|
|
28
32
|
res.status(404).json({ error: 'Image not found.' });
|
|
29
33
|
}
|
|
@@ -46,4 +50,3 @@ router.post('/:date/:id/copied', async (req, res) => {
|
|
|
46
50
|
});
|
|
47
51
|
router.delete('/:date/:id', (req, res) => { if (!deleteClipboardItem(req.params.date, req.params.id)) return res.status(404).json({ error: 'Clipboard entry not found.' }); res.status(204).end(); });
|
|
48
52
|
export default router;
|
|
49
|
-
|
package/server.js
CHANGED
|
@@ -26,10 +26,12 @@ import dataBackupRoutes from './server/routes/data-backup.js';
|
|
|
26
26
|
import presentationsRoutes from './server/routes/presentations.js';
|
|
27
27
|
import { addErrorRecord } from './server/repositories/errors.js';
|
|
28
28
|
import { startClipboardCapture } from './server/services/clipboard-history.js';
|
|
29
|
+
import { compression } from './server/middleware/compression.js';
|
|
29
30
|
|
|
30
31
|
const port = Number(process.env.PORT || 3100);
|
|
31
32
|
const app = express();
|
|
32
33
|
app.use(express.json());
|
|
34
|
+
app.use(compression);
|
|
33
35
|
|
|
34
36
|
// Intercept error responses (HTTP status >= 400) from any API route
|
|
35
37
|
app.use((req, res, next) => {
|