Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
mei23 committed Jun 10, 2020
1 parent 4940118 commit 90590ae
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 1 deletion.
8 changes: 8 additions & 0 deletions locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1431,6 +1431,14 @@ admin/views/emoji.vue:
remove-emoji:
are-you-sure: "Delete \"$1\"?"
removed: "Deleted"
remoteEmojis: "Remote emojis"
copy: "Copy"
copied: "Copied"
name: "Name"
host: "Host"
loadNext: "Next page"
loadFirst: "First page"

admin/views/announcements.vue:
announcements: "Announcements"
save: "Save"
Expand Down
7 changes: 7 additions & 0 deletions locales/ja-JP.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,13 @@ admin/views/emoji.vue:
remove-emoji:
are-you-sure: "「$1」を削除しますか?"
removed: "削除しました"
remoteEmojis: "リモート絵文字"
copy: "コピーする"
copied: "コピーしました"
name: "絵文字名"
host: "ホスト"
loadNext: "次のページ"
loadFirst: "最初のページ"

admin/views/announcements.vue:
announcements: "お知らせ"
Expand Down
21 changes: 20 additions & 1 deletion src/client/app/admin/views/emoji.vue
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
</ui-card>

<ui-card>
<template #title><fa :icon="faGrin"/> {{ $t('localEmojis') }}</template>
<template #title><fa :icon="faGrin"/> {{ $t('emojis.title') }}</template>
<section style="padding: 16px 32px">
<ui-horizon-group searchboxes>
<ui-input v-model="searchLocal" type="text" spellcheck="false" @input="fetchEmojis('local', true)">
Expand Down Expand Up @@ -85,6 +85,7 @@
</div>
<div class="detail">
<div>{{ `${emoji.name}@${emoji.host}` }}</div>
<ui-button @click="copy(emoji.id)">{{ $t('copy') }}</ui-button>
</div>
</section>

Expand Down Expand Up @@ -156,6 +157,23 @@ export default Vue.extend({
});
},
copy(id: any) {
this.$root.api('admin/emoji/copy', {
emojiId: id,
}).then(() => {
this.fetchEmojis('local', true);
this.$root.dialog({
type: 'success',
text: this.$t('copied')
});
}).catch(e => {
this.$root.dialog({
type: 'error',
text: e
});
});
},
fetchEmojis(kind?: string, truncate?: boolean) {
if (!kind || kind === 'local') {
if (truncate) this.offset = 0;
Expand Down Expand Up @@ -184,6 +202,7 @@ export default Vue.extend({
this.$root.api('admin/emoji/list', {
remote: true,
name: this.searchRemote,
host: this.searchHost || undefined,
offset: this.remoteOffset,
limit: this.limit + 1,
}).then((emojis: any[]) => {
Expand Down
67 changes: 67 additions & 0 deletions src/server/api/endpoints/admin/emoji/copy.ts
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
};
});
1 change: 1 addition & 0 deletions src/server/api/endpoints/admin/emoji/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default define(meta, async (ps) => {
}

const emojis = await Emoji.find(query, {
sort: { _id: -1 },
skip: ps.offset,
limit: ps.limit
});
Expand Down

0 comments on commit 90590ae

Please sign in to comment.