diff --git a/lib/voe-account-storage.js b/lib/voe-account-storage.js new file mode 100644 index 0000000..565c883 --- /dev/null +++ b/lib/voe-account-storage.js @@ -0,0 +1,23 @@ +function parseStorageAmount(html) { + const text = String(html).replace(/<[^>]*>/g, '').replace(/ | | /gi, ' ').trim(); + const match = text.match(/^([\d.,]+)\s*(B|[KMGTPE]i?B)$/i); + if (!match) return null; + const value = Number(match[1].replace(',', '.')); + if (!Number.isFinite(value) || value < 0) return null; + return { value, unit: match[2].toUpperCase() }; +} + +function parseVoeAccountStorage(html) { + const sidebar = String(html || '').match(/]*\bid\s*=\s*["']sidebarMenu["'][^>]*>([\s\S]*?)<\/nav\s*>/i)?.[1]; + if (!sidebar) return null; + for (const match of sidebar.matchAll(/]*>([\s\S]*?)<\/small\s*>/gi)) { + const spans = [...match[1].matchAll(/]*)>([\s\S]*?)<\/span\s*>/gi)]; + if (spans.length !== 2 || !/\bfloat-end\b/.test(spans[1][1])) continue; + const used = parseStorageAmount(spans[0][2]); + const total = parseStorageAmount(spans[1][2]); + if (used && total && total.value > 0) return { used, total }; + } + return null; +} + +module.exports = { parseVoeAccountStorage }; diff --git a/lib/voe-upload.js b/lib/voe-upload.js index 4c105c3..0ffc663 100644 --- a/lib/voe-upload.js +++ b/lib/voe-upload.js @@ -2,6 +2,7 @@ const fs = require('fs'); const path = require('path'); const crypto = require('crypto'); const { request } = require('undici'); +const { parseVoeAccountStorage } = require('./voe-account-storage'); const BASE_URL = 'https://voe.sx'; const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36'; @@ -152,7 +153,7 @@ class VoeUploader { throw new Error('VOE Upload: CSRF-Token nicht gefunden. Bist du eingeloggt?'); } - return { csrfToken }; + return { csrfToken, storage: parseVoeAccountStorage(html) }; } /** diff --git a/main.js b/main.js index 72d2e63..e2a64b0 100644 --- a/main.js +++ b/main.js @@ -1395,7 +1395,7 @@ async function checkVoeHealth(hosterConfig) { const uploader = new VoeUploader(); await uploader.login(username, password); - const { csrfToken } = await uploader._getUploadParams(); + const { csrfToken, storage } = await uploader._getUploadParams(); if (!csrfToken) { return { status: 'error', message: 'Login ok, aber Upload-Seite liefert kein CSRF-Token' }; @@ -1403,7 +1403,8 @@ async function checkVoeHealth(hosterConfig) { return { status: 'ok', - message: 'Login ok, Upload-Seite bereit' + message: 'Login ok, Upload-Seite bereit', + storage }; } diff --git a/renderer/account-status.js b/renderer/account-status.js index fc1bbf9..33894dc 100644 --- a/renderer/account-status.js +++ b/renderer/account-status.js @@ -52,7 +52,21 @@ if (typeof api?.getSessionFailedAccounts === 'function') apply(await api.getSessionFailedAccounts()); } + function formatAccountStorage(storage, locale = 'en-US') { + const formatAmount = amount => { + if (!amount || typeof amount.value !== 'number' || !Number.isFinite(amount.value) || amount.value < 0 + || !/^(B|[KMGTPE]I?B)$/.test(amount.unit || '')) return null; + const unit = amount.unit.replace('IB', 'iB'); + return `${new Intl.NumberFormat(locale, { minimumFractionDigits: 2, maximumFractionDigits: 2 }).format(amount.value)} ${unit}`; + }; + const used = formatAmount(storage?.used); + const total = formatAmount(storage?.total); + if (!used || !total || storage.total.value <= 0) return null; + return `${used} ${String(locale).startsWith('de') ? 'von' : 'of'} ${total}`; + } + const accountStatus = { + formatAccountStorage, formatAccountPauseRemaining, getAccountGroupStatus, getAccountPausePresentation, diff --git a/renderer/app.js b/renderer/app.js index 161763a..abe17eb 100644 --- a/renderer/app.js +++ b/renderer/app.js @@ -6212,6 +6212,7 @@ async function executeHealthCheck(hosters, _mode, generations) { accountStatuses[key] = { status: row.status || 'unchecked', message: row.message || '', + storage: row.storage || null, checkedAt: row.checkedAt || checkedAt }; if (row.accountId) updateAccountCard(row.accountId); @@ -7611,6 +7612,10 @@ function _buildAccountCardHtml(name, account, idx) { const toggleLabel = isDisabled ? 'Aktivieren' : 'Deaktivieren'; const priorityLabel = idx === 0 ? 'Primär' : `Fallback #${idx}`; const checkLabel = statusPresentation.requiresOtp ? 'Neuen Code anfordern' : 'Prüfen'; + const storageText = name === 'voe.sx' ? window.AccountStatus.formatAccountStorage(st.storage, getUiLocale()) : null; + const storageHtml = storageText + ? `` + : ''; const sessionPauseKey = `${name}:${account.id}`; const sessionPause = _sessionFailedAccountStates.get(sessionPauseKey) @@ -7632,6 +7637,7 @@ function _buildAccountCardHtml(name, account, idx) {