Use v4/attachments endpoint for attachment upload forms
This commit is contained in:
parent
826b361757
commit
451ee56c92
3 changed files with 21 additions and 19 deletions
|
@ -4,7 +4,7 @@
|
||||||
import { strictAssert } from '../../util/assert';
|
import { strictAssert } from '../../util/assert';
|
||||||
import type {
|
import type {
|
||||||
WebAPIType,
|
WebAPIType,
|
||||||
AttachmentV3ResponseType,
|
AttachmentUploadFormResponseType,
|
||||||
GetBackupInfoResponseType,
|
GetBackupInfoResponseType,
|
||||||
BackupMediaItemType,
|
BackupMediaItemType,
|
||||||
BackupMediaBatchResponseType,
|
BackupMediaBatchResponseType,
|
||||||
|
@ -66,7 +66,7 @@ export class BackupAPI {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getMediaUploadForm(): Promise<AttachmentV3ResponseType> {
|
public async getMediaUploadForm(): Promise<AttachmentUploadFormResponseType> {
|
||||||
return this.server.getBackupMediaUploadForm(
|
return this.server.getBackupMediaUploadForm(
|
||||||
await this.credentials.getHeadersForToday()
|
await this.credentials.getHeadersForToday()
|
||||||
);
|
);
|
||||||
|
|
|
@ -537,7 +537,7 @@ function makeHTTPError(
|
||||||
|
|
||||||
const URL_CALLS = {
|
const URL_CALLS = {
|
||||||
accountExistence: 'v1/accounts/account',
|
accountExistence: 'v1/accounts/account',
|
||||||
attachmentUploadForm: 'v3/attachments/form/upload',
|
attachmentUploadForm: 'v4/attachments/form/upload',
|
||||||
attestation: 'v1/attestation',
|
attestation: 'v1/attestation',
|
||||||
batchIdentityCheck: 'v1/profile/identity_check/batch',
|
batchIdentityCheck: 'v1/profile/identity_check/batch',
|
||||||
challenge: 'v1/challenge',
|
challenge: 'v1/challenge',
|
||||||
|
@ -982,14 +982,16 @@ export type ReportMessageOptionsType = Readonly<{
|
||||||
token?: string;
|
token?: string;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
const attachmentV3Response = z.object({
|
const attachmentUploadFormResponse = z.object({
|
||||||
cdn: z.literal(2).or(z.literal(3)),
|
cdn: z.literal(2).or(z.literal(3)),
|
||||||
key: z.string(),
|
key: z.string(),
|
||||||
headers: z.record(z.string()),
|
headers: z.record(z.string()),
|
||||||
signedUploadLocation: z.string(),
|
signedUploadLocation: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type AttachmentV3ResponseType = z.infer<typeof attachmentV3Response>;
|
export type AttachmentUploadFormResponseType = z.infer<
|
||||||
|
typeof attachmentUploadFormResponse
|
||||||
|
>;
|
||||||
|
|
||||||
export type ServerKeyCountType = {
|
export type ServerKeyCountType = {
|
||||||
count: number;
|
count: number;
|
||||||
|
@ -1214,7 +1216,7 @@ export type WebAPIType = {
|
||||||
timeout?: number;
|
timeout?: number;
|
||||||
};
|
};
|
||||||
}) => Promise<Readable>;
|
}) => Promise<Readable>;
|
||||||
getAttachmentUploadForm: () => Promise<AttachmentV3ResponseType>;
|
getAttachmentUploadForm: () => Promise<AttachmentUploadFormResponseType>;
|
||||||
getAvatar: (path: string) => Promise<Uint8Array>;
|
getAvatar: (path: string) => Promise<Uint8Array>;
|
||||||
getHasSubscription: (subscriberId: Uint8Array) => Promise<boolean>;
|
getHasSubscription: (subscriberId: Uint8Array) => Promise<boolean>;
|
||||||
getGroup: (options: GroupCredentialsType) => Promise<Proto.IGroupResponse>;
|
getGroup: (options: GroupCredentialsType) => Promise<Proto.IGroupResponse>;
|
||||||
|
@ -1304,7 +1306,7 @@ export type WebAPIType = {
|
||||||
) => Promise<VerifyServiceIdResponseType>;
|
) => Promise<VerifyServiceIdResponseType>;
|
||||||
putEncryptedAttachment: (
|
putEncryptedAttachment: (
|
||||||
encryptedBin: Uint8Array | (() => Readable),
|
encryptedBin: Uint8Array | (() => Readable),
|
||||||
uploadForm: AttachmentV3ResponseType
|
uploadForm: AttachmentUploadFormResponseType
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
putProfile: (
|
putProfile: (
|
||||||
jsonData: ProfileRequestDataType
|
jsonData: ProfileRequestDataType
|
||||||
|
@ -1368,17 +1370,17 @@ export type WebAPIType = {
|
||||||
}
|
}
|
||||||
) => Promise<MultiRecipient200ResponseType>;
|
) => Promise<MultiRecipient200ResponseType>;
|
||||||
createFetchForAttachmentUpload(
|
createFetchForAttachmentUpload(
|
||||||
attachment: AttachmentV3ResponseType
|
attachment: AttachmentUploadFormResponseType
|
||||||
): FetchFunctionType;
|
): FetchFunctionType;
|
||||||
getBackupInfo: (
|
getBackupInfo: (
|
||||||
headers: BackupPresentationHeadersType
|
headers: BackupPresentationHeadersType
|
||||||
) => Promise<GetBackupInfoResponseType>;
|
) => Promise<GetBackupInfoResponseType>;
|
||||||
getBackupUploadForm: (
|
getBackupUploadForm: (
|
||||||
headers: BackupPresentationHeadersType
|
headers: BackupPresentationHeadersType
|
||||||
) => Promise<AttachmentV3ResponseType>;
|
) => Promise<AttachmentUploadFormResponseType>;
|
||||||
getBackupMediaUploadForm: (
|
getBackupMediaUploadForm: (
|
||||||
headers: BackupPresentationHeadersType
|
headers: BackupPresentationHeadersType
|
||||||
) => Promise<AttachmentV3ResponseType>;
|
) => Promise<AttachmentUploadFormResponseType>;
|
||||||
refreshBackup: (headers: BackupPresentationHeadersType) => Promise<void>;
|
refreshBackup: (headers: BackupPresentationHeadersType) => Promise<void>;
|
||||||
getBackupCredentials: (
|
getBackupCredentials: (
|
||||||
options: GetBackupCredentialsOptionsType
|
options: GetBackupCredentialsOptionsType
|
||||||
|
@ -2769,14 +2771,14 @@ export function initialize({
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
});
|
});
|
||||||
|
|
||||||
return attachmentV3Response.parse(res);
|
return attachmentUploadFormResponse.parse(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
function createFetchForAttachmentUpload({
|
function createFetchForAttachmentUpload({
|
||||||
signedUploadLocation,
|
signedUploadLocation,
|
||||||
headers: uploadHeaders,
|
headers: uploadHeaders,
|
||||||
cdn,
|
cdn,
|
||||||
}: AttachmentV3ResponseType): FetchFunctionType {
|
}: AttachmentUploadFormResponseType): FetchFunctionType {
|
||||||
strictAssert(cdn === 3, 'Fetch can only be created for CDN 3');
|
strictAssert(cdn === 3, 'Fetch can only be created for CDN 3');
|
||||||
const { origin: expectedOrigin } = new URL(signedUploadLocation);
|
const { origin: expectedOrigin } = new URL(signedUploadLocation);
|
||||||
|
|
||||||
|
@ -2820,7 +2822,7 @@ export function initialize({
|
||||||
responseType: 'json',
|
responseType: 'json',
|
||||||
});
|
});
|
||||||
|
|
||||||
return attachmentV3Response.parse(res);
|
return attachmentUploadFormResponse.parse(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshBackup(headers: BackupPresentationHeadersType) {
|
async function refreshBackup(headers: BackupPresentationHeadersType) {
|
||||||
|
@ -3520,7 +3522,7 @@ export function initialize({
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getAttachmentUploadForm() {
|
async function getAttachmentUploadForm() {
|
||||||
return attachmentV3Response.parse(
|
return attachmentUploadFormResponse.parse(
|
||||||
await _ajax({
|
await _ajax({
|
||||||
call: 'attachmentUploadForm',
|
call: 'attachmentUploadForm',
|
||||||
httpType: 'GET',
|
httpType: 'GET',
|
||||||
|
@ -3531,7 +3533,7 @@ export function initialize({
|
||||||
|
|
||||||
async function putEncryptedAttachment(
|
async function putEncryptedAttachment(
|
||||||
encryptedBin: Uint8Array | (() => Readable),
|
encryptedBin: Uint8Array | (() => Readable),
|
||||||
uploadForm: AttachmentV3ResponseType
|
uploadForm: AttachmentUploadFormResponseType
|
||||||
) {
|
) {
|
||||||
const { signedUploadLocation, headers } = uploadForm;
|
const { signedUploadLocation, headers } = uploadForm;
|
||||||
|
|
||||||
|
@ -3558,7 +3560,7 @@ export function initialize({
|
||||||
const uploadLocation = uploadResponse.headers.get('location');
|
const uploadLocation = uploadResponse.headers.get('location');
|
||||||
strictAssert(
|
strictAssert(
|
||||||
uploadLocation,
|
uploadLocation,
|
||||||
'attachment v3 response header has no location'
|
'attachment upload form header has no location'
|
||||||
);
|
);
|
||||||
|
|
||||||
// This is going to the CDN, not the service, so we use _outerAjax
|
// This is going to the CDN, not the service, so we use _outerAjax
|
||||||
|
|
|
@ -11,7 +11,7 @@ import { strictAssert } from './assert';
|
||||||
import { backupsService } from '../services/backups';
|
import { backupsService } from '../services/backups';
|
||||||
import { tusUpload } from './uploads/tusProtocol';
|
import { tusUpload } from './uploads/tusProtocol';
|
||||||
import { defaultFileReader } from './uploads/uploads';
|
import { defaultFileReader } from './uploads/uploads';
|
||||||
import type { AttachmentV3ResponseType } from '../textsecure/WebAPI';
|
import type { AttachmentUploadFormResponseType } from '../textsecure/WebAPI';
|
||||||
import {
|
import {
|
||||||
type EncryptedAttachmentV2,
|
type EncryptedAttachmentV2,
|
||||||
encryptAttachmentV2ToDisk,
|
encryptAttachmentV2ToDisk,
|
||||||
|
@ -79,7 +79,7 @@ export async function encryptAndUploadAttachment({
|
||||||
const { server } = window.textsecure;
|
const { server } = window.textsecure;
|
||||||
strictAssert(server, 'WebAPI must be initialized');
|
strictAssert(server, 'WebAPI must be initialized');
|
||||||
|
|
||||||
let uploadForm: AttachmentV3ResponseType;
|
let uploadForm: AttachmentUploadFormResponseType;
|
||||||
let absoluteCiphertextPath: string | undefined;
|
let absoluteCiphertextPath: string | undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -129,7 +129,7 @@ export async function uploadFile({
|
||||||
}: {
|
}: {
|
||||||
absoluteCiphertextPath: string;
|
absoluteCiphertextPath: string;
|
||||||
ciphertextFileSize: number;
|
ciphertextFileSize: number;
|
||||||
uploadForm: AttachmentV3ResponseType;
|
uploadForm: AttachmentUploadFormResponseType;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const { server } = window.textsecure;
|
const { server } = window.textsecure;
|
||||||
strictAssert(server, 'WebAPI must be initialized');
|
strictAssert(server, 'WebAPI must be initialized');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue