buddy-workbench 0.1.1 → 0.1.3

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": "buddy-workbench",
3
- "version": "0.1.1",
3
+ "version": "0.1.3",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,8 +1,31 @@
1
- import { Router } from 'express';
2
- import { clipboardDates, clipboardItems, clipboardOriginal, deleteClipboardItem } from '../services/clipboard-history.js';
1
+ import express, { Router } from 'express';
2
+ import { clipboardDates, clipboardItems, clipboardOriginal, deleteClipboardItem, saveClipboardImage, clipboardImagePath } from '../services/clipboard-history.js';
3
3
 
4
4
  const router = Router();
5
5
  router.get('/', (req, res) => res.json({ dates: clipboardDates(), items: clipboardItems(req.query.date) }));
6
+
7
+ router.post('/image', express.raw({ type: 'image/*', limit: '10mb' }), (req, res) => {
8
+ try {
9
+ const buffer = req.body;
10
+ if (!buffer || buffer.length === 0) {
11
+ return res.status(400).json({ error: 'Image body is empty.' });
12
+ }
13
+ const item = saveClipboardImage(buffer);
14
+ res.json(item);
15
+ } catch (error) {
16
+ res.status(500).json({ error: error.message });
17
+ }
18
+ });
19
+
20
+ router.get('/image/:filename', (req, res) => {
21
+ try {
22
+ const filePath = clipboardImagePath(req.params.filename);
23
+ res.sendFile(filePath);
24
+ } catch (error) {
25
+ res.status(404).json({ error: 'Image not found.' });
26
+ }
27
+ });
28
+
6
29
  router.get('/:date/:id', (req, res) => { const text = clipboardOriginal(req.params.date, req.params.id); if (text === null) return res.status(404).json({ error: 'Clipboard entry not found.' }); res.type('text/plain').send(text); });
7
30
  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(); });
8
31
  export default router;
@@ -29,6 +29,10 @@ export function deleteClipboardItem(date, id) {
29
29
  const contentPath = join(paths.clipboardDir, 'content', item.contentFile);
30
30
  if (existsSync(contentPath)) unlinkSync(contentPath);
31
31
  }
32
+ if (item.imageFile) {
33
+ const imagePath = join(paths.clipboardDir, 'content', item.imageFile);
34
+ if (existsSync(imagePath)) unlinkSync(imagePath);
35
+ }
32
36
  return true;
33
37
  }
34
38
 
@@ -82,4 +86,27 @@ export async function captureClipboard() {
82
86
  } catch {}
83
87
  }
84
88
 
85
- export function startClipboardCapture() { captureClipboard(); const timer = setInterval(captureClipboard, 1000); timer.unref(); }
89
+ export function startClipboardCapture() { captureClipboard(); const timer = setInterval(captureClipboard, 2000); timer.unref(); }
90
+
91
+ export function saveClipboardImage(buffer) {
92
+ const date = today();
93
+ const id = crypto.randomUUID();
94
+ const filename = `${id}.png`;
95
+
96
+ mkdirSync(join(paths.clipboardDir, 'content'), { recursive: true });
97
+ writeFileSync(join(paths.clipboardDir, 'content', filename), buffer);
98
+
99
+ const item = {
100
+ id,
101
+ imageFile: filename,
102
+ createdAt: new Date().toISOString()
103
+ };
104
+
105
+ const items = dayItems(date);
106
+ writeJson(dayFile(date), [item, ...items].slice(0, 200));
107
+ return item;
108
+ }
109
+
110
+ export function clipboardImagePath(filename) {
111
+ return join(paths.clipboardDir, 'content', filename);
112
+ }
@@ -61,7 +61,7 @@ async function observedListeners() {
61
61
  }
62
62
 
63
63
  async function observeLauncherPorts() {
64
- if (!launchHistory.length) return;
64
+ if (!launchHistory.length || running.size === 0) return;
65
65
  const { listeners, groupByPid } = await observedListeners();
66
66
  const now = new Date().toISOString();
67
67
  let changed = false;