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;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { t } from '../i18n/index.js';
|
||||
// Вложения личных сообщений: превью картинок и видео после расшифровки и карточка файла со «Скачать».
|
||||
// Общие для ленты чата и экрана «Медиа и файлы».
|
||||
import { decryptDmFileToBlob, downloadAndDecryptDmFile } from '../services/dm-file-service.js';
|
||||
import { decryptDmFileToBlob, downloadAndDecryptDmFile, isDmFileExpired } from '../services/dm-file-service.js';
|
||||
import { formatBytes, getAttachmentKind } from '../services/attachment-format.js';
|
||||
import { showToast } from '../services/channels-ux.js';
|
||||
import { iconHtml } from './ui-icon.js';
|
||||
@@ -17,7 +17,7 @@ const dmMediaBlobs = new Map();
|
||||
const DM_MEDIA_CACHE_LIMIT = 40;
|
||||
|
||||
export function isDmInlineMedia(attachment) {
|
||||
if (attachment?.kind === 'voice') return false;
|
||||
if (attachment?.kind === 'voice' || isDmFileExpired(attachment)) return false;
|
||||
const size = Number(attachment?.size || 0);
|
||||
if (!(size > 0 && size <= DM_INLINE_MEDIA_MAX_BYTES)) return false;
|
||||
const kind = getAttachmentKind(attachment);
|
||||
@@ -27,6 +27,7 @@ export function isDmInlineMedia(attachment) {
|
||||
// Расшифрованный файл держим в памяти: лента перерисовывается на каждое новое сообщение,
|
||||
// и без кэша картинка расшифровывалась бы и мигала заново.
|
||||
export function resolveDmMediaUrl(attachment) {
|
||||
if (isDmFileExpired(attachment)) return Promise.reject(new Error('DM_FILE_EXPIRED'));
|
||||
const key = String(attachment?.id || attachment?.url || '');
|
||||
let pending = dmMediaBlobs.get(key);
|
||||
if (!pending) {
|
||||
@@ -40,7 +41,24 @@ export function resolveDmMediaUrl(attachment) {
|
||||
return pending.then((blob) => ({ url: URL.createObjectURL(blob), objectUrl: true }));
|
||||
}
|
||||
|
||||
export function createDmExpiredAttachmentCard(attachment) {
|
||||
const card = document.createElement('div');
|
||||
card.className = 'dm-file-card';
|
||||
const copy = document.createElement('span');
|
||||
copy.className = 'dm-file-card__copy';
|
||||
const name = document.createElement('strong');
|
||||
name.className = 'dm-file-card__name';
|
||||
name.textContent = attachment?.name || 'file';
|
||||
const info = document.createElement('span');
|
||||
info.className = 'dm-file-card__meta';
|
||||
info.textContent = t('screens.dm_attachments.file_expired');
|
||||
copy.append(name, info);
|
||||
card.append(copy);
|
||||
return card;
|
||||
}
|
||||
|
||||
export function createDmFileAttachmentCard(attachment) {
|
||||
if (isDmFileExpired(attachment)) return createDmExpiredAttachmentCard(attachment);
|
||||
const fileCard = document.createElement('div');
|
||||
fileCard.className = 'dm-file-card';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user