This commit is contained in:
tamaina 2023-06-04 14:56:36 +00:00
parent 4001c974a6
commit c4f434aa01
2 changed files with 71 additions and 34 deletions

View file

@ -8,36 +8,6 @@ import { DI } from '@/di-symbols.js';
import { RoleService } from '@/core/RoleService.js'; import { RoleService } from '@/core/RoleService.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
export const meta = {
tags: ['antennas'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '95063e93-a283-4b8b-9aa5-bcdb8df69a7f',
},
tooManyAntennas: {
message: 'You cannot create antenna any more.',
code: 'TOO_MANY_ANTENNAS',
id: 'faf47050-e8b5-438c-913c-db2b1576fde4',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Antenna',
},
} as const;
export const paramDef = { export const paramDef = {
type: 'object', type: 'object',
properties: { properties: {
@ -67,7 +37,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<'antenna/create'> {
name = 'antenna/create' as const;
constructor( constructor(
@Inject(DI.antennasRepository) @Inject(DI.antennasRepository)
private antennasRepository: AntennasRepository, private antennasRepository: AntennasRepository,
@ -80,7 +51,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private idService: IdService, private idService: IdService,
private globalEventService: GlobalEventService, private globalEventService: GlobalEventService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
if ((ps.keywords.length === 0) || ps.keywords[0].every(x => x === '')) { if ((ps.keywords.length === 0) || ps.keywords[0].every(x => x === '')) {
throw new Error('invalid param'); throw new Error('invalid param');
} }
@ -89,7 +60,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
userId: me.id, userId: me.id,
}); });
if (currentAntennasCount > (await this.roleService.getUserPolicies(me.id)).antennaLimit) { if (currentAntennasCount > (await this.roleService.getUserPolicies(me.id)).antennaLimit) {
throw new ApiError(meta.errors.tooManyAntennas); throw new ApiError(this.meta.errors.tooManyAntennas);
} }
let userList; let userList;
@ -101,7 +72,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}); });
if (userList == null) { if (userList == null) {
throw new ApiError(meta.errors.noSuchUserList); throw new ApiError(this.meta.errors.noSuchUserList);
} }
} }

View file

@ -1969,6 +1969,72 @@ export const endpoints = {
//#endregion //#endregion
//#region antenna //#region antenna
'antenna/create': {
tags: ['antennas'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '95063e93-a283-4b8b-9aa5-bcdb8df69a7f',
},
tooManyAntennas: {
message: 'You cannot create antenna any more.',
code: 'TOO_MANY_ANTENNAS',
id: 'faf47050-e8b5-438c-913c-db2b1576fde4',
},
},
defines: [{
req: {
type: 'object',
properties: {
name: { type: 'string', minLength: 1, maxLength: 100 },
src: { type: 'string', enum: ['home', 'all', 'users', 'list'] },
userListId: {
oneOf: [
{ type: 'string', format: 'misskey:id' },
{ type: 'null' },
],
},
keywords: {
type: 'array', items: {
type: 'array', items: {
type: 'string',
},
}
},
excludeKeywords: {
type: 'array', items: {
type: 'array', items: {
type: 'string',
},
}
},
users: {
type: 'array', items: {
type: 'string',
}
},
caseSensitive: { type: 'boolean' },
withReplies: { type: 'boolean' },
withFile: { type: 'boolean' },
notify: { type: 'boolean' },
},
required: ['name', 'src', 'keywords', 'excludeKeywords', 'users', 'caseSensitive', 'withReplies', 'withFile', 'notify'],
},
res: {
$ref: 'https://misskey-hub.net/api/schemas/Antenna',
}
}],
},
//#endregion //#endregion
} as const satisfies { [x: string]: IEndpointMeta; }; } as const satisfies { [x: string]: IEndpointMeta; };