Compare commits
2 Commits
release-20
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e878d1fe33 | ||
|
|
d88084fb9a |
@@ -88,10 +88,13 @@ pub fn provide_torrent_store() {
|
||||
let mut disconnect_notified = false;
|
||||
|
||||
loop {
|
||||
log::info!("[SSE] Attempting to connect to /api/events...");
|
||||
let es_result = EventSource::new("/api/events");
|
||||
match es_result {
|
||||
Ok(mut es) => {
|
||||
log::info!("[SSE] EventSource instantiated successfully.");
|
||||
if let Ok(mut stream) = es.subscribe("message") {
|
||||
log::info!("[SSE] Subscribed to 'message' events.");
|
||||
let mut got_first_message = false;
|
||||
while let Some(Ok((_, msg))) = stream.next().await {
|
||||
if !got_first_message {
|
||||
@@ -105,6 +108,7 @@ pub fn provide_torrent_store() {
|
||||
}
|
||||
|
||||
if let Some(data_str) = msg.data().as_string() {
|
||||
log::info!("[SSE] Received message: {:?}", data_str.chars().take(50).collect::<String>());
|
||||
match BASE64.decode(&data_str) {
|
||||
Ok(bytes) => {
|
||||
match rmp_serde::from_slice::<AppEvent>(&bytes) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const CACHE_NAME = "vibetorrent-v2";
|
||||
const CACHE_NAME = "vibetorrent-v3";
|
||||
const ASSETS_TO_CACHE = [
|
||||
"/",
|
||||
"/index.html",
|
||||
@@ -51,6 +51,11 @@ self.addEventListener("activate", (event) => {
|
||||
self.addEventListener("fetch", (event) => {
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
// Skip unsupported schemes (like chrome-extension://)
|
||||
if (!url.protocol.startsWith("http")) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Network-first strategy for API calls
|
||||
if (url.pathname.startsWith("/api/")) {
|
||||
event.respondWith(
|
||||
@@ -75,10 +80,12 @@ self.addEventListener("fetch", (event) => {
|
||||
fetch(event.request)
|
||||
.then((response) => {
|
||||
// Cache the latest version of the HTML
|
||||
const responseToCache = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
if (response && response.status === 200) {
|
||||
const responseToCache = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
cache.put(event.request, responseToCache);
|
||||
});
|
||||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => {
|
||||
|
||||
Reference in New Issue
Block a user