SHA256
Обновить публичные идентификаторы файлов
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
import { state } from '../state.js';
|
||||
import { buildArweaveDataUrl, validateArweaveTxId, validateSha256Hex } from '../services/arweave-file-service.js';
|
||||
import { buildArweaveDataUrl, validateArweaveTxId } from '../services/arweave-file-service.js';
|
||||
import { getCachedAvatarObjectUrl } from '../services/arweave-avatar-cache-service.js';
|
||||
import { resolvePublicFileUrl } from '../services/public-file-service.js';
|
||||
import { avatarR2Url } from '../services/public-file-service.js';
|
||||
import { validatePublicPiecesRoot } from '../services/public-pieces-root.js';
|
||||
|
||||
function normalizeLogin(value) {
|
||||
return String(value || '').trim();
|
||||
@@ -66,10 +67,10 @@ export function renderAvatar({
|
||||
}
|
||||
|
||||
const txId = String(avatar?.ar || '').trim();
|
||||
const sha256Hex = String(avatar?.sha256Hex || avatar?.sha256 || '').trim().toLowerCase();
|
||||
const expectedSha256Hex = validateSha256Hex(sha256Hex) ? sha256Hex : '';
|
||||
const pr = String(avatar?.pr || '').trim();
|
||||
const expectedPr = validatePublicPiecesRoot(pr) ? pr : '';
|
||||
const hasArweave = validateArweaveTxId(txId);
|
||||
const hasServerAvatar = !txId && expectedSha256Hex && normalizeLogin(authorLogin);
|
||||
const hasServerAvatar = !txId && expectedPr;
|
||||
if (!hasArweave && !hasServerAvatar) return wrap;
|
||||
|
||||
const img = document.createElement('img');
|
||||
@@ -85,24 +86,15 @@ 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);
|
||||
});
|
||||
// All public avatars use exactly the same PR/Base58 R2 object key as attachments.
|
||||
img.onload = () => setLoadedState(true);
|
||||
img.onerror = () => { img.removeAttribute('src'); setLoadedState(false); };
|
||||
img.src = avatarR2Url(expectedPr);
|
||||
return wrap;
|
||||
}
|
||||
|
||||
const gateway = state?.entrySettings?.arweaveServer;
|
||||
void getCachedAvatarObjectUrl({ gateway, txId, expectedSha256Hex })
|
||||
void getCachedAvatarObjectUrl({ gateway, txId, expectedPr })
|
||||
.then((objectUrl) => {
|
||||
const directUrl = buildArweaveDataUrl({ gateway, txId });
|
||||
let triedDirectUrl = false;
|
||||
@@ -120,7 +112,7 @@ export function renderAvatar({
|
||||
};
|
||||
img.onerror = () => {
|
||||
if (!triedDirectUrl) {
|
||||
if (expectedSha256Hex) {
|
||||
if (expectedPr) {
|
||||
releaseObjectUrl();
|
||||
img.removeAttribute('src');
|
||||
setLoadedState(false);
|
||||
@@ -138,7 +130,7 @@ export function renderAvatar({
|
||||
img.src = objectUrl;
|
||||
})
|
||||
.catch(() => {
|
||||
if (expectedSha256Hex) {
|
||||
if (expectedPr) {
|
||||
img.removeAttribute('src');
|
||||
setLoadedState(false);
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user