Перевести вложения DM на R2 и обновить файловый API

This commit is contained in:
AidarKC
2026-11-15 14:33:52 +03:00
parent 3ecec25fce
commit 70540ff041
23 changed files with 770 additions and 202 deletions
+3 -2
View File
@@ -3,6 +3,7 @@ import { formatNumber } from '../i18n/format.js';
import { openMediaViewer } from '../components/media-viewer.js';
import { buildArweaveDataUrl, sha256HexFromArrayBuffer, validateArweaveTxId, validateSha256Hex } from './arweave-file-service.js';
import { resolvePublicFileUrl } from './public-file-service.js';
import { validatePublicPiecesRoot } from './public-pieces-root.js';
const ATTACH_BLOCK_RE = /^<(?:SHiNE|S):(attach|att);([^>]*)>\n?/u;
export const MAX_MESSAGE_ATTACHMENTS = 10;
@@ -47,8 +48,8 @@ export function normalizeAttachment(input = {}) {
const size = Number(input.sz || input.size || input.sizeBytes || 0);
const name = normalizeName(input.nm || input.name || input.fileName || 'file');
if (txId && !validateArweaveTxId(txId)) throw new Error(t('remaining.attachment_errors.invalid_arweave_transaction_id'));
if (!/^[A-Za-z0-9_-]{43}$/.test(pr) && !validateSha256Hex(sha256Hex)) throw new Error('Некорректный идентификатор файла');
if (pr && !/^[A-Za-z0-9_-]{43}$/.test(pr)) throw new Error('Некорректный Pieces Root');
if (!validatePublicPiecesRoot(pr) && !validateSha256Hex(sha256Hex)) throw new Error('Некорректный идентификатор файла');
if (pr && !validatePublicPiecesRoot(pr)) throw new Error('Некорректный Pieces Root');
if (mm && (!/^[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]+$/i.test(mm) || mm.length > 127)) throw new Error('Некорректный MIME');
if (!Number.isInteger(size) || size <= 0) throw new Error(t('remaining.attachment_errors.invalid_file_size'));
return { v: 1, name, size, sha256: sha256Hex, pr, mm, ar: txId, uploadedAtMs: Number(input.uploadedAtMs || 0) || Date.now() };