Remove window.textsecure global

This commit is contained in:
Fedor Indutny
2025-10-09 13:03:13 -07:00
committed by GitHub
parent 4e2827af4b
commit bcac163e73
250 changed files with 5177 additions and 5930 deletions

View File

@@ -1,6 +1,7 @@
// Copyright 2025 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import { strictAssert } from '../../../util/assert.js';
import type { fetchBytesViaProxy } from '../../../textsecure/WebAPI.js';
/** @internal Exported for testing */
export const _SEGMENT_SIZE_BUCKETS: ReadonlyArray<number> = [
@@ -24,11 +25,10 @@ export type _SegmentRange = Readonly<{
async function fetchContentLength(
url: string,
doFetchBytesViaProxy: typeof fetchBytesViaProxy,
signal?: AbortSignal
): Promise<number> {
const { messaging } = window.textsecure;
strictAssert(messaging, 'Missing window.textsecure.messaging');
const { response } = await messaging.server.fetchBytesViaProxy({
const { response } = await doFetchBytesViaProxy({
url,
method: 'HEAD',
signal,
@@ -92,11 +92,10 @@ async function fetchSegment(
url: string,
segmentRange: _SegmentRange,
contentLength: number,
doFetchBytesViaProxy: typeof fetchBytesViaProxy,
signal?: AbortSignal
): Promise<ArrayBufferView> {
const { messaging } = window.textsecure;
strictAssert(messaging, 'Missing window.textsecure.messaging');
const { data, response } = await messaging.server.fetchBytesViaProxy({
const { data, response } = await doFetchBytesViaProxy({
method: 'GET',
url,
signal,
@@ -140,14 +139,25 @@ async function fetchSegment(
export async function fetchInSegments(
url: string,
doFetchBytesViaProxy: typeof fetchBytesViaProxy,
signal?: AbortSignal
): Promise<Blob> {
const contentLength = await fetchContentLength(url, signal);
const contentLength = await fetchContentLength(
url,
doFetchBytesViaProxy,
signal
);
const segmentSize = _getSegmentSize(contentLength);
const segmentRanges = _getSegmentRanges(contentLength, segmentSize);
const segmentBuffers = await Promise.all(
segmentRanges.map(segmentRange => {
return fetchSegment(url, segmentRange, contentLength, signal);
return fetchSegment(
url,
segmentRange,
contentLength,
doFetchBytesViaProxy,
signal
);
})
);
return new Blob(segmentBuffers);

View File

@@ -5,6 +5,10 @@ import { z } from 'zod';
import type { Simplify } from 'type-fest';
import { strictAssert } from '../../../util/assert.js';
import { parseUnknown } from '../../../util/schemas.js';
import {
fetchJsonViaProxy,
fetchBytesViaProxy,
} from '../../../textsecure/WebAPI.js';
import { fetchInSegments } from './segments.js';
const BASE_URL = 'https://tenor.googleapis.com/v2';
@@ -196,9 +200,6 @@ export async function tenor<Path extends keyof TenorEndpoints>(
params: Omit<TenorEndpoints[Path]['params'], 'key'>,
signal?: AbortSignal
): Promise<TenorEndpoints[Path]['response']> {
const { messaging } = window.textsecure;
strictAssert(messaging, 'Missing window.textsecure.messaging');
const schema = ResponseSchemaMap[path];
strictAssert(schema, 'Missing schema');
@@ -216,7 +217,7 @@ export async function tenor<Path extends keyof TenorEndpoints>(
url.searchParams.set(key, param);
}
const response = await messaging.server.fetchJsonViaProxy({
const response = await fetchJsonViaProxy({
method: 'GET',
url: url.toString(),
signal,
@@ -229,5 +230,5 @@ export function tenorDownload(
tenorCdnUrl: string,
signal?: AbortSignal
): Promise<Blob> {
return fetchInSegments(tenorCdnUrl, signal);
return fetchInSegments(tenorCdnUrl, fetchBytesViaProxy, signal);
}