From 5a6c4128455a5b23e909a89fc3f201f183fe868b Mon Sep 17 00:00:00 2001 From: Will Miao <13051207myq@gmail.com> Date: Tue, 11 Mar 2025 15:08:52 +0800 Subject: [PATCH] Update WebSocket connection to use secure protocol based on current window location --- static/js/api/loraApi.js | 3 ++- static/js/managers/DownloadManager.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/static/js/api/loraApi.js b/static/js/api/loraApi.js index fe961412..86278c21 100644 --- a/static/js/api/loraApi.js +++ b/static/js/api/loraApi.js @@ -113,7 +113,8 @@ export async function fetchCivitai() { await state.loadingManager.showWithProgress(async (loading) => { try { - ws = new WebSocket(`ws://${window.location.host}/ws/fetch-progress`); + const wsProtocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; + const ws = new WebSocket(`${wsProtocol}${window.location.host}/ws/fetch-progress`); const operationComplete = new Promise((resolve, reject) => { ws.onmessage = (event) => { diff --git a/static/js/managers/DownloadManager.js b/static/js/managers/DownloadManager.js index 2a0f5746..75631bb1 100644 --- a/static/js/managers/DownloadManager.js +++ b/static/js/managers/DownloadManager.js @@ -269,7 +269,8 @@ export class DownloadManager { this.loadingManager.show('Downloading LoRA...', 0); // Setup WebSocket for progress updates - const ws = new WebSocket(`ws://${window.location.host}/ws/fetch-progress`); + const wsProtocol = window.location.protocol === 'https:' ? 'wss://' : 'ws://'; + const ws = new WebSocket(`${wsProtocol}${window.location.host}/ws/fetch-progress`); ws.onmessage = (event) => { const data = JSON.parse(event.data); if (data.status === 'progress') {