mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-02 16:37:36 +01:00
[API] Implement some Emoji APIs
This commit is contained in:
parent
31c3f6abf7
commit
3487ddabea
5 changed files with 117 additions and 2 deletions
|
@ -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;
|
||||
|
|
|
@ -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: {
|
33
src/server/api/endpoints/admin/emoji/list.ts
Normal file
33
src/server/api/endpoints/admin/emoji/list.ts
Normal 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
|
||||
})));
|
||||
}));
|
31
src/server/api/endpoints/admin/emoji/remove.ts
Normal file
31
src/server/api/endpoints/admin/emoji/remove.ts
Normal 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();
|
||||
}));
|
49
src/server/api/endpoints/admin/emoji/update.ts
Normal file
49
src/server/api/endpoints/admin/emoji/update.ts
Normal 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();
|
||||
}));
|
Loading…
Reference in a new issue