SHA256
Перевести вложения DM на R2 и обновить файловый API
This commit is contained in:
@@ -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() };
|
||||
|
||||
Reference in New Issue
Block a user