2022-09-17 21:27:08 +03:00
|
|
|
import { Inject, Injectable } from '@nestjs/common';
|
|
|
|
import { Endpoint } from '@/server/api/endpoint-base.js';
|
|
|
|
import { InstancesRepository } from '@/models/index.js';
|
|
|
|
import { InstanceEntityService } from '@/core/entities/InstanceEntityService.js';
|
|
|
|
import { UtilityService } from '@/core/UtilityService.js';
|
|
|
|
import { DI } from '@/di-symbols.js';
|
2019-02-07 11:11:20 +02:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 04:20:58 +02:00
|
|
|
tags: ['federation'],
|
|
|
|
|
2022-01-18 15:27:10 +02:00
|
|
|
requireCredential: false,
|
2019-02-07 11:11:20 +02:00
|
|
|
|
2022-02-19 07:05:32 +02:00
|
|
|
res: {
|
|
|
|
oneOf: [{
|
|
|
|
type: 'object',
|
|
|
|
ref: 'FederationInstance',
|
|
|
|
}, {
|
|
|
|
type: 'null',
|
|
|
|
}],
|
2021-03-06 15:34:11 +02:00
|
|
|
},
|
2022-02-19 07:05:32 +02:00
|
|
|
} as const;
|
2021-03-06 15:34:11 +02:00
|
|
|
|
2022-02-20 06:15:40 +02:00
|
|
|
export const paramDef = {
|
2022-02-19 07:05:32 +02:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
host: { type: 'string' },
|
2021-12-09 16:58:30 +02:00
|
|
|
},
|
2022-02-19 07:05:32 +02:00
|
|
|
required: ['host'],
|
2022-01-18 15:27:10 +02:00
|
|
|
} as const;
|
2019-02-07 11:11:20 +02:00
|
|
|
|
2022-01-02 19:12:50 +02:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 21:27:08 +03:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.instancesRepository)
|
|
|
|
private instancesRepository: InstancesRepository,
|
2019-02-07 11:11:20 +02:00
|
|
|
|
2022-09-17 21:27:08 +03:00
|
|
|
private utilityService: UtilityService,
|
|
|
|
private instanceEntityService: InstanceEntityService,
|
|
|
|
) {
|
|
|
|
super(meta, paramDef, async (ps, me) => {
|
|
|
|
const instance = await this.instancesRepository
|
|
|
|
.findOneBy({ host: this.utilityService.toPuny(ps.host) });
|
|
|
|
|
|
|
|
return instance ? await this.instanceEntityService.pack(instance) : null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|