SHA256
Обновить обработку аватаров и вложений
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { state } from '../state.js';
|
||||
import { buildArweaveDataUrl, validateArweaveTxId, validateSha256Hex } from '../services/arweave-file-service.js';
|
||||
import { getCachedAvatarObjectUrl } from '../services/arweave-avatar-cache-service.js';
|
||||
import { resolvePublicFileUrl } from '../services/public-file-service.js';
|
||||
|
||||
function normalizeLogin(value) {
|
||||
return String(value || '').trim();
|
||||
@@ -37,6 +38,7 @@ export function renderAvatar({
|
||||
alt = 'Аватар',
|
||||
glow = false,
|
||||
official = false,
|
||||
authorLogin = '',
|
||||
} = {}) {
|
||||
const wrap = document.createElement('div');
|
||||
const classes = new Set(['avatar', 'avatar-image', 'avatar-framed']);
|
||||
@@ -63,11 +65,11 @@ export function renderAvatar({
|
||||
}
|
||||
|
||||
const txId = String(avatar?.ar || '').trim();
|
||||
if (!validateArweaveTxId(txId)) {
|
||||
return wrap;
|
||||
}
|
||||
const sha256Hex = String(avatar?.sha256Hex || avatar?.sha256 || '').trim().toLowerCase();
|
||||
const expectedSha256Hex = validateSha256Hex(sha256Hex) ? sha256Hex : '';
|
||||
const hasArweave = validateArweaveTxId(txId);
|
||||
const hasServerAvatar = !txId && expectedSha256Hex && normalizeLogin(authorLogin);
|
||||
if (!hasArweave && !hasServerAvatar) return wrap;
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.className = 'avatar-photo';
|
||||
@@ -81,6 +83,23 @@ export function renderAvatar({
|
||||
};
|
||||
setLoadedState(false);
|
||||
|
||||
if (hasServerAvatar) {
|
||||
void resolvePublicFileUrl({
|
||||
sha256: expectedSha256Hex,
|
||||
authorLogin: normalizeLogin(authorLogin),
|
||||
solanaEndpoint: state?.entrySettings?.solanaServer,
|
||||
fallbackServerLogin: state?.entrySettings?.shineServerLogin,
|
||||
}).then((url) => {
|
||||
img.onload = () => setLoadedState(true);
|
||||
img.onerror = () => { img.removeAttribute('src'); setLoadedState(false); };
|
||||
img.src = url;
|
||||
}).catch(() => {
|
||||
img.removeAttribute('src');
|
||||
setLoadedState(false);
|
||||
});
|
||||
return wrap;
|
||||
}
|
||||
|
||||
const gateway = state?.entrySettings?.arweaveServer;
|
||||
void getCachedAvatarObjectUrl({ gateway, txId, expectedSha256Hex })
|
||||
.then((objectUrl) => {
|
||||
@@ -157,6 +176,7 @@ export function renderUserAvatar({
|
||||
title = '',
|
||||
glow = false,
|
||||
official = false,
|
||||
authorLogin = '',
|
||||
} = {}) {
|
||||
return renderAvatar({
|
||||
initials: buildAvatarInitials({ login, firstName, lastName }),
|
||||
@@ -167,5 +187,6 @@ export function renderUserAvatar({
|
||||
alt: 'Аватар',
|
||||
glow,
|
||||
official,
|
||||
authorLogin: login,
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user