buddy-workbench 0.1.102 → 0.1.104

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.102",
3
+ "version": "0.1.104",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "bin": {
@@ -1,9 +1,10 @@
1
1
  import express, { Router } from 'express';
2
2
  import { existsSync, readFileSync } from 'node:fs';
3
- import { clipboardDates, clipboardItems, clipboardOriginal, deleteClipboardItem, saveClipboardImage, clipboardImagePath, allTaggedClipboardItems, updateClipboardItemTags, markClipboardCopied, copyClipboardImage } from '../services/clipboard-history.js';
3
+ import { clipboardDates, clipboardItems, searchClipboardItems, clipboardOriginal, deleteClipboardItem, saveClipboardImage, clipboardImagePath, allTaggedClipboardItems, updateClipboardItemTags, markClipboardCopied, copyClipboardImage } from '../services/clipboard-history.js';
4
4
 
5
5
  const router = Router();
6
6
  router.get('/', (req, res) => res.json({ dates: clipboardDates(), items: clipboardItems(req.query.date) }));
7
+ router.get('/search', (req, res) => res.json({ items: searchClipboardItems(req.query.q) }));
7
8
  router.get('/tagged', (_req, res) => res.json({ items: allTaggedClipboardItems() }));
8
9
 
9
10
  router.post('/image', express.raw({ type: 'image/*', limit: '10mb' }), (req, res) => {
@@ -210,6 +210,36 @@ function getEditorUrl(editor = 'vscode', path = '') {
210
210
 
211
211
  function dayItems(date) { return readJson(dayFile(date), []); }
212
212
 
213
+ function getClipboardEditorDetails() {
214
+ const settings = readSettings();
215
+ const editor = settings.defaultEditor || 'vscode';
216
+ return {
217
+ editor,
218
+ editorName: editor === 'idea' ? 'IntelliJ IDEA' : editor === 'devin' ? 'Devin' : 'VS Code'
219
+ };
220
+ }
221
+
222
+ function withClipboardEditorDetails(item, date, editorDetails) {
223
+ const itemWithDate = date ? { ...item, date } : item;
224
+ if (!item.contentFile) return itemWithDate;
225
+ const { editor, editorName } = editorDetails || getClipboardEditorDetails();
226
+ return {
227
+ ...itemWithDate,
228
+ editorUrl: getEditorUrl(editor, join(paths.clipboardDir, 'content', item.contentFile)),
229
+ editorName
230
+ };
231
+ }
232
+
233
+ function clipboardSearchValue(item) {
234
+ const values = [item.text, item.preview, ...(Array.isArray(item.tags) ? item.tags : [])];
235
+ if (item.contentFile) {
236
+ try {
237
+ values.push(readFileSync(join(paths.clipboardDir, 'content', item.contentFile), 'utf8'));
238
+ } catch {}
239
+ }
240
+ return values.filter(Boolean).join('\n').toLowerCase();
241
+ }
242
+
213
243
  async function getClipboardText() {
214
244
  if (process.platform === 'win32') {
215
245
  try { return await readWindowsClipboard(); } catch { return ''; }
@@ -237,10 +267,16 @@ async function getClipboardText() {
237
267
  }
238
268
 
239
269
  export function clipboardItems(date = today()) {
240
- const settings = readSettings();
241
- const editor = settings.defaultEditor || 'vscode';
242
- const editorName = editor === 'idea' ? 'IntelliJ IDEA' : editor === 'devin' ? 'Devin' : 'VS Code';
243
- return dayItems(date).map((item) => item.contentFile ? { ...item, editorUrl: getEditorUrl(editor, join(paths.clipboardDir, 'content', item.contentFile)), editorName } : item);
270
+ const editorDetails = getClipboardEditorDetails();
271
+ return dayItems(date).map((item) => withClipboardEditorDetails(item, undefined, editorDetails));
272
+ }
273
+ export function searchClipboardItems(query) {
274
+ const normalizedQuery = String(query || '').trim().toLowerCase();
275
+ if (!normalizedQuery) return [];
276
+ const editorDetails = getClipboardEditorDetails();
277
+ return clipboardDates().flatMap((date) => dayItems(date)
278
+ .filter((item) => clipboardSearchValue(item).includes(normalizedQuery))
279
+ .map((item) => withClipboardEditorDetails(item, date, editorDetails)));
244
280
  }
245
281
  export function allTaggedClipboardItems() {
246
282
  const settings = readSettings();