This commit is contained in:
tamaina 2023-06-04 15:13:53 +00:00
parent de9a5d515d
commit aead5305a7
2 changed files with 66 additions and 62 deletions

View File

@ -6,67 +6,10 @@ import { AntennaEntityService } from '@/core/entities/AntennaEntityService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { ApiError } from '../../error.js'; import { ApiError } from '../../error.js';
export const meta = {
tags: ['antennas'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: '10c673ac-8852-48eb-aa1f-f5b67f069290',
},
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '1c6b35c9-943e-48c2-81e4-2844989407f7',
},
},
res: {
type: 'object',
optional: false, nullable: false,
ref: 'Antenna',
},
} as const;
export const paramDef = {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },
name: { type: 'string', minLength: 1, maxLength: 100 },
src: { type: 'string', enum: ['home', 'all', 'users', 'list'] },
userListId: { type: 'string', format: 'misskey:id', nullable: true },
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: ['antennaId', 'name', 'src', 'keywords', 'excludeKeywords', 'users', 'caseSensitive', 'withReplies', 'withFile', 'notify'],
} 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<'antennas/update'> {
name = 'antennas/update' as const;
constructor( constructor(
@Inject(DI.antennasRepository) @Inject(DI.antennasRepository)
private antennasRepository: AntennasRepository, private antennasRepository: AntennasRepository,
@ -77,7 +20,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
private antennaEntityService: AntennaEntityService, private antennaEntityService: AntennaEntityService,
private globalEventService: GlobalEventService, private globalEventService: GlobalEventService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(async (ps, me) => {
// Fetch the antenna // Fetch the antenna
const antenna = await this.antennasRepository.findOneBy({ const antenna = await this.antennasRepository.findOneBy({
id: ps.antennaId, id: ps.antennaId,
@ -85,7 +28,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> {
}); });
if (antenna == null) { if (antenna == null) {
throw new ApiError(meta.errors.noSuchAntenna); throw new ApiError(this.meta.errors.noSuchAntenna);
} }
let userList; let userList;
@ -97,7 +40,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

@ -2142,6 +2142,67 @@ export const endpoints = {
}, },
}], }],
}, },
'antennas/update': {
tags: ['antennas'],
requireCredential: true,
prohibitMoved: true,
kind: 'write:account',
errors: {
noSuchAntenna: {
message: 'No such antenna.',
code: 'NO_SUCH_ANTENNA',
id: '10c673ac-8852-48eb-aa1f-f5b67f069290',
},
noSuchUserList: {
message: 'No such user list.',
code: 'NO_SUCH_USER_LIST',
id: '1c6b35c9-943e-48c2-81e4-2844989407f7',
},
},
defines: [{
req: {
type: 'object',
properties: {
antennaId: { type: 'string', format: 'misskey:id' },
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: ['antennaId', '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; };