forked from misskey-dev/misskey
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
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 | ||
}); | ||
|
||
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 | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters