Merge branch 'master' into eslint-database-import

This commit is contained in:
Ulf Gebhardt 2023-06-15 14:27:34 +02:00 committed by GitHub
commit 443bd2f499
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,6 +24,8 @@ type CommunityApi = {
url: string url: string
} }
type KeyPair = { publicKey: Buffer; secretKey: Buffer }
export const startDHT = async (topic: string): Promise<void> => { export const startDHT = async (topic: string): Promise<void> => {
try { try {
const TOPIC = DHT.hash(Buffer.from(topic)) const TOPIC = DHT.hash(Buffer.from(topic))
@ -32,11 +34,11 @@ export const startDHT = async (topic: string): Promise<void> => {
CONFIG.FEDERATION_DHT_SEED CONFIG.FEDERATION_DHT_SEED
? Buffer.alloc(KEY_SECRET_SEEDBYTES, CONFIG.FEDERATION_DHT_SEED) ? Buffer.alloc(KEY_SECRET_SEEDBYTES, CONFIG.FEDERATION_DHT_SEED)
: null, : null,
) ) as KeyPair
const pubKeyString = keyPair.publicKey.toString('hex') const pubKeyString = keyPair.publicKey.toString('hex')
logger.info(`keyPairDHT: publicKey=${pubKeyString}`) logger.info(`keyPairDHT: publicKey=${pubKeyString}`)
logger.debug(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`) logger.debug(`keyPairDHT: secretKey=${keyPair.secretKey.toString('hex')}`)
await writeHomeCommunityEntry(pubKeyString) await writeHomeCommunityEntry(keyPair)
const ownApiVersions = await writeFederatedHomeCommunityEntries(pubKeyString) const ownApiVersions = await writeFederatedHomeCommunityEntries(pubKeyString)
logger.info(`ApiList: ${JSON.stringify(ownApiVersions)}`) logger.info(`ApiList: ${JSON.stringify(ownApiVersions)}`)
@ -212,13 +214,13 @@ async function writeFederatedHomeCommunityEntries(pubKey: string): Promise<Commu
return homeApiVersions return homeApiVersions
} }
async function writeHomeCommunityEntry(pubKey: string): Promise<void> { async function writeHomeCommunityEntry(keyPair: KeyPair): Promise<void> {
try { try {
// check for existing homeCommunity entry // check for existing homeCommunity entry
let homeCom = await DbCommunity.findOne({ foreign: false }) let homeCom = await DbCommunity.findOne({ foreign: false })
if (homeCom) { if (homeCom) {
// simply update the existing entry, but it MUST keep the ID and UUID because of possible relations // simply update the existing entry, but it MUST keep the ID and UUID because of possible relations
homeCom.publicKey = Buffer.from(pubKey) homeCom.publicKey = keyPair.publicKey
homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/'
homeCom.name = CONFIG.COMMUNITY_NAME homeCom.name = CONFIG.COMMUNITY_NAME
homeCom.description = CONFIG.COMMUNITY_DESCRIPTION homeCom.description = CONFIG.COMMUNITY_DESCRIPTION
@ -228,7 +230,7 @@ async function writeHomeCommunityEntry(pubKey: string): Promise<void> {
// insert a new homecommunity entry including a new ID and a new but ensured unique UUID // insert a new homecommunity entry including a new ID and a new but ensured unique UUID
homeCom = new DbCommunity() homeCom = new DbCommunity()
homeCom.foreign = false homeCom.foreign = false
homeCom.publicKey = Buffer.from(pubKey) homeCom.publicKey = keyPair.publicKey
homeCom.communityUuid = await newCommunityUuid() homeCom.communityUuid = await newCommunityUuid()
homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/' homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/'
homeCom.name = CONFIG.COMMUNITY_NAME homeCom.name = CONFIG.COMMUNITY_NAME