Добавить лицензию CC0 1.0

This commit is contained in:
AidarKC
2026-11-16 23:50:28 +03:00
parent 548160f7f8
commit c477560632
39 changed files with 901 additions and 138 deletions
+8 -3
View File
@@ -107,7 +107,7 @@ function normalizeFileAttachment(fields = {}) {
const mime = decodeFileField(fields.mime || '').trim() || 'application/octet-stream';
const size = Number(fields.size || 0);
const encryptedSize = Number(fields.encsize || 0);
if (!id || !url || !keyB64Url || !Number.isFinite(size) || size < 0) return null;
if (!id || (version < 3 && !url) || !keyB64Url || !Number.isFinite(size) || size < 0) return null;
if (version >= 2) {
const ivPrefixB64Url = String(fields.ivp || '').trim();
@@ -134,6 +134,7 @@ function normalizeFileAttachment(fields = {}) {
} : {}),
kind,
durationMs,
uploadedAtMs: Number(fields.at || 0) || 0,
};
}
@@ -161,7 +162,7 @@ export function buildDmFileTechBlock(attachment = {}) {
const keyB64Url = String(attachment?.keyB64Url || '').trim();
const size = Math.max(0, Math.floor(Number(attachment?.size || 0)));
const encryptedSize = Math.max(0, Math.floor(Number(attachment?.encryptedSize || 0)));
if (!id || !url || !keyB64Url) throw new Error('Не хватает данных для технического блока файла');
if (!id || (version < 3 && !url) || !keyB64Url) throw new Error('Не хватает данных для технического блока файла');
const name = encodeURIComponent(String(attachment?.name || 'file'));
const mime = encodeURIComponent(String(attachment?.mime || 'application/octet-stream'));
const encodedUrl = encodeURIComponent(url);
@@ -176,7 +177,11 @@ export function buildDmFileTechBlock(attachment = {}) {
const kind = String(attachment?.kind || 'file') === 'voice' ? 'voice' : 'file';
const durationMs = Math.max(0, Math.floor(Number(attachment?.durationMs || 0)));
const torrentFields = version === 2 ? `;th=${torrentHash};pr=${piecesRoot}` : '';
return `<S:file;v=${version};id=${id};url=${encodedUrl};key=${keyB64Url};ivp=${ivPrefix};name=${name};mime=${mime};size=${size};encsize=${encryptedSize};chunk=${chunkSize};chunks=${chunkCount}${torrentFields};kind=${kind};dur=${durationMs}>`;
// Новые DM v3: в E2EE передаём идентификаторы и ключи, а домен — через senderLogin.
// URL ранее созданных v3 и legacy v2/v1 продолжаем читать без изменения.
const urlField = version >= 3 ? '' : `;url=${encodedUrl}`;
const uploadTime = version >= 3 ? `;at=${Math.max(0, Math.floor(Number(attachment?.uploadedAtMs || 0)))}` : '';
return `<S:file;v=${version};id=${id}${urlField};key=${keyB64Url};ivp=${ivPrefix};name=${name};mime=${mime};size=${size};encsize=${encryptedSize};chunk=${chunkSize};chunks=${chunkCount}${torrentFields};kind=${kind};dur=${durationMs}${uploadTime}>`;
}
const ivB64Url = String(attachment?.ivB64Url || '').trim();