2022-09-17 18:27:08 +00: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 09:11:20 +00:00
|
|
|
|
|
|
|
export const meta = {
|
2019-02-23 02:20:58 +00:00
|
|
|
tags: ['federation'],
|
|
|
|
|
2022-01-18 13:27:10 +00:00
|
|
|
requireCredential: false,
|
2019-02-07 09:11:20 +00:00
|
|
|
|
2022-02-19 05:05:32 +00:00
|
|
|
res: {
|
|
|
|
oneOf: [{
|
|
|
|
type: 'object',
|
|
|
|
ref: 'FederationInstance',
|
|
|
|
}, {
|
|
|
|
type: 'null',
|
|
|
|
}],
|
2021-03-06 13:34:11 +00:00
|
|
|
},
|
2022-02-19 05:05:32 +00:00
|
|
|
} as const;
|
2021-03-06 13:34:11 +00:00
|
|
|
|
2022-02-20 04:15:40 +00:00
|
|
|
export const paramDef = {
|
2022-02-19 05:05:32 +00:00
|
|
|
type: 'object',
|
|
|
|
properties: {
|
|
|
|
host: { type: 'string' },
|
2021-12-09 14:58:30 +00:00
|
|
|
},
|
2022-02-19 05:05:32 +00:00
|
|
|
required: ['host'],
|
2022-01-18 13:27:10 +00:00
|
|
|
} as const;
|
2019-02-07 09:11:20 +00:00
|
|
|
|
2022-01-02 17:12:50 +00:00
|
|
|
// eslint-disable-next-line import/no-default-export
|
2022-09-17 18:27:08 +00:00
|
|
|
@Injectable()
|
|
|
|
export default class extends Endpoint<typeof meta, typeof paramDef> {
|
|
|
|
constructor(
|
|
|
|
@Inject(DI.instancesRepository)
|
|
|
|
private instancesRepository: InstancesRepository,
|
2019-02-07 09:11:20 +00:00
|
|
|
|
2022-09-17 18:27:08 +00: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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|