mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-18 23:49:20 +01:00
Reuse recent CDN locators
This commit is contained in:
@@ -39,7 +39,11 @@ import {
|
||||
APPLICATION_OCTET_STREAM,
|
||||
stringToMIMEType,
|
||||
} from '../types/MIME.std.js';
|
||||
import { SECOND, DurationInSeconds } from '../util/durations/index.std.js';
|
||||
import {
|
||||
SECOND,
|
||||
DurationInSeconds,
|
||||
HOUR,
|
||||
} from '../util/durations/index.std.js';
|
||||
import type { AnyPaymentEvent } from '../types/Payment.std.js';
|
||||
import { PaymentEventKind } from '../types/Payment.std.js';
|
||||
import { filterAndClean } from '../util/BodyRange.node.js';
|
||||
@@ -47,9 +51,12 @@ import { bytesToUuid } from '../util/uuidToBytes.std.js';
|
||||
import { createName } from '../util/attachmentPath.node.js';
|
||||
import { partitionBodyAndNormalAttachments } from '../util/Attachment.std.js';
|
||||
import { isNotNil } from '../util/isNotNil.std.js';
|
||||
import { createLogger } from '../logging/log.std.js';
|
||||
|
||||
const { isNumber } = lodash;
|
||||
|
||||
const log = createLogger('processDataMessage');
|
||||
|
||||
const FLAGS = Proto.DataMessage.Flags;
|
||||
export const ATTACHMENT_MAX = 32;
|
||||
|
||||
@@ -85,7 +92,6 @@ export function processAttachment(
|
||||
height,
|
||||
caption,
|
||||
blurHash,
|
||||
uploadTimestamp,
|
||||
} = attachmentWithoutNulls;
|
||||
|
||||
const hasCdnId = Long.isLong(cdnId) ? !cdnId.isZero() : Boolean(cdnId);
|
||||
@@ -94,6 +100,15 @@ export function processAttachment(
|
||||
throw new Error('Missing size on incoming attachment!');
|
||||
}
|
||||
|
||||
let uploadTimestamp = attachmentWithoutNulls.uploadTimestamp?.toNumber();
|
||||
|
||||
// Make sure uploadTimestamp is not set to an obviously wrong future value (we use
|
||||
// uploadTimestamp to determine whether to re-use CDN pointers)
|
||||
if (uploadTimestamp && uploadTimestamp > Date.now() + 12 * HOUR) {
|
||||
log.warn('uploadTimestamp is in the future, dropping');
|
||||
uploadTimestamp = undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
cdnKey,
|
||||
cdnNumber,
|
||||
@@ -104,7 +119,7 @@ export function processAttachment(
|
||||
height,
|
||||
caption,
|
||||
blurHash,
|
||||
uploadTimestamp: uploadTimestamp?.toNumber(),
|
||||
uploadTimestamp,
|
||||
cdnId: hasCdnId ? String(cdnId) : undefined,
|
||||
clientUuid: Bytes.isNotEmpty(clientUuid)
|
||||
? bytesToUuid(clientUuid)
|
||||
|
||||
Reference in New Issue
Block a user