v12 (#5712)
Co-authored-by: MeiMei <30769358+mei23@users.noreply.github.com> Co-authored-by: Satsuki Yanagi <17376330+u1-liquid@users.noreply.github.com>
This commit is contained in:
parent
a5955c1123
commit
f6154dc0af
871 changed files with 26140 additions and 71950 deletions
92
src/server/api/endpoints/antennas/create.ts
Normal file
92
src/server/api/endpoints/antennas/create.ts
Normal file
|
@ -0,0 +1,92 @@
|
|||
import $ from 'cafy';
|
||||
import define from '../../define';
|
||||
import { genId } from '../../../../misc/gen-id';
|
||||
import { Antennas, UserLists } from '../../../../models';
|
||||
import { ID } from '../../../../misc/cafy-id';
|
||||
import { ApiError } from '../../error';
|
||||
|
||||
export const meta = {
|
||||
tags: ['antennas'],
|
||||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'write:account',
|
||||
|
||||
params: {
|
||||
name: {
|
||||
validator: $.str.range(1, 100)
|
||||
},
|
||||
|
||||
src: {
|
||||
validator: $.str.or(['home', 'all', 'users', 'list'])
|
||||
},
|
||||
|
||||
userListId: {
|
||||
validator: $.nullable.optional.type(ID),
|
||||
},
|
||||
|
||||
keywords: {
|
||||
validator: $.arr($.arr($.str))
|
||||
},
|
||||
|
||||
users: {
|
||||
validator: $.arr($.str)
|
||||
},
|
||||
|
||||
caseSensitive: {
|
||||
validator: $.bool
|
||||
},
|
||||
|
||||
withReplies: {
|
||||
validator: $.bool
|
||||
},
|
||||
|
||||
withFile: {
|
||||
validator: $.bool
|
||||
},
|
||||
|
||||
notify: {
|
||||
validator: $.bool
|
||||
}
|
||||
},
|
||||
|
||||
errors: {
|
||||
noSuchUserList: {
|
||||
message: 'No such user list.',
|
||||
code: 'NO_SUCH_USER_LIST',
|
||||
id: '95063e93-a283-4b8b-9aa5-bcdb8df69a7f'
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
export default define(meta, async (ps, user) => {
|
||||
let userList;
|
||||
|
||||
if (ps.src === 'list') {
|
||||
userList = await UserLists.findOne({
|
||||
id: ps.userListId,
|
||||
userId: user.id,
|
||||
});
|
||||
|
||||
if (userList == null) {
|
||||
throw new ApiError(meta.errors.noSuchUserList);
|
||||
}
|
||||
}
|
||||
|
||||
const antenna = await Antennas.save({
|
||||
id: genId(),
|
||||
createdAt: new Date(),
|
||||
userId: user.id,
|
||||
name: ps.name,
|
||||
src: ps.src,
|
||||
userListId: userList ? userList.id : null,
|
||||
keywords: ps.keywords,
|
||||
users: ps.users,
|
||||
caseSensitive: ps.caseSensitive,
|
||||
withReplies: ps.withReplies,
|
||||
withFile: ps.withFile,
|
||||
notify: ps.notify,
|
||||
});
|
||||
|
||||
return await Antennas.pack(antenna);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue