Add support xiaomi source

This commit is contained in:
Alex X
2025-12-14 13:07:45 +03:00
parent 17c1f69f66
commit a4d4598a13
9 changed files with 1678 additions and 0 deletions
+82
View File
@@ -413,6 +413,88 @@
</script>
<button id="xiaomi">Xiaomi</button>
<div>
<form id="xiaomi-login-form">
<input type="text" name="username" placeholder="username" required>
<input type="password" name="password" placeholder="password" required>
<button type="submit">login</button>
</form>
<form id="xiaomi-captcha-form">
<img id="xiaomi-captcha">
<input type="text" name="captcha" placeholder="captcha" required size="10">
<button type="submit">send</button>
</form>
<form id="xiaomi-verify-form">
<label id="xiaomi-verify"></label>
<input type="text" name="verify" placeholder="verify" required size="10">
<button type="submit">send</button>
</form>
<form id="xiaomi-devices-form">
<select id="xiaomi-id" name="id" required></select>
<select name="region" required>
<option value="cn">China</option>
<option value="de">Europe</option>
<option value="i2">India</option>
<option value="ru">Russia</option>
<option value="sg">Singapore</option>
<option value="us">United States</option>
</select>
<button type="submit">load devices</button>
</form>
<table id="xiaomi-table"></table>
</div>
<script>
async function xiaomiReload(ev) {
if (ev) ev.target.nextElementSibling.style.display = 'grid';
document.getElementById('xiaomi-login-form').style.display = 'flex';
document.getElementById('xiaomi-captcha-form').style.display = 'none';
document.getElementById('xiaomi-verify-form').style.display = 'none';
const r = await fetch('api/xiaomi', {'cache': 'no-cache'});
const data = await r.json();
const users = document.getElementById('xiaomi-id');
users.innerHTML = data.map(item => `<option value="${item}">${item}</option>`).join('');
}
document.getElementById('xiaomi').addEventListener('click', xiaomiReload);
async function xiaomiLogin(ev) {
ev.preventDefault();
const params = new URLSearchParams(new FormData(ev.target));
const r = await fetch('api/xiaomi', {method: 'POST', body: params});
if (r.status === 401) {
/** @type {{captcha: string, verify_email: string, verify_phone: string}} */
const data = await r.json();
document.getElementById('xiaomi-login-form').style.display = 'none';
if (data.captcha) {
document.getElementById('xiaomi-captcha-form').style.display = 'flex';
document.getElementById('xiaomi-captcha').src = 'data:image/jpeg;base64,' + data.captcha;
} else {
document.getElementById('xiaomi-verify-form').style.display = 'flex';
document.getElementById('xiaomi-verify').innerText = data.verify_email || data.verify_phone;
}
} else if (r.ok) {
alert('OK');
xiaomiReload();
} else {
alert('ERROR: ' + await r.text());
}
}
document.getElementById('xiaomi-login-form').addEventListener('submit', xiaomiLogin);
document.getElementById('xiaomi-captcha-form').addEventListener('submit', xiaomiLogin);
document.getElementById('xiaomi-verify-form').addEventListener('submit', xiaomiLogin);
document.getElementById('xiaomi-devices-form').addEventListener('submit', async ev => {
ev.preventDefault();
const params = new URLSearchParams(new FormData(ev.target));
await getSources('xiaomi-table', 'api/xiaomi?' + params.toString());
});
</script>
<button id="webtorrent">WebTorrent Shares</button>
<div>
<table id="webtorrent-table"></table>