SHA256
Вложения: видео без пустых полос, карточка файла, размеры по-русски
- Горизонтальное видео в чате и в канале занимает свою высоту (раньше – рамка 20rem с пустыми полосами сверху и снизу, как будто вложение не догрузилось): ориентация теперь определяется и для видео, по метаданным, как уже было у фото. - Карточка файла в личке: значок документа вместо эмодзи-скрепки, круглая кнопка со стрелкой вместо голого слова «Скачать», которое на телефоне падало отдельной строкой под именем и не выглядело кнопкой. Во время загрузки в кнопке спиннер и проценты. Тосты после скачивания – «Файл сохранён» / «Файл скачан» вместо технических. - Размер файла по-русски: «93 КБ», «1,4 МБ» (было «93.4 KB», «1.40 MB») – во всех местах, где показывается размер вложения.
This commit is contained in:
+1
-1
@@ -1,2 +1,2 @@
|
|||||||
client.version=1.19.20
|
client.version=1.19.21
|
||||||
server.version=1.15.0
|
server.version=1.15.0
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@
|
|||||||
}());
|
}());
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
window.__SHINE_BUILD_HASH__ = '20261013110000';
|
window.__SHINE_BUILD_HASH__ = '20261013113000';
|
||||||
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
|
window.__SHINE_CLIENT_VERSION__ = '1.2.10';
|
||||||
</script>
|
</script>
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
// Вложения личных сообщений: превью картинок и видео после расшифровки и карточка файла со «Скачать».
|
// Вложения личных сообщений: превью картинок и видео после расшифровки и карточка файла со «Скачать».
|
||||||
// Общие для ленты чата и экрана «Медиа и файлы».
|
// Общие для ленты чата и экрана «Медиа и файлы».
|
||||||
import { decryptDmFileToBlob, downloadAndDecryptDmFile, formatDmFileSize } from '../services/dm-file-service.js';
|
import { decryptDmFileToBlob, downloadAndDecryptDmFile } from '../services/dm-file-service.js';
|
||||||
import { getAttachmentKind } from '../services/attachment-format.js';
|
import { formatBytes, getAttachmentKind } from '../services/attachment-format.js';
|
||||||
import { showToast } from '../services/channels-ux.js';
|
import { showToast } from '../services/channels-ux.js';
|
||||||
|
import { iconHtml } from './ui-icon.js';
|
||||||
|
import { createSpinner } from './feedback.js';
|
||||||
|
|
||||||
// Картинки и видео в личке показываются так же, как в каналах (карусель + просмотрщик),
|
// Картинки и видео в личке показываются так же, как в каналах (карусель + просмотрщик),
|
||||||
// только файл сначала расшифровывается. Большие файлы остаются карточками со «Скачать»,
|
// только файл сначала расшифровывается. Большие файлы остаются карточками со «Скачать»,
|
||||||
@@ -42,7 +44,8 @@ export function createDmFileAttachmentCard(attachment) {
|
|||||||
|
|
||||||
const fileIcon = document.createElement('span');
|
const fileIcon = document.createElement('span');
|
||||||
fileIcon.className = 'dm-file-card__icon';
|
fileIcon.className = 'dm-file-card__icon';
|
||||||
fileIcon.textContent = '📎';
|
fileIcon.setAttribute('aria-hidden', 'true');
|
||||||
|
fileIcon.innerHTML = iconHtml('doc');
|
||||||
|
|
||||||
const fileCopy = document.createElement('span');
|
const fileCopy = document.createElement('span');
|
||||||
fileCopy.className = 'dm-file-card__copy';
|
fileCopy.className = 'dm-file-card__copy';
|
||||||
@@ -51,21 +54,28 @@ export function createDmFileAttachmentCard(attachment) {
|
|||||||
fileName.textContent = attachment.name || 'file';
|
fileName.textContent = attachment.name || 'file';
|
||||||
const fileMeta = document.createElement('span');
|
const fileMeta = document.createElement('span');
|
||||||
fileMeta.className = 'dm-file-card__meta';
|
fileMeta.className = 'dm-file-card__meta';
|
||||||
const metaParts = [formatDmFileSize(attachment.size)];
|
const metaParts = [formatBytes(attachment.size)];
|
||||||
if (Number(attachment?.version || 1) >= 2) metaParts.push('BitTorrent v2');
|
if (Number(attachment?.version || 1) >= 2) metaParts.push('BitTorrent v2');
|
||||||
fileMeta.textContent = metaParts.join(' · ');
|
fileMeta.textContent = metaParts.join(' · ');
|
||||||
fileCopy.append(fileName, fileMeta);
|
fileCopy.append(fileName, fileMeta);
|
||||||
|
|
||||||
|
// Круглая кнопка со стрелкой; пока файл качается и расшифровывается – проценты в ней же.
|
||||||
const downloadBtn = document.createElement('button');
|
const downloadBtn = document.createElement('button');
|
||||||
downloadBtn.type = 'button';
|
downloadBtn.type = 'button';
|
||||||
downloadBtn.className = 'ui-button dm-file-card__download';
|
downloadBtn.className = 'dm-file-card__download';
|
||||||
downloadBtn.textContent = 'Скачать';
|
downloadBtn.title = 'Скачать';
|
||||||
|
downloadBtn.setAttribute('aria-label', `Скачать ${attachment.name || 'файл'}`);
|
||||||
|
const showDownloadIcon = () => {
|
||||||
|
downloadBtn.classList.remove('is-busy');
|
||||||
|
downloadBtn.innerHTML = iconHtml('download');
|
||||||
|
};
|
||||||
|
showDownloadIcon();
|
||||||
downloadBtn.addEventListener('click', async (event) => {
|
downloadBtn.addEventListener('click', async (event) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
if (downloadBtn.disabled) return;
|
if (downloadBtn.disabled) return;
|
||||||
downloadBtn.disabled = true;
|
downloadBtn.disabled = true;
|
||||||
const previousLabel = downloadBtn.textContent;
|
downloadBtn.classList.add('is-busy');
|
||||||
downloadBtn.textContent = 'Скачивание…';
|
downloadBtn.replaceChildren(createSpinner({ size: 'sm', label: 'Скачивание' }));
|
||||||
try {
|
try {
|
||||||
const result = await downloadAndDecryptDmFile(attachment, {
|
const result = await downloadAndDecryptDmFile(attachment, {
|
||||||
onProgress: ({ processedBytes, totalBytes }) => {
|
onProgress: ({ processedBytes, totalBytes }) => {
|
||||||
@@ -75,18 +85,14 @@ export function createDmFileAttachmentCard(attachment) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!result?.cancelled) {
|
if (!result?.cancelled) {
|
||||||
showToast(
|
// Сохранён сразу на диск (по частям) или отдан браузеру – для человека это одно и то же.
|
||||||
result?.streamed
|
showToast(result?.streamed ? 'Файл сохранён' : 'Файл скачан', { timeoutMs: 1600 });
|
||||||
? 'Файл расшифрован по частям и сохранён напрямую на диск'
|
|
||||||
: 'Файл расшифрован и передан браузеру для сохранения',
|
|
||||||
{ timeoutMs: 1800 },
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
showToast(error?.message || 'Не удалось скачать файл', { kind: 'error', timeoutMs: 2800 });
|
showToast(error?.message || 'Не удалось скачать файл', { kind: 'error', timeoutMs: 2800 });
|
||||||
} finally {
|
} finally {
|
||||||
downloadBtn.disabled = false;
|
downloadBtn.disabled = false;
|
||||||
downloadBtn.textContent = previousLabel;
|
showDownloadIcon();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -17,12 +17,16 @@ export function escapeHtml(text) {
|
|||||||
.replaceAll("'", ''');
|
.replaceAll("'", ''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Размер файла по-русски: «83 Б», «93 КБ», «1,4 МБ»; после 10 – без дробной части.
|
||||||
export function formatBytes(bytes) {
|
export function formatBytes(bytes) {
|
||||||
const value = Number(bytes || 0);
|
const value = Number(bytes || 0);
|
||||||
if (!Number.isFinite(value) || value <= 0) return '0 B';
|
if (!Number.isFinite(value) || value <= 0) return '0 Б';
|
||||||
if (value < 1024) return `${value} B`;
|
for (const [unit, size] of [['ГБ', 1024 ** 3], ['МБ', 1024 ** 2], ['КБ', 1024]]) {
|
||||||
if (value < 1024 * 1024) return `${(value / 1024).toFixed(1)} KB`;
|
if (value < size) continue;
|
||||||
return `${(value / (1024 * 1024)).toFixed(2)} MB`;
|
const amount = value / size;
|
||||||
|
return `${amount.toLocaleString('ru-RU', { maximumFractionDigits: amount >= 10 ? 0 : 1 })} ${unit}`;
|
||||||
|
}
|
||||||
|
return `${Math.round(value)} Б`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeName(name) {
|
function normalizeName(name) {
|
||||||
@@ -241,16 +245,18 @@ function createMediaSlide({ item, url, kind, messageTimestampMs, slide, onOpen }
|
|||||||
onOpen?.();
|
onOpen?.();
|
||||||
});
|
});
|
||||||
|
|
||||||
const bindImageLayout = (img) => {
|
// Горизонтальное фото или видео занимает свою высоту, а не рамку 20rem с пустыми полосами.
|
||||||
img.addEventListener('load', () => {
|
const applyMediaLayout = (media, width, height) => {
|
||||||
frame.classList.add('is-loaded');
|
const isLandscape = width > 0 && height > 0 && width > height;
|
||||||
const naturalWidth = Number(img.naturalWidth || 0);
|
media.classList.toggle('is-landscape', isLandscape);
|
||||||
const naturalHeight = Number(img.naturalHeight || 0);
|
|
||||||
const isLandscape = naturalWidth > 0 && naturalHeight > 0 && naturalWidth > naturalHeight;
|
|
||||||
img.classList.toggle('is-landscape', isLandscape);
|
|
||||||
frame.classList.toggle('is-landscape', isLandscape);
|
frame.classList.toggle('is-landscape', isLandscape);
|
||||||
slide.classList.toggle('has-landscape-media', isLandscape);
|
slide.classList.toggle('has-landscape-media', isLandscape);
|
||||||
slide.parentElement?.classList.toggle('has-landscape-media', isLandscape);
|
slide.parentElement?.classList.toggle('has-landscape-media', isLandscape);
|
||||||
|
};
|
||||||
|
const bindImageLayout = (img) => {
|
||||||
|
img.addEventListener('load', () => {
|
||||||
|
frame.classList.add('is-loaded');
|
||||||
|
applyMediaLayout(img, Number(img.naturalWidth || 0), Number(img.naturalHeight || 0));
|
||||||
}, { once: true });
|
}, { once: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -280,6 +286,7 @@ function createMediaSlide({ item, url, kind, messageTimestampMs, slide, onOpen }
|
|||||||
const videoSize = formatBytes(item.size);
|
const videoSize = formatBytes(item.size);
|
||||||
info.textContent = videoSize;
|
info.textContent = videoSize;
|
||||||
video.addEventListener('loadedmetadata', () => {
|
video.addEventListener('loadedmetadata', () => {
|
||||||
|
applyMediaLayout(video, Number(video.videoWidth || 0), Number(video.videoHeight || 0));
|
||||||
const duration = formatVideoDuration(video.duration);
|
const duration = formatVideoDuration(video.duration);
|
||||||
info.textContent = duration ? `${videoSize} · ${duration}` : videoSize;
|
info.textContent = duration ? `${videoSize} · ${duration}` : videoSize;
|
||||||
// Metadata сама по себе не гарантирует первого кадра. Переход к самому
|
// Metadata сама по себе не гарантирует первого кадра. Переход к самому
|
||||||
|
|||||||
@@ -930,68 +930,69 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.dm-file-card {
|
.dm-file-card {
|
||||||
min-width: min(285px, 72vw);
|
min-width: min(250px, 68vw);
|
||||||
max-width: min(330px, 76vw);
|
max-width: min(330px, 76vw);
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 36px minmax(0, 1fr) auto;
|
grid-template-columns: 40px minmax(0, 1fr) 36px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 9px;
|
gap: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dm-file-card__icon {
|
.dm-file-card__icon {
|
||||||
width: 36px;
|
width: 40px;
|
||||||
height: 36px;
|
height: 40px;
|
||||||
display: grid;
|
display: grid;
|
||||||
place-items: center;
|
place-items: center;
|
||||||
border-radius: 12px;
|
border-radius: 12px;
|
||||||
background: color-mix(in srgb, var(--text-primary) 8%, transparent);
|
color: var(--accent);
|
||||||
font-size: 19px;
|
background: color-mix(in srgb, var(--accent) 16%, transparent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dm-file-card__icon svg { width: 22px; height: 22px; }
|
||||||
|
|
||||||
.dm-file-card__copy {
|
.dm-file-card__copy {
|
||||||
min-width: 0;
|
min-width: 0;
|
||||||
display: grid;
|
display: grid;
|
||||||
gap: 3px;
|
gap: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dm-file-card__name {
|
.dm-file-card__name {
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
text-overflow: ellipsis;
|
text-overflow: ellipsis;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
font-size: 13px;
|
font-size: var(--text-sm);
|
||||||
font-weight: 680;
|
font-weight: 600;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dm-file-card__meta {
|
.dm-file-card__meta {
|
||||||
font-size: 11px;
|
font-size: var(--text-xs);
|
||||||
color: var(--text-secondary);
|
color: var(--text-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Круглая кнопка «Скачать»: стрелка, во время загрузки – спиннер и проценты. */
|
||||||
.dm-file-card__download {
|
.dm-file-card__download {
|
||||||
min-height: 34px;
|
width: 36px;
|
||||||
padding: 0 10px;
|
height: 36px;
|
||||||
border-radius: 11px;
|
display: grid;
|
||||||
font-size: 12px;
|
place-items: center;
|
||||||
font-weight: 650;
|
padding: 0;
|
||||||
white-space: nowrap;
|
border: 0;
|
||||||
|
border-radius: 50%;
|
||||||
|
color: var(--accent);
|
||||||
|
background: color-mix(in srgb, var(--accent) 14%, transparent);
|
||||||
|
font: inherit;
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 700;
|
||||||
|
font-variant-numeric: tabular-nums;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color var(--duration-fast) ease;
|
||||||
}
|
}
|
||||||
|
|
||||||
.dm-file-card__download:disabled {
|
.dm-file-card__download svg { width: 19px; height: 19px; }
|
||||||
opacity: 0.65;
|
.dm-file-card__download:active { background: color-mix(in srgb, var(--accent) 26%, transparent); }
|
||||||
cursor: progress;
|
@media (hover: hover) { .dm-file-card__download:hover { background: color-mix(in srgb, var(--accent) 22%, transparent); } }
|
||||||
}
|
.dm-file-card__download:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
|
||||||
|
.dm-file-card__download:disabled { cursor: progress; }
|
||||||
@media (max-width: 390px) {
|
|
||||||
.dm-screen .dm-file-card {
|
|
||||||
min-width: min(264px, 76vw);
|
|
||||||
grid-template-columns: 32px minmax(0, 1fr);
|
|
||||||
}
|
|
||||||
|
|
||||||
.dm-screen .dm-file-card__download {
|
|
||||||
grid-column: 2;
|
|
||||||
justify-self: start;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* ===== DM file transfer v2 + voice notes ===== */
|
/* ===== DM file transfer v2 + voice notes ===== */
|
||||||
@@ -1589,5 +1590,4 @@
|
|||||||
.chat-media-files { gap: 10px; }
|
.chat-media-files { gap: 10px; }
|
||||||
.chat-media-file { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border-subtle); border-radius: 16px; background: var(--surface); }
|
.chat-media-file { display: grid; gap: 6px; padding: 10px 12px; border: 1px solid var(--border-subtle); border-radius: 16px; background: var(--surface); }
|
||||||
.chat-media-file .dm-file-card { min-width: 0; max-width: none; }
|
.chat-media-file .dm-file-card { min-width: 0; max-width: none; }
|
||||||
.chat-media-file .dm-file-card__download { border: 1px solid var(--border-control); }
|
.chat-media-file__meta { padding-left: 50px; font-size: var(--text-xs); }
|
||||||
.chat-media-file__meta { padding-left: 45px; font-size: var(--text-xs); }
|
|
||||||
|
|||||||
Reference in New Issue
Block a user