SHA256
Исправить восстановление сессии после переподключения
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { buildAvatarReference } from './avatar-reference.js';
|
||||
import { WsJsonClient } from './ws-client.js';
|
||||
import { invalidateConnectionsGraphCache } from './connections-graph-cache.js';
|
||||
import {
|
||||
@@ -727,14 +728,8 @@ function composeChannelMetaText({ title = '', description = '', avatar = null }
|
||||
const cleanDescription = normalizeChannelMetaDescription(description);
|
||||
const rows = [];
|
||||
if (cleanTitle) rows.push(`<S:title;v=1;${cleanTitle}>`);
|
||||
if (avatar?.sha256 || avatar?.sha256Hex) {
|
||||
const size = Number(avatar.size || 0);
|
||||
const sha256 = String(avatar.sha256 || avatar.sha256Hex || '').trim().toLowerCase();
|
||||
const ar = String(avatar.ar || '').trim();
|
||||
if (!Number.isInteger(size) || size <= 0) throw new Error('Некорректный размер аватара.');
|
||||
if (!/^[0-9a-f]{64}$/u.test(sha256)) throw new Error('Некорректный SHA-256 аватара.');
|
||||
if (ar && !/^[A-Za-z0-9_-]{43}$/u.test(ar)) throw new Error('Некорректный Arweave txId аватара.');
|
||||
rows.push(`<S:ava;v=1;sz=${size};sha256=${sha256}${ar ? `;ar=${ar}` : ''}>`);
|
||||
if (avatar?.pr) {
|
||||
rows.push(buildAvatarReference({ size: avatar.size, pr: avatar.pr, ar: avatar.ar }));
|
||||
}
|
||||
if (cleanDescription) rows.push(cleanDescription);
|
||||
return rows.join('\n');
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { readFileSync } from 'node:fs';
|
||||
import { fileURLToPath } from 'node:url';
|
||||
import { dirname, resolve } from 'node:path';
|
||||
import { avatarR2Url } from '../js/services/public-file-service.js';
|
||||
import { buildAvatarReference, parseAvatarReference } from '../js/services/avatar-reference.js';
|
||||
import { encodePublicPiecesRoot } from '../js/services/public-pieces-root.js';
|
||||
import { preparePublicFile } from '../js/services/file-preparation-service.js';
|
||||
|
||||
const ui = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
||||
const source = (path) => readFileSync(resolve(ui, path), 'utf8');
|
||||
const pr = encodePublicPiecesRoot(new Uint8Array(32).fill(255));
|
||||
|
||||
test('avatar v2: PR Base58 exactly as public attachment; Arweave TX ID unchanged', () => {
|
||||
assert.equal(avatarR2Url(pr), `https://files.shineup.me/${pr}`);
|
||||
const value = buildAvatarReference({ pr, size: 1000 });
|
||||
assert.equal(value, `<S:ava;v=2;sz=1000;pr=${pr}>`);
|
||||
assert.equal(parseAvatarReference(value).pr, pr);
|
||||
assert.equal(parseAvatarReference(value).source, 'r2');
|
||||
const ar = 'A'.repeat(43);
|
||||
const withAr = buildAvatarReference({ pr, size: 1000, ar });
|
||||
assert.equal(parseAvatarReference(withAr).ar, ar);
|
||||
assert.equal(parseAvatarReference(withAr).source, 'arweave');
|
||||
for (const legacy of [`<S:ava;v=1;sz=1000;sha256=${'a'.repeat(64)}>`, 'AR:' + ar]) {
|
||||
assert.equal(parseAvatarReference(legacy).ok, false);
|
||||
}
|
||||
assert.throws(() => buildAvatarReference({ pr: pr.toLowerCase(), size: 1000 }));
|
||||
assert.throws(() => avatarR2Url('not-a-root'));
|
||||
});
|
||||
|
||||
test('Avatar PR computed on the same exact bytes as public attachments', async () => {
|
||||
const file = new File([Uint8Array.of(1, 2, 3, 4, 5)], 'avatar.webp', { type: 'image/webp' });
|
||||
const prepared = await preparePublicFile(file);
|
||||
assert.equal(prepared.pr, (await preparePublicFile(file)).pr);
|
||||
assert.equal(avatarR2Url(prepared.pr), `https://files.shineup.me/${prepared.pr}`);
|
||||
});
|
||||
|
||||
test('avatar R2 upload reuses signed public PR prepare; no avatar-specific endpoint/path', () => {
|
||||
const service = source('js/services/public-file-service.js');
|
||||
assert.match(service, /return uploadR2PublicFile\(\{ file, login, sessionId, wsUrl, onStatus \}\)/);
|
||||
assert.match(service, /\/api\/files\/prepare/);
|
||||
assert.doesNotMatch(service, /\/api\/avatars\/prepare/);
|
||||
assert.doesNotMatch(service, /avatars\/\$\{/);
|
||||
assert.match(source('js/components/avatar-image.js'), /img\.src = avatarR2Url\(expectedPr\)/);
|
||||
assert.match(source('js/pages/network/graph-canvas.js'), /avatarR2Url\(pr\)/);
|
||||
assert.match(source('js/pages/network-legacy/force-graph.js'), /avatarR2Url\(pr\)/);
|
||||
});
|
||||
Reference in New Issue
Block a user