SHA256
Добавить лицензию CC0 1.0
This commit is contained in:
@@ -2,7 +2,8 @@ import { t } from '../i18n/index.js';
|
||||
import { state } from '../state.js';
|
||||
import { buildArweaveDataUrl, validateArweaveTxId } from '../services/arweave-file-service.js';
|
||||
import { getCachedAvatarObjectUrl } from '../services/arweave-avatar-cache-service.js';
|
||||
import { avatarR2Url } from '../services/public-file-service.js';
|
||||
import { resolvePublicFileUrl } from '../services/public-file-service.js';
|
||||
import { updatedUserFileUrlAfterError } from '../services/user-file-server-service.js';
|
||||
import { validatePublicPiecesRoot } from '../services/public-pieces-root.js';
|
||||
|
||||
function normalizeLogin(value) {
|
||||
@@ -78,6 +79,7 @@ export function renderAvatar({
|
||||
img.alt = String(alt || t('screens.avatar_image.text_002'));
|
||||
img.loading = 'lazy';
|
||||
img.decoding = 'async';
|
||||
img.referrerPolicy = 'no-referrer';
|
||||
wrap.append(img);
|
||||
|
||||
const setLoadedState = (loaded) => {
|
||||
@@ -88,8 +90,23 @@ export function renderAvatar({
|
||||
if (hasServerAvatar) {
|
||||
// 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);
|
||||
let attemptedRefresh = false;
|
||||
img.onerror = async () => {
|
||||
const previousUrl = img.src;
|
||||
if (!attemptedRefresh && authorLogin) {
|
||||
attemptedRefresh = true;
|
||||
try {
|
||||
const updated = await updatedUserFileUrlAfterError({
|
||||
login: authorLogin, id: expectedPr, previousUrl,
|
||||
});
|
||||
if (updated && img.parentElement === wrap) { img.src = updated; return; }
|
||||
} catch { /* старый адрес останется недоступным */ }
|
||||
}
|
||||
img.removeAttribute('src'); setLoadedState(false);
|
||||
};
|
||||
void resolvePublicFileUrl({ pr: expectedPr, authorLogin }).then((url) => {
|
||||
if (img.parentElement === wrap) img.src = url;
|
||||
}).catch(() => { img.removeAttribute('src'); setLoadedState(false); });
|
||||
return wrap;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user