mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
rework PR-comments
This commit is contained in:
parent
020713b924
commit
ffe83a5d94
@ -1,21 +1,15 @@
|
||||
import { GraphQLClient, gql } from 'graphql-request'
|
||||
import { gql } from 'graphql-request'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
import { GraphQLGetClient } from '../GraphQLGetClient'
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/`
|
||||
logger.info(`requestGetPublicKey with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = new GraphQLClient(endpoint, {
|
||||
method: 'GET',
|
||||
jsonSerializer: {
|
||||
parse: JSON.parse,
|
||||
stringify: JSON.stringify,
|
||||
},
|
||||
})
|
||||
logger.info(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const graphQLClient = GraphQLGetClient.getInstance(endpoint)
|
||||
logger.debug(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const query = gql`
|
||||
query {
|
||||
getPublicKey {
|
||||
|
||||
@ -1,21 +1,15 @@
|
||||
import { GraphQLClient, gql } from 'graphql-request'
|
||||
import { gql } from 'graphql-request'
|
||||
import { backendLogger as logger } from '@/server/logger'
|
||||
import { Community as DbCommunity } from '@entity/Community'
|
||||
import { GraphQLGetClient } from '../GraphQLGetClient'
|
||||
|
||||
// eslint-disable-next-line camelcase
|
||||
export async function requestGetPublicKey(dbCom: DbCommunity): Promise<string | undefined> {
|
||||
let endpoint = dbCom.endPoint.endsWith('/') ? dbCom.endPoint : dbCom.endPoint + '/'
|
||||
endpoint = `${endpoint}${dbCom.apiVersion}/`
|
||||
logger.info(`requestGetPublicKey with endpoint='${endpoint}'...`)
|
||||
|
||||
const graphQLClient = new GraphQLClient(endpoint, {
|
||||
method: 'GET',
|
||||
jsonSerializer: {
|
||||
parse: JSON.parse,
|
||||
stringify: JSON.stringify,
|
||||
},
|
||||
})
|
||||
logger.info(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const graphQLClient = GraphQLGetClient.getInstance(endpoint)
|
||||
logger.debug(`graphQLClient=${JSON.stringify(graphQLClient)}`)
|
||||
const query = gql`
|
||||
query {
|
||||
getPublicKey {
|
||||
|
||||
35
backend/src/federation/client/GraphQLGetClient.ts
Normal file
35
backend/src/federation/client/GraphQLGetClient.ts
Normal file
@ -0,0 +1,35 @@
|
||||
import { GraphQLClient } from 'graphql-request'
|
||||
import { PatchedRequestInit } from 'graphql-request/dist/types'
|
||||
|
||||
export class GraphQLGetClient extends GraphQLClient {
|
||||
private static instance: GraphQLGetClient
|
||||
|
||||
/**
|
||||
* The Singleton's constructor should always be private to prevent direct
|
||||
* construction calls with the `new` operator.
|
||||
*/
|
||||
// eslint-disable-next-line no-useless-constructor
|
||||
private constructor(url: string, options?: PatchedRequestInit) {
|
||||
super(url, options)
|
||||
}
|
||||
|
||||
/**
|
||||
* The static method that controls the access to the singleton instance.
|
||||
*
|
||||
* This implementation let you subclass the Singleton class while keeping
|
||||
* just one instance of each subclass around.
|
||||
*/
|
||||
public static getInstance(url: string): GraphQLGetClient {
|
||||
if (!GraphQLGetClient.instance) {
|
||||
GraphQLGetClient.instance = new GraphQLGetClient(url, {
|
||||
method: 'GET',
|
||||
jsonSerializer: {
|
||||
parse: JSON.parse,
|
||||
stringify: JSON.stringify,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return GraphQLGetClient.instance
|
||||
}
|
||||
}
|
||||
@ -20,7 +20,7 @@ export async function startValidateCommunities(timerInterval: number): Promise<v
|
||||
|
||||
export async function validateCommunities(): Promise<void> {
|
||||
const dbCommunities: DbCommunity[] = await DbCommunity.createQueryBuilder()
|
||||
.where({ verifiedAt: IsNull() })
|
||||
.where({ foreign: true, verifiedAt: IsNull() })
|
||||
.orWhere('verified_at < last_announced_at')
|
||||
.getMany()
|
||||
/*
|
||||
|
||||
@ -15,7 +15,7 @@ export class Community extends BaseEntity {
|
||||
@Column({ name: 'foreign', type: 'bool', nullable: false, default: true })
|
||||
foreign: boolean
|
||||
|
||||
@Column({ name: 'public_key', type: 'binary', length: 64, default: null, nullable: true })
|
||||
@Column({ name: 'public_key', type: 'binary', length: 64, default: null, nullable: false })
|
||||
publicKey: Buffer
|
||||
|
||||
@Column({ name: 'api_version', length: 10, nullable: false })
|
||||
@ -28,7 +28,7 @@ export class Community extends BaseEntity {
|
||||
lastAnnouncedAt: Date
|
||||
|
||||
@Column({ name: 'verified_at', type: 'datetime', nullable: true })
|
||||
verifiedAt: Date
|
||||
verifiedAt: Date | null
|
||||
|
||||
@Column({ name: 'last_error_at', type: 'datetime', nullable: true })
|
||||
lastErrorAt: Date
|
||||
|
||||
@ -14,13 +14,16 @@ export async function upgrade(queryFn: (query: string, values?: any[]) => Promis
|
||||
'ALTER TABLE `communities` ADD COLUMN `foreign` tinyint(4) NOT NULL DEFAULT 1 AFTER `id`;',
|
||||
)
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;',
|
||||
'ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(64) NOT NULL AFTER `foreign`;',
|
||||
)
|
||||
/*
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;',
|
||||
'ALTER TABLE `communities` ADD COLUMN `verified_at` datetime(3) AFTER `last_announced_at`;',
|
||||
)
|
||||
*/
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` ADD COLUMN `last_error_at` datetime(3) AFTER `verified_at`;',
|
||||
)
|
||||
}
|
||||
|
||||
export async function downgrade(queryFn: (query: string, values?: any[]) => Promise<Array<any>>) {
|
||||
@ -28,6 +31,7 @@ export async function downgrade(queryFn: (query: string, values?: any[]) => Prom
|
||||
await queryFn(
|
||||
'ALTER TABLE `communities` MODIFY COLUMN `last_announced_at` datetime(3) NOT NULL AFTER `end_point`;',
|
||||
)
|
||||
await queryFn('ALTER TABLE `communities` MODIFY COLUMN `public_key` binary(64) AFTER `id`;')
|
||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `foreign`;')
|
||||
// await queryFn('ALTER TABLE `communities` DROP COLUMN `verified_at`;')
|
||||
await queryFn('ALTER TABLE `communities` DROP COLUMN `last_error_at`;')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user