[API] Implement some Emoji APIs

This commit is contained in:
syuilo 2018-11-04 03:18:32 +09:00
parent 31c3f6abf7
commit 3487ddabea
No known key found for this signature in database
GPG Key ID: BDC4C49D06AB9D69
5 changed files with 117 additions and 2 deletions

View File

@ -1,3 +1,4 @@
import * as mongo from 'mongodb';
import db from '../db/mongodb';
const Emoji = db.get<IEmoji>('emoji');
@ -8,6 +9,7 @@ Emoji.createIndex(['name', 'host'], { unique: true });
export default Emoji;
export type IEmoji = {
_id: mongo.ObjectID;
name: string;
host: string;
url: string;

View File

@ -1,6 +1,6 @@
import $ from 'cafy';
import Emoji from '../../../../models/emoji';
import define from '../../define';
import Emoji from '../../../../../models/emoji';
import define from '../../../define';
export const meta = {
desc: {

View File

@ -0,0 +1,33 @@
import $ from 'cafy';
import Emoji from '../../../../../models/emoji';
import define from '../../../define';
export const meta = {
desc: {
'ja-JP': 'カスタム絵文字を取得します。'
},
requireCredential: true,
requireAdmin: true,
params: {
host: {
validator: $.str.optional.nullable,
default: null as any
}
}
};
export default define(meta, (ps) => new Promise(async (res, rej) => {
const emojis = await Emoji.find({
host: ps.host
});
res(emojis.map(e => ({
id: e._id,
name: e.name,
aliases: e.aliases,
host: e.host,
url: e.url
})));
}));

View File

@ -0,0 +1,31 @@
import $ from 'cafy';
import Emoji from '../../../../../models/emoji';
import define from '../../../define';
import ID from '../../../../../misc/cafy-id';
export const meta = {
desc: {
'ja-JP': 'カスタム絵文字を削除します。'
},
requireCredential: true,
requireAdmin: true,
params: {
id: {
validator: $.type(ID)
}
}
};
export default define(meta, (ps) => new Promise(async (res, rej) => {
const emoji = await Emoji.findOne({
_id: ps.id
});
if (emoji == null) return rej('emoji not found');
await Emoji.remove({ _id: emoji._id });
res();
}));

View File

@ -0,0 +1,49 @@
import $ from 'cafy';
import Emoji from '../../../../../models/emoji';
import define from '../../../define';
import ID from '../../../../../misc/cafy-id';
export const meta = {
desc: {
'ja-JP': 'カスタム絵文字を更新します。'
},
requireCredential: true,
requireAdmin: true,
params: {
id: {
validator: $.type(ID)
},
name: {
validator: $.str
},
url: {
validator: $.str
},
aliases: {
validator: $.arr($.str)
}
}
};
export default define(meta, (ps) => new Promise(async (res, rej) => {
const emoji = await Emoji.findOne({
_id: ps.id
});
if (emoji == null) return rej('emoji not found');
await Emoji.update({ _id: emoji._id }, {
$set: {
name: ps.name,
aliases: ps.aliases,
url: ps.url
}
});
res();
}));