MCPcopy Create free account
hub / github.com/1Panel-dev/1Panel / checkStreamAuth

Function checkStreamAuth

frontend/src/utils/stream-auth.ts:4–37  ·  view source on GitHub ↗
(url: string, currentNode?: string)

Source from the content-addressed store, hash-verified

2import { handleAuthResponseCode, handleAuthResponseStatus } from '@/utils/auth-response';
3
4export const checkStreamAuth = async (url: string, currentNode?: string) => {
5 const { currentNode: storeCurrentNode, language } = useGlobalStore();
6 const controller = new AbortController();
7 const timeout = window.setTimeout(() => controller.abort(), 5000);
8 try {
9 const res = await fetch(url.replace(/^ws/, 'http'), {
10 credentials: 'include',
11 headers: {
12 'Accept-Language': language.value,
13 CurrentNode: encodeURIComponent(currentNode || storeCurrentNode.value),
14 },
15 signal: controller.signal,
16 });
17 const statusResult = handleAuthResponseStatus(res.status);
18 if (statusResult.handled) {
19 return statusResult.message;
20 }
21 const contentType = res.headers.get('content-type') || '';
22 if (!contentType.includes('application/json')) {
23 await res.body?.cancel();
24 return '';
25 }
26 const data = await res.json();
27 const codeResult = handleAuthResponseCode(data);
28 if (codeResult.handled) {
29 return codeResult.message;
30 }
31 return '';
32 } catch {
33 return '';
34 } finally {
35 window.clearTimeout(timeout);
36 }
37};

Callers 1

initWebSocketFunction · 0.90

Calls 4

useGlobalStoreFunction · 0.90
handleAuthResponseStatusFunction · 0.90
handleAuthResponseCodeFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected