init: add ubuntu keyserver
This commit is contained in:
parent
e5c8dc252a
commit
81ff06001c
|
@ -1,11 +1,12 @@
|
|||
import { Module } from '@nestjs/common'
|
||||
import { HKPController } from './controllers/hkp.controller.js'
|
||||
import { OpenPGPKeysProvider } from './providers/openpgp.provider.js'
|
||||
import { AllKeysProvider } from './providers/all.provider.js'
|
||||
import { Module } from '@nestjs/common';
|
||||
import { HKPController } from './controllers/hkp.controller.js';
|
||||
import { OpenPGPKeysProvider } from './providers/openpgp.provider.js';
|
||||
import { AllKeysProvider } from './providers/all.provider.js';
|
||||
import { UbuntuKeysProvider } from './providers/ubuntu.provider.js';
|
||||
|
||||
@Module({
|
||||
providers: [OpenPGPKeysProvider, AllKeysProvider],
|
||||
providers: [OpenPGPKeysProvider, UbuntuKeysProvider, AllKeysProvider],
|
||||
controllers: [HKPController],
|
||||
exports: [OpenPGPKeysProvider, AllKeysProvider],
|
||||
exports: [OpenPGPKeysProvider, UbuntuKeysProvider, AllKeysProvider],
|
||||
})
|
||||
export class KeysModule {}
|
||||
|
|
|
@ -5,6 +5,7 @@ import {
|
|||
} from './abstract.provider.js'
|
||||
import { Indexes, InfoLine } from '../indexes.js'
|
||||
import { OpenPGPKeysProvider } from './openpgp.provider.js'
|
||||
import { UbuntuKeysProvider } from './ubuntu.provider.js';
|
||||
|
||||
/**
|
||||
* This provider searches all key providers and returns their combined result
|
||||
|
@ -14,10 +15,10 @@ export class AllKeysProvider implements AbstractKeysProvider {
|
|||
|
||||
readonly url = Object.freeze('http://none');
|
||||
|
||||
constructor(private openPgpKeysProvider: OpenPGPKeysProvider) {}
|
||||
constructor(private openPgpKeysProvider: OpenPGPKeysProvider, private ubuntuKeysProvider: UbuntuKeysProvider) {}
|
||||
|
||||
getAll(): AbstractKeysProvider[] {
|
||||
return [this.openPgpKeysProvider]
|
||||
return [this.openPgpKeysProvider, this.ubuntuKeysProvider]
|
||||
}
|
||||
|
||||
@Get()
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { ResponsePromise } from 'ky';
|
||||
import type { KyResponse, ResponsePromise } from 'ky';
|
||||
import ky from 'ky'
|
||||
import type {
|
||||
AdditionalData,
|
||||
|
@ -30,11 +30,12 @@ export function proxyRequest(
|
|||
headers: {
|
||||
'User-Agent': 'Cupid (https://cupid.blek.codes)',
|
||||
},
|
||||
timeout: 15000,
|
||||
searchParams: {
|
||||
op,
|
||||
search,
|
||||
},
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export async function proxyGetOp(
|
||||
|
@ -42,12 +43,17 @@ export async function proxyGetOp(
|
|||
search: string,
|
||||
data: AdditionalData
|
||||
): Promise<GetOperationReturn> {
|
||||
const httpRes = await proxyRequest(url, 'get', search, data)
|
||||
let httpRes: KyResponse;
|
||||
try {
|
||||
httpRes = await proxyRequest(url, 'index', search, data);
|
||||
if (httpRes.status !== 200) {
|
||||
return 404;
|
||||
}
|
||||
} catch {
|
||||
return 404
|
||||
}
|
||||
|
||||
return getKey(await httpRes.text())
|
||||
return getKey(await httpRes.text());
|
||||
}
|
||||
|
||||
export async function proxyIndexOp(
|
||||
|
@ -55,10 +61,15 @@ export async function proxyIndexOp(
|
|||
search: string,
|
||||
data: AdditionalData
|
||||
): Promise<Indexes> {
|
||||
const httpRes = await proxyRequest(url, 'index', search, data)
|
||||
let httpRes: KyResponse;
|
||||
try {
|
||||
httpRes = await proxyRequest(url, 'index', search, data);
|
||||
if (httpRes.status !== 200) {
|
||||
return []
|
||||
}
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
|
||||
const rawIndexes = await httpRes.text()
|
||||
return parseIndexes(rawIndexes.split('\n'))
|
||||
|
|
Loading…
Reference in New Issue