70 lines
2.5 KiB
HTML
70 lines
2.5 KiB
HTML
<!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 () => {
|
|
const tmp = Math.floor(Date.now() / 1000);
|
|
const secretValue = get_secret_value(
|
|
BigInt(tmp),
|
|
'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'
|
|
);
|
|
|
|
|
|
|
|
document.getElementById('result').innerText = secretValue;
|
|
|
|
const txt = 'https://api.id.hublab.ru/api/v1/guestlogin'
|
|
|
|
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
|
|
}
|
|
)
|
|
|
|
});
|
|
}
|
|
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; // Пробрасываем ошибку дальше
|
|
}
|
|
}
|
|
|
|
|
|
|
|
runWasm();
|
|
</script>
|
|
</body>
|
|
</html> |