mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2026-09-27 00:00:59 +00:00
* feat: change isProductPro logic (#12712) * fix: tighten frontend RBAC permission guards (#12717) * fix: tighten frontend RBAC permission guards * feat: add permission directive coverage * refactor frontend global store usage * serve frontend routes with fallback --------- Co-authored-by: CityFun <31820853+zhengkunwang223@users.noreply.github.com>
38 lines
1.4 KiB
Go
38 lines
1.4 KiB
Go
import { useGlobalStore } from '@/composables/useGlobalStore';
|
|
import { handleAuthResponseCode, handleAuthResponseStatus } from '@/utils/auth-response';
|
|
|
|
export const checkStreamAuth = async (url: string, currentNode?: string) => {
|
|
const { currentNode: storeCurrentNode, language } = useGlobalStore();
|
|
const controller = new AbortController();
|
|
const timeout = window.setTimeout(() => controller.abort(), 5000);
|
|
try {
|
|
const res = await fetch(url.replace(/^ws/, 'http'), {
|
|
credentials: 'include',
|
|
headers: {
|
|
'Accept-Language': language.value,
|
|
CurrentNode: encodeURIComponent(currentNode || storeCurrentNode.value),
|
|
},
|
|
signal: controller.signal,
|
|
});
|
|
const statusResult = handleAuthResponseStatus(res.status);
|
|
if (statusResult.handled) {
|
|
return statusResult.message;
|
|
}
|
|
const contentType = res.headers.get('content-type') || '';
|
|
if (!contentType.includes('application/json')) {
|
|
await res.body?.cancel();
|
|
return '';
|
|
}
|
|
const data = await res.json();
|
|
const codeResult = handleAuthResponseCode(data);
|
|
if (codeResult.handled) {
|
|
return codeResult.message;
|
|
}
|
|
return '';
|
|
} catch {
|
|
return '';
|
|
} finally {
|
|
window.clearTimeout(timeout);
|
|
}
|
|
};
|