Обновить example.html
This commit is contained in:
42
example.html
42
example.html
@@ -19,21 +19,31 @@
|
|||||||
<p id="result"></p>
|
<p id="result"></p>
|
||||||
|
|
||||||
<script type="module">
|
<script type="module">
|
||||||
import init, { get_secret_value } from './hublib.js'; // импортируем функции для wasm
|
import init, { get_secret_value } from './hublib.js';
|
||||||
|
|
||||||
async function runWasm() {
|
async function runWasm() {
|
||||||
await init();
|
await init();
|
||||||
|
|
||||||
|
|
||||||
document.getElementById('getSecretValue').addEventListener('click', async () => {
|
document.getElementById('getSecretValue').addEventListener('click', async () => {
|
||||||
const userAgent = document.getElementById('userAgent').value || navigator.userAgent; // тупо поле для user agent
|
const userAgent = document.getElementById('userAgent').value || navigator.userAgent;
|
||||||
const url = document.getElementById('url').value || window.location.href; // тупо поле для url
|
const url = document.getElementById('url').value || window.location.href;
|
||||||
|
|
||||||
const serverTs = await fetchServerTimestamp(); // получаем timestamp из эндпоинта (код ниже)
|
const serverTs = await fetchServerTimestamp()
|
||||||
const secretValue = await get_secret_value(BigInt(serverTs.timestamp), userAgent, url); // вставляем всё в функцию генерации подписи
|
const secretValue = await get_secret_value(BigInt(serverTs.timestamp), userAgent, url);
|
||||||
// const asd = await fetch_timestamp();
|
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 в случае ошибки
|
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; // Пробрасываем ошибку дальше
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user