mirror of
https://github.com/Monadical-SAS/reflector.git
synced 2026-03-21 22:56:47 +00:00
* fix: local processing instead of http server for cpu * add fallback token if service worker doesnt work * chore: rename processors to keep processor pattern up to date and allow other processors to be createed and used with env vars
34 lines
948 B
JavaScript
34 lines
948 B
JavaScript
let authToken = null;
|
|
|
|
self.addEventListener("install", () => {
|
|
self.skipWaiting();
|
|
});
|
|
|
|
self.addEventListener("activate", (event) => {
|
|
event.waitUntil(self.clients.claim());
|
|
});
|
|
|
|
self.addEventListener("message", (event) => {
|
|
if (event.data && event.data.type === "SET_AUTH_TOKEN") {
|
|
authToken = event.data.token;
|
|
}
|
|
});
|
|
|
|
self.addEventListener("fetch", function (event) {
|
|
// Check if the request is for a media file (allow optional query params)
|
|
if (/\/v1\/transcripts\/.*\/audio\/mp3(\?|$)/.test(event.request.url)) {
|
|
// Modify the request to add the Authorization header
|
|
const modifiedHeaders = new Headers(event.request.headers);
|
|
if (authToken) {
|
|
modifiedHeaders.append("Authorization", `Bearer ${authToken}`);
|
|
}
|
|
|
|
const modifiedRequest = new Request(event.request, {
|
|
headers: modifiedHeaders,
|
|
});
|
|
|
|
// Respond with the modified request
|
|
event.respondWith(fetch(modifiedRequest));
|
|
}
|
|
});
|