SHA256
Смерджить свежий main в голосовые сообщения
Подтянуты изменения main до d9a91875 (аудит API, учёт публикации блоков,
звонки и настройки). Конфликт только в VERSION.properties: client 1.21.7,
server 1.17.5 — выше main и PR очереди выплат.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -41,6 +41,8 @@ import {
|
||||
saveSessionMaterial,
|
||||
} from './key-vault.js';
|
||||
import { signEventContainer, submitSignedEvent, readStoredLineMeta } from './core-content.js';
|
||||
import { showToast } from './channels-ux.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
import { defaultServerWs } from '../deploy-config.js';
|
||||
import { readPendingHeaderIdentity, clearPendingHeaderIdentity } from './pending-header-identity.js';
|
||||
|
||||
@@ -1172,6 +1174,14 @@ export class AuthService {
|
||||
const connectionScope = String(createResp?.payload?.connectionScope || '').trim().toUpperCase();
|
||||
|
||||
const canonicalLogin = await this.resolveCanonicalDisplayLogin(cleanLogin);
|
||||
void (async () => {
|
||||
try {
|
||||
const user = await this.getUser(canonicalLogin);
|
||||
const { publishPendingBlocks } = await import('./block-publication-service.js');
|
||||
await publishPendingBlocks({ ws: this.ws, login: canonicalLogin, storagePwd,
|
||||
blockchainName: String(user?.blockchainName || `${canonicalLogin}-${BCH_SUFFIX}`) });
|
||||
} catch (error) { console.warn('Block publication resume failed', error); }
|
||||
})();
|
||||
|
||||
return {
|
||||
login: canonicalLogin,
|
||||
@@ -1314,12 +1324,13 @@ export class AuthService {
|
||||
const cleanLogin = (login || '').trim();
|
||||
if (!cleanLogin) throw new Error('Нет login для авто-входа');
|
||||
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin, targetSessionId);
|
||||
const requestedSessionId = String(preferredSessionId || '').trim();
|
||||
const sessionMaterial = await loadSessionMaterial(cleanLogin, requestedSessionId);
|
||||
if (!sessionMaterial?.sessionId || !sessionMaterial?.sessionKey || !sessionMaterial?.sessionPrivPkcs8) {
|
||||
throw new Error('На устройстве нет сохраненного ключа сессии');
|
||||
}
|
||||
|
||||
const targetSessionId = preferredSessionId || sessionMaterial.sessionId;
|
||||
const targetSessionId = requestedSessionId || sessionMaterial.sessionId;
|
||||
const privateKey = await importPkcs8Ed25519(sessionMaterial.sessionPrivPkcs8);
|
||||
|
||||
const challengeResp = await this.ws.request('SessionChallenge', { sessionId: targetSessionId });
|
||||
@@ -1349,6 +1360,14 @@ export class AuthService {
|
||||
const connectionScope = String(loginResp?.payload?.connectionScope || '').trim().toUpperCase();
|
||||
|
||||
const canonicalLogin = await this.resolveCanonicalDisplayLogin(cleanLogin);
|
||||
void (async () => {
|
||||
try {
|
||||
const user = await this.getUser(canonicalLogin);
|
||||
const { publishPendingBlocks } = await import('./block-publication-service.js');
|
||||
await publishPendingBlocks({ ws: this.ws, login: canonicalLogin, storagePwd,
|
||||
blockchainName: String(user?.blockchainName || `${canonicalLogin}-${BCH_SUFFIX}`) });
|
||||
} catch (error) { console.warn('Block publication resume failed', error); }
|
||||
})();
|
||||
|
||||
return {
|
||||
login: canonicalLogin,
|
||||
@@ -1722,26 +1741,34 @@ export class AuthService {
|
||||
}
|
||||
|
||||
async runAddBlockWithRetry({ login, storagePwd, resolveFreshState, event }) {
|
||||
const freshState = await resolveFreshState();
|
||||
const blockchainName = String(freshState?.blockchainName || '').trim();
|
||||
if (!blockchainName) throw new Error('runAddBlockWithRetry: blockchainName is empty');
|
||||
const tryAdd = cursor => this.submitPreparedAddBlock({ login, storagePwd, blockchainName,
|
||||
blockNumber: Number(cursor?.serverLastGlobalNumber ?? -1) + 1,
|
||||
prevBlockHash: normalizeHex32(cursor?.serverLastGlobalHash, ZERO64), event });
|
||||
let response = await tryAdd(freshState.cursor);
|
||||
// Only a definitive global cursor conflict allows a new signature. An ambiguous
|
||||
// delivery is handled by submitSignedEvent using the original signed bytes.
|
||||
const code = String(response?.payload?.code || response?.code || '').toLowerCase();
|
||||
if (response.status !== 200 && ['bad_block_number', 'bad_prev_hash'].includes(code)) {
|
||||
const refreshed = await resolveFreshState();
|
||||
if (refreshed.blockchainName !== blockchainName) throw new Error('Blockchain changed during AddBlock');
|
||||
// HEADER must never be recreated at a nonzero number.
|
||||
if (!(event.msgType === MSG_TYPE_TECH && event.msgSubType === MSG_SUBTYPE_TECH_HEADER)) {
|
||||
response = await tryAdd(refreshed.cursor);
|
||||
try {
|
||||
const freshState = await resolveFreshState();
|
||||
const blockchainName = String(freshState?.blockchainName || '').trim();
|
||||
if (!blockchainName) throw new Error('runAddBlockWithRetry: blockchainName is empty');
|
||||
const tryAdd = cursor => this.submitPreparedAddBlock({ login, storagePwd, blockchainName,
|
||||
blockNumber: Number(cursor?.serverLastGlobalNumber ?? -1) + 1,
|
||||
prevBlockHash: normalizeHex32(cursor?.serverLastGlobalHash, ZERO64), event });
|
||||
let response = await tryAdd(freshState.cursor);
|
||||
// Only a definitive global cursor conflict allows a new signature. An ambiguous
|
||||
// delivery is handled by submitSignedEvent using the original signed bytes.
|
||||
const code = String(response?.payload?.code || response?.code || '').toLowerCase();
|
||||
if (response.status !== 200 && ['bad_block_number', 'bad_prev_hash'].includes(code)) {
|
||||
const refreshed = await resolveFreshState();
|
||||
if (refreshed.blockchainName !== blockchainName) throw new Error('Blockchain changed during AddBlock');
|
||||
// HEADER must never be recreated at a nonzero number.
|
||||
if (!(event.msgType === MSG_TYPE_TECH && event.msgSubType === MSG_SUBTYPE_TECH_HEADER)) {
|
||||
response = await tryAdd(refreshed.cursor);
|
||||
}
|
||||
}
|
||||
if (response.status !== 200) throw opError('AddBlock', response);
|
||||
void import('./block-publication-service.js').then(({ publishPendingBlocks }) =>
|
||||
publishPendingBlocks({ ws: this.ws, login, storagePwd, blockchainName }))
|
||||
.catch(error => console.warn('Block publication start failed', error));
|
||||
return { response, blockchainName };
|
||||
} catch (error) {
|
||||
showToast(t('block_publication.add_failed'), { kind: 'error' });
|
||||
throw error;
|
||||
}
|
||||
if (response.status !== 200) throw opError('AddBlock', response);
|
||||
return { response, blockchainName };
|
||||
}
|
||||
|
||||
async addBlockSigned({ login, storagePwd, msgType, msgSubType, msgVersion = 1, bodyBytes, channelSlug = '', _skipHeaderEnsure = false }) {
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
import { base64ToBytes } from './crypto-utils.js';
|
||||
import { unpackCoreContent } from './core-content.js';
|
||||
import { uploadSignedBlockDataItem } from './turbo-upload-service.js';
|
||||
import { showToast } from './channels-ux.js';
|
||||
import { t } from '../i18n/index.js';
|
||||
|
||||
const running = new Set();
|
||||
const scheduled = new Map();
|
||||
const lastNotice = new Map();
|
||||
|
||||
/** После перезапуска браузер повторно получает подписанные bytes с сервера. */
|
||||
export async function publishPendingBlocks({ ws, login, storagePwd, blockchainName }) {
|
||||
if (!ws || !login || !storagePwd || !blockchainName || running.has(blockchainName)) return;
|
||||
running.add(blockchainName);
|
||||
let keepPolling = false;
|
||||
try {
|
||||
const response = await ws.request('BlockPublication', { action: 'list', blockchainName });
|
||||
if (response.status !== 200) return;
|
||||
keepPolling = true;
|
||||
for (const block of response.payload?.pendingBlocks || []) {
|
||||
const read = await ws.request('GetBlockchainBlock', { blockchainName, blockNumber: block.blockNumber });
|
||||
if (read.status !== 200 || String(read.payload?.blockHash || '').toLowerCase() !== block.coreHash) {
|
||||
throw new Error('Pending block bytes unavailable or changed');
|
||||
}
|
||||
const { contentDataItem, coreDataItem } = unpackCoreContent(base64ToBytes(read.payload.blockBytesB64));
|
||||
let uploadError = '';
|
||||
try {
|
||||
if (!block.contentConfirmed) await uploadSignedBlockDataItem({ login, storagePwd, bytes: contentDataItem, expectedId: block.contentId });
|
||||
if (!block.coreConfirmed) await uploadSignedBlockDataItem({ login, storagePwd, bytes: coreDataItem, expectedId: block.coreId });
|
||||
} catch (error) {
|
||||
uploadError = String(error?.message || error);
|
||||
const insufficientCredits = /(?:\b402\b|insufficient (?:balance|funds|credits)|not enough (?:balance|funds|credits)|payment required|недостаточно (?:средств|кредитов))/i.test(uploadError);
|
||||
const noticeKey = `${blockchainName}:${block.blockNumber}`;
|
||||
if (Date.now() - (lastNotice.get(noticeKey) || 0) >= 30 * 60_000) {
|
||||
showToast(t(insufficientCredits ? 'block_publication.insufficient_credits' : 'block_publication.upload_failed',
|
||||
{ number: block.blockNumber }), { kind: 'error', timeoutMs: 7000 });
|
||||
lastNotice.set(noticeKey, Date.now());
|
||||
}
|
||||
}
|
||||
await ws.request('BlockPublication', {
|
||||
action: 'report', blockchainName, blockNumber: block.blockNumber,
|
||||
contentId: block.contentId, coreId: block.coreId,
|
||||
contentHash: block.contentHash, coreHash: block.coreHash, error: uploadError,
|
||||
});
|
||||
if (uploadError) break;
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Block publication queue unavailable', error);
|
||||
} finally {
|
||||
running.delete(blockchainName);
|
||||
if (keepPolling && !scheduled.has(blockchainName)) {
|
||||
const timer = globalThis.setTimeout(() => {
|
||||
scheduled.delete(blockchainName);
|
||||
void publishPendingBlocks({ ws, login, storagePwd, blockchainName });
|
||||
}, 30_000);
|
||||
scheduled.set(blockchainName, timer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2265,34 +2265,20 @@ async function applyCameraState(call) {
|
||||
videoTrack.enabled = true;
|
||||
}
|
||||
} else {
|
||||
const blackTrack = ensureBlackVideoTrack(call);
|
||||
if (hadSlotBefore) {
|
||||
if (call.localStream && blackTrack) {
|
||||
const existingVideoTracks = call.localStream.getVideoTracks?.() || [];
|
||||
existingVideoTracks.forEach((track) => {
|
||||
if (track.id !== blackTrack.id) {
|
||||
try { call.localStream.removeTrack(track); } catch {}
|
||||
}
|
||||
});
|
||||
if (!existingVideoTracks.some((track) => track.id === blackTrack.id)) {
|
||||
call.localStream.addTrack(blackTrack);
|
||||
}
|
||||
}
|
||||
try {
|
||||
if (videoTransceiver && videoTransceiver.direction !== 'sendrecv') {
|
||||
videoTransceiver.direction = 'sendrecv';
|
||||
}
|
||||
} catch {}
|
||||
if (videoTransceiver?.sender) {
|
||||
try { await videoTransceiver.sender.replaceTrack(blackTrack || null); } catch {}
|
||||
// A black placeholder is still an active video track for the peer and leaves
|
||||
// its call UI on a black screen. Removing the source makes the remote track
|
||||
// mute, which restores the regular avatar call stage until video returns.
|
||||
try { await videoTransceiver.sender.replaceTrack(null); } catch {}
|
||||
call.videoSender = videoTransceiver.sender;
|
||||
bindVideoSenderStream(call, videoTransceiver.sender);
|
||||
await applyVideoSenderEncodingProfile(videoTransceiver.sender, 'placeholder');
|
||||
}
|
||||
} else {
|
||||
if (call.localStream && blackTrack) {
|
||||
syncLocalStreamVideoTrack(call, blackTrack, { stopRemoved: false });
|
||||
}
|
||||
try {
|
||||
if (videoTransceiver && videoTransceiver.direction !== 'sendrecv') {
|
||||
videoTransceiver.direction = 'sendrecv';
|
||||
@@ -2301,8 +2287,6 @@ async function applyCameraState(call) {
|
||||
if (hadReservedBefore && videoTransceiver?.sender) {
|
||||
try { await videoTransceiver.sender.replaceTrack(null); } catch {}
|
||||
call.videoSender = videoTransceiver.sender;
|
||||
} else if (call.videoTransportMode === VIDEO_TRANSPORT_SLOT && blackTrack) {
|
||||
await ensureVideoSenderSlot(call, { sourceTrack: blackTrack, profile: 'placeholder' });
|
||||
}
|
||||
}
|
||||
await disableCameraTrack(call);
|
||||
|
||||
@@ -166,7 +166,10 @@ function getIconSvg(name) {
|
||||
return '<svg viewBox="0 0 24 24" aria-hidden="true"><rect x="9" y="3.5" width="6" height="11" rx="3" fill="none" stroke="currentColor" stroke-width="1.8"/><path d="M6 11.5a6 6 0 0 0 7.2 5.88" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M12 17.5v3" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M8.5 20.5h7" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round"/><path d="M5 5l14 14" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/></svg>';
|
||||
}
|
||||
if (name === 'hangup') {
|
||||
return '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M7 7l10 10M17 7 7 17" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round"/></svg>';
|
||||
return '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.1 8.5c3.8-3.1 10-3.1 13.8 0l-2 2.4a1.3 1.3 0 0 1-1.6.3l-1.6-.8a1.3 1.3 0 0 0-1.2 0l-1.6.8a1.3 1.3 0 0 1-1.6-.3z" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
}
|
||||
if (name === 'answer') {
|
||||
return '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M5.1 8.5c3.8-3.1 10-3.1 13.8 0l-2 2.4a1.3 1.3 0 0 1-1.6.3l-1.6-.8a1.3 1.3 0 0 0-1.2 0l-1.6.8a1.3 1.3 0 0 1-1.6-.3z" fill="none" stroke="currentColor" stroke-width="1.9" stroke-linecap="round" stroke-linejoin="round" transform="rotate(180 12 12)"/></svg>';
|
||||
}
|
||||
if (name === 'minimize') {
|
||||
return '<svg viewBox="0 0 24 24" aria-hidden="true"><path d="M12 6v12M7.5 10.5 12 6l4.5 4.5" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>';
|
||||
@@ -455,16 +458,16 @@ function ensureUi() {
|
||||
|
||||
acceptBtn = document.createElement('button');
|
||||
acceptBtn.type = 'button';
|
||||
acceptBtn.className = 'call-accept-btn';
|
||||
acceptBtn.textContent = t('remaining.call_ui.answer');
|
||||
acceptBtn.className = 'call-call-action-btn call-call-action-btn--accept';
|
||||
setButtonIcon(acceptBtn, 'answer', t('remaining.call_ui.answer'));
|
||||
acceptBtn.addEventListener('click', async () => {
|
||||
await acceptIncomingCall();
|
||||
});
|
||||
|
||||
declineBtn = document.createElement('button');
|
||||
declineBtn.type = 'button';
|
||||
declineBtn.className = 'destructive-btn call-decline-btn';
|
||||
declineBtn.textContent = t('remaining.call_ui.decline');
|
||||
declineBtn.className = 'call-call-action-btn call-call-action-btn--decline';
|
||||
setButtonIcon(declineBtn, 'hangup', t('remaining.call_ui.decline'));
|
||||
declineBtn.addEventListener('click', async () => {
|
||||
await declineIncomingCall();
|
||||
});
|
||||
|
||||
@@ -188,6 +188,39 @@ export async function uploadFileWithTurbo({
|
||||
};
|
||||
}
|
||||
|
||||
/** Загружает готовый подписанный DataItem, сохраняя исходные bytes и ID. */
|
||||
export async function uploadSignedBlockDataItem({ login, storagePwd, bytes, expectedId }) {
|
||||
if (!(bytes instanceof Uint8Array) || bytes.length === 0) throw new Error('Empty signed DataItem');
|
||||
const alreadyUploaded = async () => {
|
||||
try {
|
||||
const response = await fetch(`https://turbo.ardrive.io/tx/${encodeURIComponent(expectedId)}/status`);
|
||||
if (!response.ok) return false;
|
||||
const status = String((await response.json())?.status || '').toUpperCase();
|
||||
return ['PENDING', 'CONFIRMED', 'BUNDLED', 'FINALIZED'].includes(status);
|
||||
} catch { return false; }
|
||||
};
|
||||
if (await alreadyUploaded()) return { id: expectedId, alreadyUploaded: true };
|
||||
const { turbo } = await getTurboContextForStoredSolanaKey({ login, storagePwd });
|
||||
let result;
|
||||
try {
|
||||
result = await turbo.uploadSignedDataItem({
|
||||
dataItemStreamFactory: () => new ReadableStream({
|
||||
start(controller) { controller.enqueue(bytes); controller.close(); },
|
||||
}),
|
||||
dataItemSizeFactory: () => bytes.length,
|
||||
});
|
||||
} catch (error) {
|
||||
// Потерянный ответ Turbo или повтор того же DataItem не создаёт новый блок.
|
||||
if (await alreadyUploaded()) return { id: expectedId, alreadyUploaded: true };
|
||||
if (/data item exists|already exists/i.test(String(error?.message || error))) {
|
||||
return { id: expectedId, alreadyUploaded: true };
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
if (String(result?.id || '') !== expectedId) throw new Error('Turbo returned another DataItem ID');
|
||||
return result;
|
||||
}
|
||||
|
||||
export async function topUpTurboWithSolana({
|
||||
login,
|
||||
storagePwd,
|
||||
|
||||
Reference in New Issue
Block a user