Add support for receiving attachments from CDN 2
This commit is contained in:
parent
4dc7631851
commit
a0e9791623
16 changed files with 156 additions and 64 deletions
6
ts/textsecure.d.ts
vendored
6
ts/textsecure.d.ts
vendored
|
@ -153,7 +153,8 @@ export declare class AttachmentPointerClass {
|
|||
encoding?: string
|
||||
) => AttachmentPointerClass;
|
||||
|
||||
id?: ProtoBigNumberType;
|
||||
cdnId?: ProtoBigNumberType;
|
||||
cdnKey?: string;
|
||||
contentType?: string;
|
||||
key?: ProtoBinaryType;
|
||||
size?: number;
|
||||
|
@ -164,6 +165,9 @@ export declare class AttachmentPointerClass {
|
|||
width?: number;
|
||||
height?: number;
|
||||
caption?: string;
|
||||
blurHash?: string;
|
||||
uploadTimestamp?: ProtoBigNumberType;
|
||||
cdnNumber?: number;
|
||||
}
|
||||
|
||||
export declare class ContactDetailsClass {
|
||||
|
|
|
@ -21,6 +21,7 @@ import {
|
|||
AttachmentPointerClass,
|
||||
DataMessageClass,
|
||||
EnvelopeClass,
|
||||
ProtoBigNumberType,
|
||||
ReceiptMessageClass,
|
||||
SyncMessageClass,
|
||||
TypingMessageClass,
|
||||
|
@ -62,7 +63,8 @@ declare global {
|
|||
}
|
||||
|
||||
type AttachmentType = {
|
||||
id?: string;
|
||||
cdnId?: string;
|
||||
cdnKey?: string;
|
||||
data: ArrayBuffer;
|
||||
contentType?: string;
|
||||
size?: number;
|
||||
|
@ -71,6 +73,9 @@ type AttachmentType = {
|
|||
width?: number;
|
||||
height?: number;
|
||||
caption?: string;
|
||||
blurHash?: string;
|
||||
uploadTimestamp?: ProtoBigNumberType;
|
||||
cdnNumber?: number;
|
||||
};
|
||||
|
||||
type CacheAddItemType = {
|
||||
|
@ -1571,13 +1576,16 @@ class MessageReceiverInner extends EventTarget {
|
|||
cleanAttachment(attachment: AttachmentPointerClass) {
|
||||
return {
|
||||
...omit(attachment, 'thumbnail'),
|
||||
id: attachment.id.toString(),
|
||||
cdnId: attachment.cdnId?.toString(),
|
||||
key: attachment.key ? attachment.key.toString('base64') : null,
|
||||
digest: attachment.digest ? attachment.digest.toString('base64') : null,
|
||||
};
|
||||
}
|
||||
async downloadAttachment(attachment: AttachmentPointerClass) {
|
||||
const encrypted = await this.server.getAttachment(attachment.id);
|
||||
const encrypted = await this.server.getAttachment(
|
||||
attachment.cdnId || attachment.cdnKey,
|
||||
attachment.cdnNumber || 0
|
||||
);
|
||||
const { key, digest, size } = attachment;
|
||||
|
||||
if (!digest) {
|
||||
|
|
|
@ -334,7 +334,7 @@ export default class MessageSender {
|
|||
const id = await this.server.putAttachment(result.ciphertext);
|
||||
|
||||
const proto = new window.textsecure.protobuf.AttachmentPointer();
|
||||
proto.id = id;
|
||||
proto.cdnId = id;
|
||||
proto.contentType = attachment.contentType;
|
||||
proto.key = key;
|
||||
proto.size = attachment.size;
|
||||
|
|
|
@ -491,7 +491,10 @@ const URL_CALLS = {
|
|||
|
||||
type InitializeOptionsType = {
|
||||
url: string;
|
||||
cdnUrl: string;
|
||||
cdnUrlObject: {
|
||||
readonly '0': string;
|
||||
readonly [propName: string]: string;
|
||||
};
|
||||
certificateAuthority: string;
|
||||
contentProxyUrl: string;
|
||||
proxyUrl: string;
|
||||
|
@ -532,7 +535,7 @@ export type WebAPIType = {
|
|||
deviceName?: string | null,
|
||||
options?: { accessKey?: ArrayBuffer }
|
||||
) => Promise<any>;
|
||||
getAttachment: (id: string) => Promise<any>;
|
||||
getAttachment: (cdnKey: string, cdnNumber: number) => Promise<any>;
|
||||
getAvatar: (path: string) => Promise<any>;
|
||||
getDevices: () => Promise<any>;
|
||||
getKeysForIdentifier: (
|
||||
|
@ -643,7 +646,7 @@ export type ProxiedRequestOptionsType = {
|
|||
// tslint:disable-next-line max-func-body-length
|
||||
export function initialize({
|
||||
url,
|
||||
cdnUrl,
|
||||
cdnUrlObject,
|
||||
certificateAuthority,
|
||||
contentProxyUrl,
|
||||
proxyUrl,
|
||||
|
@ -652,8 +655,14 @@ export function initialize({
|
|||
if (!is.string(url)) {
|
||||
throw new Error('WebAPI.initialize: Invalid server url');
|
||||
}
|
||||
if (!is.string(cdnUrl)) {
|
||||
throw new Error('WebAPI.initialize: Invalid cdnUrl');
|
||||
if (!is.object(cdnUrlObject)) {
|
||||
throw new Error('WebAPI.initialize: Invalid cdnUrlObject');
|
||||
}
|
||||
if (!is.string(cdnUrlObject['0'])) {
|
||||
throw new Error('WebAPI.initialize: Missing CDN 0 configuration');
|
||||
}
|
||||
if (!is.string(cdnUrlObject['2'])) {
|
||||
throw new Error('WebAPI.initialize: Missing CDN 2 configuration');
|
||||
}
|
||||
if (!is.string(certificateAuthority)) {
|
||||
throw new Error('WebAPI.initialize: Invalid certificateAuthority');
|
||||
|
@ -871,7 +880,7 @@ export function initialize({
|
|||
async function getAvatar(path: string) {
|
||||
// Using _outerAJAX, since it's not hardcoded to the Signal Server. Unlike our
|
||||
// attachment CDN, it uses our self-signed certificate, so we pass it in.
|
||||
return _outerAjax(`${cdnUrl}/${path}`, {
|
||||
return _outerAjax(`${cdnUrlObject['0']}/${path}`, {
|
||||
certificateAuthority,
|
||||
contentType: 'application/octet-stream',
|
||||
proxyUrl,
|
||||
|
@ -1198,25 +1207,31 @@ export function initialize({
|
|||
}
|
||||
|
||||
async function getSticker(packId: string, stickerId: string) {
|
||||
return _outerAjax(`${cdnUrl}/stickers/${packId}/full/${stickerId}`, {
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
responseType: 'arraybuffer',
|
||||
type: 'GET',
|
||||
redactUrl: redactStickerUrl,
|
||||
version,
|
||||
});
|
||||
return _outerAjax(
|
||||
`${cdnUrlObject['0']}/stickers/${packId}/full/${stickerId}`,
|
||||
{
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
responseType: 'arraybuffer',
|
||||
type: 'GET',
|
||||
redactUrl: redactStickerUrl,
|
||||
version,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function getStickerPackManifest(packId: string) {
|
||||
return _outerAjax(`${cdnUrl}/stickers/${packId}/manifest.proto`, {
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
responseType: 'arraybuffer',
|
||||
type: 'GET',
|
||||
redactUrl: redactStickerUrl,
|
||||
version,
|
||||
});
|
||||
return _outerAjax(
|
||||
`${cdnUrlObject['0']}/stickers/${packId}/manifest.proto`,
|
||||
{
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
responseType: 'arraybuffer',
|
||||
type: 'GET',
|
||||
redactUrl: redactStickerUrl,
|
||||
version,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
type ServerAttachmentType = {
|
||||
|
@ -1304,7 +1319,7 @@ export function initialize({
|
|||
// Upload manifest
|
||||
const manifestParams = makePutParams(manifest, encryptedManifest);
|
||||
// This is going to the CDN, not the service, so we use _outerAjax
|
||||
await _outerAjax(`${cdnUrl}/`, {
|
||||
await _outerAjax(`${cdnUrlObject['0']}/`, {
|
||||
...manifestParams,
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
|
@ -1322,7 +1337,7 @@ export function initialize({
|
|||
encryptedStickers[index]
|
||||
);
|
||||
await queue.add(async () =>
|
||||
_outerAjax(`${cdnUrl}/`, {
|
||||
_outerAjax(`${cdnUrlObject['0']}/`, {
|
||||
...stickerParams,
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
|
@ -1341,9 +1356,10 @@ export function initialize({
|
|||
return packId;
|
||||
}
|
||||
|
||||
async function getAttachment(id: string) {
|
||||
async function getAttachment(cdnKey: string, cdnNumber: number) {
|
||||
const cdnUrl = cdnUrlObject[cdnNumber] || cdnUrlObject['0'];
|
||||
// This is going to the CDN, not the service, so we use _outerAjax
|
||||
return _outerAjax(`${cdnUrl}/attachments/${id}`, {
|
||||
return _outerAjax(`${cdnUrl}/attachments/${cdnKey}`, {
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
responseType: 'arraybuffer',
|
||||
|
@ -1365,7 +1381,7 @@ export function initialize({
|
|||
const params = makePutParams(response, encryptedBin);
|
||||
|
||||
// This is going to the CDN, not the service, so we use _outerAjax
|
||||
await _outerAjax(`${cdnUrl}/attachments/`, {
|
||||
await _outerAjax(`${cdnUrlObject['0']}/attachments/`, {
|
||||
...params,
|
||||
certificateAuthority,
|
||||
proxyUrl,
|
||||
|
|
|
@ -11817,4 +11817,4 @@
|
|||
"reasonCategory": "falseMatch",
|
||||
"updated": "2020-04-05T23:45:16.746Z"
|
||||
}
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue