Skip to content

Commit 14d0d04

Browse files
committed
Remove handlers from background-main
1 parent 32e0dfd commit 14d0d04

1 file changed

Lines changed: 0 additions & 40 deletions

File tree

ext/js/background/background-main.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,49 +17,9 @@
1717
*/
1818

1919
import {log} from '../core/log.js';
20-
import {toError} from '../core/to-error.js';
2120
import {WebExtension} from '../extension/web-extension.js';
2221
import {Backend} from './backend.js';
2322

24-
/**
25-
* @param {string} url
26-
* @returns {Promise<{data: string, contentType: string}>}
27-
*/
28-
async function fetchLocalAudioData(url) {
29-
const response = await fetch(url);
30-
if (!response.ok) {
31-
throw new Error(`Local server responded with HTTP status code ${response.status}`);
32-
}
33-
34-
const contentType = response.headers.get('content-type') || 'audio/mpeg';
35-
const arrayBuffer = await response.arrayBuffer();
36-
37-
let binary = '';
38-
const bytes = new Uint8Array(arrayBuffer);
39-
for (let i = 0; i < bytes.byteLength; i++) {
40-
binary += String.fromCharCode(bytes[i]);
41-
}
42-
43-
return {
44-
data: btoa(binary),
45-
contentType: contentType,
46-
};
47-
}
48-
49-
chrome.runtime.onMessage.addListener((message, _sender, sendResponse) => {
50-
if (message.type === 'FETCH_LOCAL_AUDIO_DATA') {
51-
const url = /** @type {unknown} */ (message.url);
52-
if (typeof url !== 'string') {
53-
sendResponse({success: false, error: 'Invalid or missing URL parameter'});
54-
return false;
55-
}
56-
fetchLocalAudioData(url)
57-
.then((result) => sendResponse({success: true, data: result.data, contentType: result.contentType}))
58-
.catch((error) => sendResponse({success: false, error: toError(error).message}));
59-
return true;
60-
}
61-
});
62-
6323
/** Entry point. */
6424
async function main() {
6525
const webExtension = new WebExtension();

0 commit comments

Comments
 (0)