forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 12
/
copy.ts
68 lines (56 loc) · 1.32 KB
/
copy.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import $ from 'cafy';
import define from '../../../define';
import { ApiError } from '../../../error';
import Emoji, { IEmoji } from '../../../../../models/emoji';
import ID from '../../../../../misc/cafy-id';
import { tryStockEmoji } from '../../../../../services/emoji-store';
export const meta = {
tags: ['admin'],
requireCredential: true as const,
requireModerator: true,
params: {
emojiId: {
validator: $.type(ID)
},
},
errors: {
noSuchEmoji: {
message: 'No such emoji.',
code: 'NO_SUCH_EMOJI',
id: 'e2785b66-dca3-4087-9cac-b93c541cc425'
},
duplicatedName: {
message: 'Duplicated name.',
code: 'DUPLICATED_NAME',
id: '3206c9df-e133-4f5b-bf1f-e51123efb39d'
},
}
};
export default define(meta, async (ps, me) => {
let emoji = await Emoji.findOne(ps.emojiId);
if (emoji == null) {
throw new ApiError(meta.errors.noSuchEmoji);
}
const n = await Emoji.findOne({
name: emoji.name,
host: null,
});
if (n) {
throw new ApiError(meta.errors.duplicatedName);
}
// ローカル未保存なら保存
await tryStockEmoji(emoji);
emoji = await Emoji.findOne(ps.emojiId) as IEmoji;
const copied = await Emoji.insert({
updatedAt: new Date(),
name: emoji.name,
host: null,
aliases: [],
url: emoji.url,
type: emoji.type,
md5: emoji.md5
});
return {
id: copied._id
};
});