mirror of
https://activitypub.software/TransFem-org/Sharkey
synced 2024-11-22 05:55:12 +00:00
Create type definition for 'lookup-dns-cache' (#4051)
This commit is contained in:
parent
bbcdf1bb8a
commit
76569bfb08
2 changed files with 23 additions and 6 deletions
17
src/@types/lookup-dns-cache.d.ts
vendored
Normal file
17
src/@types/lookup-dns-cache.d.ts
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
declare module 'lookup-dns-cache' {
|
||||
type IPv4 = 4;
|
||||
|
||||
type IPv6 = 6;
|
||||
|
||||
type Family = IPv4 | IPv6 | undefined;
|
||||
|
||||
interface IRunOptions {
|
||||
family?: Family;
|
||||
all?: boolean;
|
||||
}
|
||||
|
||||
type RunCallback = (error: Error | null, address?: string | string[], family?: Family) => void;
|
||||
|
||||
export function lookup(hostname: string, options: IRunOptions | Family, callback: RunCallback): {} | undefined;
|
||||
export function lookup(hostname: string, callback: RunCallback): {} | undefined;
|
||||
}
|
|
@ -3,7 +3,7 @@ const { sign } = require('http-signature');
|
|||
import { URL } from 'url';
|
||||
import * as debug from 'debug';
|
||||
import * as crypto from 'crypto';
|
||||
const { lookup } = require('lookup-dns-cache');
|
||||
import { lookup, IRunOptions } from 'lookup-dns-cache';
|
||||
import * as promiseAny from 'promise-any';
|
||||
|
||||
import config from '../../config';
|
||||
|
@ -89,16 +89,16 @@ export default (user: ILocalUser, url: string, object: any) => new Promise(async
|
|||
async function resolveAddr(domain: string) {
|
||||
// v4/v6で先に取得できた方を採用する
|
||||
return await promiseAny([
|
||||
resolveAddrInner(domain, { ipv6: false }),
|
||||
resolveAddrInner(domain, { ipv6: true })
|
||||
resolveAddrInner(domain, { family: 4 }),
|
||||
resolveAddrInner(domain, { family: 6 })
|
||||
]);
|
||||
}
|
||||
|
||||
function resolveAddrInner(domain: string, options = { }): Promise<string> {
|
||||
function resolveAddrInner(domain: string, options: IRunOptions = {}): Promise<string> {
|
||||
return new Promise((res, rej) => {
|
||||
lookup(domain, options, (error: any, address: string) => {
|
||||
lookup(domain, options, (error: any, address: string | string[]) => {
|
||||
if (error) return rej(error);
|
||||
return res(address);
|
||||
return res(Array.isArray(address) ? address[0] : address);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue