Обновить example.html

This commit is contained in:
2025-05-23 14:27:28 +00:00
parent 26ff0bc3c8
commit 5756a77d6c

View File

@@ -19,21 +19,31 @@
<p id="result"></p>
<script type="module">
import init, { get_secret_value } from './hublib.js'; // импортируем функции для wasm
import init, { get_secret_value } from './hublib.js';
async function runWasm() {
await init();
await init();
document.getElementById('getSecretValue').addEventListener('click', async () => {
const userAgent = document.getElementById('userAgent').value || navigator.userAgent; // тупо поле для user agent
const url = document.getElementById('url').value || window.location.href; // тупо поле для url
const userAgent = document.getElementById('userAgent').value || navigator.userAgent;
const url = document.getElementById('url').value || window.location.href;
const serverTs = await fetchServerTimestamp(); // получаем timestamp из эндпоинта (код ниже)
const secretValue = await get_secret_value(BigInt(serverTs.timestamp), userAgent, url); // вставляем всё в функцию генерации подписи
// const asd = await fetch_timestamp();
const serverTs = await fetchServerTimestamp()
const secretValue = await get_secret_value(BigInt(serverTs.timestamp), userAgent, url);
console.log(secretValue)
document.getElementById('result').innerText = secretValue; // подпись выводится на экран. если там вывелась какая-то ошибка, то кринж
document.getElementById('result').innerText = secretValue;
const txt = 'https://api.id.hublab.ru/api/v1/guestlogin?given_time=' +
serverTs.timestamp +
'&user_agent=' + userAgent +
'&gotten_sign=' + secretValue;
const response1 = await makePostRequest(txt)
document.getElementById('result-check').innerText = response1.ok;
});
}
@@ -53,6 +63,24 @@
return null; // Возвращаем null в случае ошибки
}
}
async function makePostRequest(url) {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json', // Указываем, что отправляем данные в формате JSON
},
});
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; // Пробрасываем ошибку дальше
}
}