fix: support pinned attachment lookup arrays
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { lookup as dnsLookup } from 'node:dns/promises';
|
||||
import { request as httpsRequest } from 'node:https';
|
||||
import { isIP } from 'node:net';
|
||||
import { isIP, type LookupFunction } from 'node:net';
|
||||
import { basename } from 'node:path';
|
||||
import { sha256Bytes } from './crypto.js';
|
||||
import { diagnosticDurationMs } from './diagnostics.js';
|
||||
@@ -207,6 +207,18 @@ export async function resolveAgentBusAttachmentAddresses(
|
||||
return addresses;
|
||||
}
|
||||
|
||||
export function createPinnedAttachmentLookup(
|
||||
address: { address: string; family: number }
|
||||
): LookupFunction {
|
||||
return (_hostname, options, callback) => {
|
||||
if (options.all) {
|
||||
callback(null, [address]);
|
||||
return;
|
||||
}
|
||||
callback(null, address.address, address.family);
|
||||
};
|
||||
}
|
||||
|
||||
async function downloadPinnedHttps(
|
||||
url: URL,
|
||||
address: { address: string; family: number },
|
||||
@@ -217,9 +229,7 @@ async function downloadPinnedHttps(
|
||||
method: 'GET',
|
||||
headers: { Accept: 'application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/octet-stream' },
|
||||
timeout: DOWNLOAD_TIMEOUT_MS,
|
||||
lookup: ((_hostname: string, _options: unknown, callback: (error: NodeJS.ErrnoException | null, address: string, family: number) => void) => {
|
||||
callback(null, address.address, address.family);
|
||||
}) as never
|
||||
lookup: createPinnedAttachmentLookup(address)
|
||||
}, (response) => {
|
||||
const statusCode = Number(response.statusCode || 0);
|
||||
const location = Array.isArray(response.headers.location) ? response.headers.location[0] : response.headers.location;
|
||||
|
||||
Reference in New Issue
Block a user