MCPcopy
hub / github.com/signalapp/Signal-Desktop / processAttachment

Function processAttachment

ts/textsecure/processDataMessage.preload.ts:75–142  ·  view source on GitHub ↗
(
  attachment?: Proto.AttachmentPointer | null
)

Source from the content-addressed store, hash-verified

73): ProcessedAttachment | undefined;
74
75export function processAttachment(
76 attachment?: Proto.AttachmentPointer | null
77): ProcessedAttachment | undefined {
78 if (attachment == null) {
79 return undefined;
80 }
81
82 const {
83 cdnNumber,
84 attachmentIdentifier,
85 clientUuid,
86 key,
87 size,
88 contentType,
89 digest,
90 incrementalMac,
91 chunkSize,
92 fileName,
93 flags,
94 width,
95 height,
96 caption,
97 blurHash,
98 } = attachment;
99
100 if (!isNumber(size)) {
101 throw new Error('Missing size on incoming attachment!');
102 }
103
104 let uploadTimestamp: number | undefined =
105 toNumber(attachment.uploadTimestamp) ?? 0;
106
107 // Make sure uploadTimestamp is not set to an obviously wrong future value (we use
108 // uploadTimestamp to determine whether to re-use CDN pointers)
109 if (uploadTimestamp && uploadTimestamp > Date.now() + 12 * HOUR) {
110 log.warn('uploadTimestamp is in the future, dropping');
111 uploadTimestamp = undefined;
112 }
113
114 return {
115 cdnKey: attachmentIdentifier?.cdnKey,
116 cdnNumber: cdnNumber ?? 0,
117 chunkSize: chunkSize ?? 0,
118 fileName: fileName ?? '',
119 flags: flags ?? 0,
120 width: width ?? 0,
121 height: height ?? 0,
122 caption: caption ?? '',
123 blurHash: blurHash ?? '',
124 uploadTimestamp,
125 cdnId:
126 attachmentIdentifier?.cdnId === 0n
127 ? undefined
128 : attachmentIdentifier?.cdnId?.toString(),
129 clientUuid: Bytes.isNotEmpty(clientUuid)
130 ? bytesToUuid(clientUuid)
131 : undefined,
132 contentType: contentType

Callers 8

#handleStoryMessageMethod · 0.90
#handleContactsMethod · 0.90
processQuoteFunction · 0.70
processContactFunction · 0.70
processPreviewFunction · 0.70
processStickerFunction · 0.70
processDataMessageFunction · 0.70

Calls 7

toNumberFunction · 0.90
bytesToUuidFunction · 0.90
stringToMIMETypeFunction · 0.90
isNotEmptyMethod · 0.80
toBase64Method · 0.80
warnMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected