opencode-plugin-boops 2.5.3 → 2.6.1

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.
Files changed (2) hide show
  1. package/index.ts +20 -20
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -171,35 +171,35 @@ export const BoopsPlugin: Plugin = async ({ client }) => {
171
171
  }
172
172
  }
173
173
 
174
- // Get cache path for an event (no extension, stores by event name)
175
- const getCachePath = (eventName: string): string => {
176
- // Sanitize event name for filesystem (replace dots with dashes)
177
- const safeName = eventName.replace(/\./g, "-")
178
- return join(cacheDir, safeName)
174
+ // Get cache path for a sound (uses URL hash to ensure uniqueness)
175
+ const getCachePath = (url: string): string => {
176
+ // Use a hash of the URL to ensure unique cache keys
177
+ // This works for all URLs (notificationsounds.com, custom URLs, etc.)
178
+ const hash = Bun.hash(url).toString(16)
179
+
180
+ // Try to preserve the file extension for better debugging
181
+ let ext = '.ogg'
182
+ try {
183
+ const urlObj = new URL(url)
184
+ const pathname = urlObj.pathname
185
+ const extMatch = pathname.match(/\.(\w+)$/)
186
+ if (extMatch) ext = `.${extMatch[1]}`
187
+ } catch {
188
+ // Use default extension if URL parsing fails
189
+ }
190
+
191
+ return join(cacheDir, `${hash}${ext}`)
179
192
  }
180
193
 
181
- // Download and cache a sound file from URL for a specific event
194
+ // Download and cache a sound file from URL
182
195
  const downloadSound = async (url: string, eventName: string): Promise<string> => {
183
- const cachedPath = getCachePath(eventName)
196
+ const cachedPath = getCachePath(url)
184
197
 
185
198
  // Return cached file if it exists
186
199
  if (existsSync(cachedPath)) {
187
200
  return cachedPath
188
201
  }
189
202
 
190
- // Delete any old cached file for this event (in case URL changed)
191
- try {
192
- const files = await readdir(cacheDir)
193
- const safeName = eventName.replace(/\./g, "-")
194
- for (const file of files) {
195
- if (file.startsWith(safeName)) {
196
- await unlink(join(cacheDir, file))
197
- }
198
- }
199
- } catch {
200
- // Ignore errors
201
- }
202
-
203
203
  // Download the file
204
204
  await log(`Downloading sound for ${eventName}: ${url}`)
205
205
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "opencode-plugin-boops",
3
- "version": "2.5.3",
3
+ "version": "2.6.1",
4
4
  "description": "Sound notifications for OpenCode - plays pleasant sounds when tasks complete or input is needed",
5
5
  "main": "index.ts",
6
6
  "type": "module",