This commit is contained in:
tamaina 2023-06-20 07:38:15 +00:00
parent bad25a804c
commit 4d021f315f
8 changed files with 238 additions and 177 deletions

View file

@ -5,36 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js'; import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Following',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['host'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/followers'> {
name = 'federation/followers' as const;
constructor( constructor(
@Inject(DI.followingsRepository) @Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository, private followingsRepository: FollowingsRepository,
@ -42,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private followingEntityService: FollowingEntityService, private followingEntityService: FollowingEntityService,
private queryService: QueryService, private queryService: QueryService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId) const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere('following.followeeHost = :host', { host: ps.host }); .andWhere('following.followeeHost = :host', { host: ps.host });

View file

@ -5,36 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js'; import { FollowingEntityService } from '@/core/entities/FollowingEntityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'Following',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['host'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/followings'> {
name = 'federation/followings' as const;
constructor( constructor(
@Inject(DI.followingsRepository) @Inject(DI.followingsRepository)
private followingsRepository: FollowingsRepository, private followingsRepository: FollowingsRepository,
@ -42,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private followingEntityService: FollowingEntityService, private followingEntityService: FollowingEntityService,
private queryService: QueryService, private queryService: QueryService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId) const query = this.queryService.makePaginationQuery(this.followingsRepository.createQueryBuilder('following'), ps.sinceId, ps.untilId)
.andWhere('following.followerHost = :host', { host: ps.host }); .andWhere('following.followerHost = :host', { host: ps.host });

View file

@ -6,44 +6,10 @@ import { MetaService } from '@/core/MetaService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { sqlLikeEscape } from '@/misc/sql-like-escape.js'; import { sqlLikeEscape } from '@/misc/sql-like-escape.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
allowGet: true,
cacheSec: 3600,
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'FederationInstance',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string', nullable: true, description: 'Omit or use `null` to not filter by host.' },
blocked: { type: 'boolean', nullable: true },
notResponding: { type: 'boolean', nullable: true },
suspended: { type: 'boolean', nullable: true },
federating: { type: 'boolean', nullable: true },
subscribing: { type: 'boolean', nullable: true },
publishing: { type: 'boolean', nullable: true },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },
offset: { type: 'integer', default: 0 },
sort: { type: 'string' },
},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/instances'> {
name = 'federation/instances' as const;
constructor( constructor(
@Inject(DI.instancesRepository) @Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository, private instancesRepository: InstancesRepository,
@ -51,7 +17,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private instanceEntityService: InstanceEntityService, private instanceEntityService: InstanceEntityService,
private metaService: MetaService, private metaService: MetaService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const query = this.instancesRepository.createQueryBuilder('instance'); const query = this.instancesRepository.createQueryBuilder('instance');
switch (ps.sort) { switch (ps.sort) {

View file

@ -5,32 +5,10 @@ import { InstanceEntityService } from '@/core/entities/InstanceEntityService.js'
import { UtilityService } from '@/core/UtilityService.js'; import { UtilityService } from '@/core/UtilityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
res: {
oneOf: [{
type: 'object',
ref: 'FederationInstance',
}, {
type: 'null',
}],
},
} as const;
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },
},
required: ['host'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/show-instance'> {
name = 'federation/show-instance' as const;
constructor( constructor(
@Inject(DI.instancesRepository) @Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository, private instancesRepository: InstancesRepository,
@ -38,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private utilityService: UtilityService, private utilityService: UtilityService,
private instanceEntityService: InstanceEntityService, private instanceEntityService: InstanceEntityService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const instance = await this.instancesRepository const instance = await this.instancesRepository
.findOneBy({ host: this.utilityService.toPuny(ps.host) }); .findOneBy({ host: this.utilityService.toPuny(ps.host) });

View file

@ -25,7 +25,8 @@ export const paramDef = {
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/stats'> {
name = 'federation/stats' as const;
constructor( constructor(
@Inject(DI.instancesRepository) @Inject(DI.instancesRepository)
private instancesRepository: InstancesRepository, private instancesRepository: InstancesRepository,
@ -35,7 +36,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private instanceEntityService: InstanceEntityService, private instanceEntityService: InstanceEntityService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([ const [topSubInstances, topPubInstances, allSubCount, allPubCount] = await Promise.all([
this.instancesRepository.find({ this.instancesRepository.find({
where: { where: {

View file

@ -3,28 +3,15 @@ import { Endpoint } from '@/server/api/endpoint-base.js';
import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js'; import { ApPersonService } from '@/core/activitypub/models/ApPersonService.js';
import { GetterService } from '@/server/api/GetterService.js'; import { GetterService } from '@/server/api/GetterService.js';
export const meta = {
tags: ['federation'],
requireCredential: true,
} as const;
export const paramDef = {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/update-remote-user'> {
name = 'federation/update-remote-user' as const;
constructor( constructor(
private getterService: GetterService, private getterService: GetterService,
private apPersonService: ApPersonService, private apPersonService: ApPersonService,
) { ) {
super(meta, paramDef, async (ps) => { super(async (ps) => {
const user = await this.getterService.getRemoteUser(ps.userId); const user = await this.getterService.getRemoteUser(ps.userId);
await this.apPersonService.updatePerson(user.uri!); await this.apPersonService.updatePerson(user.uri!);
}); });

View file

@ -5,36 +5,10 @@ import { QueryService } from '@/core/QueryService.js';
import { UserEntityService } from '@/core/entities/UserEntityService.js'; import { UserEntityService } from '@/core/entities/UserEntityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
export const meta = {
tags: ['federation'],
requireCredential: false,
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'UserDetailedNotMe',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
host: { type: 'string' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['host'],
} as const;
// eslint-disable-next-line import/no-default-export // eslint-disable-next-line import/no-default-export
@Injectable() @Injectable()
export default class extends Endpoint<typeof meta, typeof paramDef> { export default class extends Endpoint<'federation/users'> {
name = 'federation/users' as const;
constructor( constructor(
@Inject(DI.usersRepository) @Inject(DI.usersRepository)
private usersRepository: UsersRepository, private usersRepository: UsersRepository,
@ -42,7 +16,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private userEntityService: UserEntityService, private userEntityService: UserEntityService,
private queryService: QueryService, private queryService: QueryService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
const query = this.queryService.makePaginationQuery(this.usersRepository.createQueryBuilder('user'), ps.sinceId, ps.untilId) const query = this.queryService.makePaginationQuery(this.usersRepository.createQueryBuilder('user'), ps.sinceId, ps.untilId)
.andWhere('user.host = :host', { host: ps.host }); .andWhere('user.host = :host', { host: ps.host });

View file

@ -4104,9 +4104,21 @@ export const endpoints = {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' }, sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' }, untilId: { type: 'string', format: 'misskey:id' },
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, folderId: {
type: { type: 'string', nullable: true, pattern: /^[a-zA-Z\/\-*]+$/.toString().slice(1, -1) }, oneOf: [
sort: { type: 'string', nullable: true, enum: ['+createdAt', '-createdAt', '+name', '-name', '+size', '-size'] }, { type: 'string', format: 'misskey:id' },
{ type: 'null' },
],
default: null,
},
type: {
oneOf: [
{ type: 'string', pattern: /^[a-zA-Z\/\-*]+$/.toString().slice(1, -1) },
{ type: 'null' },
],
default: null,
},
sort: { enum: [null, '+createdAt', '-createdAt', '+name', '-name', '+size', '-size'] },
}, },
required: [], required: [],
}, },
@ -4132,7 +4144,13 @@ export const endpoints = {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 }, limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' }, sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' }, untilId: { type: 'string', format: 'misskey:id' },
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null }, folderId: {
oneOf: [
{ type: 'string', format: 'misskey:id' },
{ type: 'null' },
],
default: null,
},
}, },
required: [], required: [],
}, },
@ -4190,10 +4208,7 @@ export const endpoints = {
properties: { properties: {
available: { type: 'boolean' }, available: { type: 'boolean' },
reason: { reason: {
oneOf: [ enum: [null, 'used', 'format', 'disposable', 'mx', 'smtp']
{ type: 'string', enum: ['used', 'format', 'disposable', 'mx', 'smtp'] },
{ type: 'null' },
],
}, },
}, },
required: [ required: [
@ -4203,6 +4218,198 @@ export const endpoints = {
}, },
}], }],
}, },
//#region federation
'federation/followers': {
tags: ['federation'],
requireCredential: false,
defines: [{
req: {
type: 'object',
properties: {
host: { type: 'string' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['host'],
},
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/Following',
},
}
}]
},
'federation/followings': {
tags: ['federation'],
requireCredential: false,
defines: [{
req: {
type: 'object',
properties: {
host: { type: 'string' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['host'],
},
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/Following',
},
}
}]
},
'federation/instances': {
tags: ['federation'],
requireCredential: false,
allowGet: true,
cacheSec: 3600,
defines: [{
req: {
type: 'object',
properties: {
host: { type: ['string', 'null'], description: 'Omit or use `null` to not filter by host.' },
blocked: { type: ['boolean', 'null'] },
notResponding: { type: ['boolean', 'null'] },
suspended: { type: ['boolean', 'null'] },
federating: { type: ['boolean', 'null'] },
subscribing: { type: ['boolean', 'null'] },
publishing: { type: ['boolean', 'null'] },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 30 },
offset: { type: 'integer', default: 0 },
sort: { type: 'string' },
},
required: [],
},
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/FederationInstance',
},
},
}],
},
'federation/show-instance': {
tags: ['federation'],
requireCredential: false,
defines: [{
req: {
type: 'object',
properties: {
host: { type: 'string' },
},
required: ['host'],
},
res: {
oneOf: [{
$ref: 'https://misskey-hub.net/api/schemas/FederationInstance',
}, {
type: 'null',
}],
}
}]
},
'federation/stats': {
tags: ['federation'],
requireCredential: false,
allowGet: true,
cacheSec: 60 * 60,
defines: [{
req: {
type: 'object',
properties: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: [],
},
res: {
type: 'object',
properties: {
topSubInstances: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/FederationInstance',
},
},
otherFollowersCount: {
type: 'number',
},
topPubInstances: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/FederationInstance',
},
},
otherFollowingCount: {
type: 'number',
},
},
required: [
'topSubInstances',
'otherFollowersCount',
'topPubInstances',
'otherFollowingCount',
],
},
}],
},
'federation/update-remote-user': {
tags: ['federation'],
requireCredential: true,
defines: [{
req: {
type: 'object',
properties: {
userId: { type: 'string', format: 'misskey:id' },
},
required: ['userId'],
},
res: undefined,
}],
},
'federation/users': {
tags: ['federation'],
requireCredential: false,
defines: [{
req: {
type: 'object',
properties: {
host: { type: 'string' },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
},
required: ['host'],
},
res: {
type: 'array',
items: {
$ref: 'https://misskey-hub.net/api/schemas/UserDetailedNotMe',
},
},
}],
},
//#endregion
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };
/** /**