mirror of
https://github.com/filebrowser/filebrowser.git
synced 2025-05-08 11:22:10 +00:00

--------- Co-authored-by: Joep <jcbuhre@gmail.com> Co-authored-by: Omar Hussein <omarmohammad1951@gmail.com> Co-authored-by: Oleg Lobanov <oleg@lobanov.me>
24 lines
668 B
TypeScript
24 lines
668 B
TypeScript
import { removePrefix } from "./utils";
|
|
import { baseURL } from "@/utils/constants";
|
|
import { useAuthStore } from "@/stores/auth";
|
|
|
|
const ssl = window.location.protocol === "https:";
|
|
const protocol = ssl ? "wss:" : "ws:";
|
|
|
|
export default function command(
|
|
url: string,
|
|
command: string,
|
|
onmessage: WebSocket["onmessage"],
|
|
onclose: WebSocket["onclose"]
|
|
) {
|
|
const authStore = useAuthStore();
|
|
|
|
url = removePrefix(url);
|
|
url = `${protocol}//${window.location.host}${baseURL}/api/command${url}?auth=${authStore.jwt}`;
|
|
|
|
const conn = new window.WebSocket(url);
|
|
conn.onopen = () => conn.send(command);
|
|
conn.onmessage = onmessage;
|
|
conn.onclose = onclose;
|
|
}
|