changed structure
This commit is contained in:
88
example.html
Normal file
88
example.html
Normal file
@@ -0,0 +1,88 @@
|
||||
<!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 userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36'
|
||||
const path = '/api/v1/guestlogin';
|
||||
const time = getHTTPFormattedTime();
|
||||
|
||||
const secretValue = get_secret_value(
|
||||
time,
|
||||
userAgent,
|
||||
path
|
||||
);
|
||||
|
||||
document.getElementById('result').innerText = secretValue;
|
||||
|
||||
const txt = 'https://api.id.hublab.ru/api/v1/guestlogin';
|
||||
const response1 = await makePostRequest(
|
||||
txt,
|
||||
{
|
||||
'X-Request-Time': getHTTPFormattedTime(),
|
||||
'Client-info': secretValue,
|
||||
'User-Agent': userAgent,
|
||||
}
|
||||
)
|
||||
|
||||
});
|
||||
}
|
||||
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; // Пробрасываем ошибку дальше
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
|
||||
|
||||
runWasm();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user