Files
hublib-web/web/example.html

88 lines
3.3 KiB
HTML
Raw Normal View History

2025-05-27 13:17:11 +03:00
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>WASM Example</title>
</head>
<body>
<h1>WASM Example</h1>
<button id="getSecretValue">Получить секретное значение</button>
<p id="result"></p>
<script type="module">
import init, { get_secret_value } from './hublib.js';
async function runWasm() {
await init();
document.getElementById('getSecretValue').addEventListener('click', async () => {
2025-05-28 12:37:31 +03:00
const tmp = Math.floor(Date.now() / 1000);
const secretValue = get_secret_value(
2025-05-28 17:10:45 +03:00
getHTTPFormattedTime(),
2025-05-28 12:37:31 +03:00
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
'/api/v1/guestlogin'
);
2025-05-27 13:17:11 +03:00
document.getElementById('result').innerText = secretValue;
2025-05-28 12:37:31 +03:00
const txt = 'https://api.id.hublab.ru/api/v1/guestlogin'
2025-05-27 13:17:11 +03:00
2025-05-28 12:37:31 +03:00
const response1 = await makePostRequest(
txt,
{
'X-SIGN': secretValue,
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36',
'Accept-Time': tmp
}
)
2025-05-27 13:17:11 +03:00
});
}
2025-05-28 12:37:31 +03:00
async function makePostRequest(url, headers) {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
...headers, // Расширяем заголовки
},
});
if (!response.ok) {
throw new Error(`HTTP error! Статус: ${response.status}`);
}
const responseData = await response.json(); // Получаем ответ как JSON
return responseData; // Возвращаем полученные данные
} catch (error) {
console.error('Ошибка при выполнении POST-запроса:', error);
throw error; // Пробрасываем ошибку дальше
}
}
2025-05-27 13:17:11 +03:00
2025-05-28 17:10:45 +03:00
function getHTTPFormattedTime() {
const now = new Date();
const days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const day = days[now.getUTCDay()];
const date = now.getUTCDate().toString().padStart(2, '0');
const month = months[now.getUTCMonth()];
const year = now.getUTCFullYear();
const hours = now.getUTCHours().toString().padStart(2, '0');
const minutes = now.getUTCMinutes().toString().padStart(2, '0');
const seconds = now.getUTCSeconds().toString().padStart(2, '0');
return `${day}, ${date} ${month} ${year} ${hours}:${minutes}:${seconds} GMT`;
}
const httpTime = getHTTPFormattedTime();
2025-05-27 13:17:11 +03:00
runWasm();
</script>
</body>
</html>