import axios from './axios.js'; // XML Encode function xmlEncode(text) { if (typeof text !== 'string') return ''; return text.replace(/&/g, '&').replace(/} - The full, encrypted URL. */ export async function getEncryptedUrl(relativeUrl, origin) { if (!relativeUrl) { return ''; } const urlParts = relativeUrl.split('?'); if (urlParts.length < 2) { return new URL(relativeUrl, origin).href; } const path = urlParts[0]; const queryString = urlParts[1]; const xmlPayload = ` ${xmlEncode(queryString)} `; const encryptionUrl = new URL('/Common/Agents/ExeFunCommon.aspx', origin).href; try { const response = await axios.post(encryptionUrl, xmlPayload, { headers: { 'Content-Type': 'application/xml', } }); const encryptedQuery = response.data; if (encryptedQuery) { return `${new URL(path, origin).href}?${encodeURIComponent(encryptedQuery)}`; } } catch (error) { console.error(`加密链接失败: ${relativeUrl}`, error.message); } // Fallback to original url on error return new URL(relativeUrl, origin).href; }