From 772f9ed31064c0e56e9be01b103f63289ea8e98f Mon Sep 17 00:00:00 2001 From: Yongwen Zhuang Date: Sun, 10 Sep 2023 13:40:20 +0800 Subject: [PATCH 1/2] feat: support split emotion cdn --- src/client/utils/i18n/i18n.js | 10 +++++----- src/client/view/components/TkSubmit.vue | 7 ++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index 167f27be8..f7e3b20ab 100644 --- a/src/client/utils/i18n/i18n.js +++ b/src/client/utils/i18n/i18n.js @@ -364,11 +364,11 @@ export default { `Аватар тўлдирувчиси. Стандарт: «идентификатор». Қуйидагилардан танланг: ${defaultGravatar.join(', ')}` ], [S.ACI + '_EMOTION_CDN']: [ - '表情 CDN,默认为:https://owo.imaegoo.com/owo.json', - '表情 CDN,預設為:https://owo.imaegoo.com/owo.json', - '表情 CDN 來源,預設為:https://owo.imaegoo.com/owo.json', - 'Emotion CDN. Default: https://owo.imaegoo.com/owo.json', - 'Emotion CDN. Default: https://owo.imaegoo.com/owo.json' + '表情 CDN,默认为:https://owo.imaegoo.com/owo.json。英文逗号分隔。', + '表情 CDN,預設為:https://owo.imaegoo.com/owo.json。英文逗號分隔。', + '表情 CDN 來源,預設為:https://owo.imaegoo.com/owo.json。使用英文逗號分隔。', + 'Emotion CDN. Default: https://owo.imaegoo.com/owo.json. Separate by comma.', + 'Emotion CDN. Default: https://owo.imaegoo.com/owo.json. Вергул билан ажратинг.' ], [S.ACI + '_FORBIDDEN_WORDS']: [ '违禁词配置,包含违禁词的内容会直接标记为垃圾评论。英文逗号分隔。', diff --git a/src/client/view/components/TkSubmit.vue b/src/client/view/components/TkSubmit.vue index 471f6ebf3..4538ee0ab 100644 --- a/src/client/view/components/TkSubmit.vue +++ b/src/client/view/components/TkSubmit.vue @@ -132,7 +132,12 @@ export default { }, async initOwo () { if (this.config.SHOW_EMOTION === 'true') { - const odata = await initOwoEmotion(this.config.EMOTION_CDN || 'https://owo.imaegoo.com/owo.json') + const emotion_cdn = this.config.EMOTION_CDN || 'https://owo.imaegoo.com/owo.json' + const odata = {} + emotion_cdn.split(',').forEach((url) => { + const sub_odata = await initOwoEmotion(url.trim()) + Object.assign(odata, sub_odata) + }) this.owo = new OwO({ logo: iconEmotion, // OwO button text, default: `OωO表情` container: this.$refs.owo, // OwO container, default: `document.getElementsByClassName('OwO')[0]` From 810627961df26127685907e6e5e35c02a802f5cb Mon Sep 17 00:00:00 2001 From: iMaeGoo Date: Mon, 11 Sep 2023 12:36:17 +0800 Subject: [PATCH 2/2] feat: support split emotion cdn --- src/client/utils/emotion.js | 9 ++++++++- src/client/utils/i18n/i18n.js | 10 +++++----- src/client/utils/index.js | 4 ++-- src/client/view/components/TkSubmit.vue | 9 ++------- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/client/utils/emotion.js b/src/client/utils/emotion.js index 90ddf7b78..514843a0e 100644 --- a/src/client/utils/emotion.js +++ b/src/client/utils/emotion.js @@ -18,6 +18,13 @@ function initOwoEmotion (api) { }) } +async function initOwoEmotions (apis) { + const odata = {} + const odatas = await Promise.all(apis.split(',').map((api) => initOwoEmotion(api.trim()))) + Object.assign(odata, ...odatas) + return odata +} + // 格式化不规范的 OwO 数据格式 function formatOdata (odata) { try { @@ -69,6 +76,6 @@ function initMarkedOwo (odata) { } export { - initOwoEmotion, + initOwoEmotions, initMarkedOwo } diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index f7e3b20ab..63f2ba680 100644 --- a/src/client/utils/i18n/i18n.js +++ b/src/client/utils/i18n/i18n.js @@ -364,11 +364,11 @@ export default { `Аватар тўлдирувчиси. Стандарт: «идентификатор». Қуйидагилардан танланг: ${defaultGravatar.join(', ')}` ], [S.ACI + '_EMOTION_CDN']: [ - '表情 CDN,默认为:https://owo.imaegoo.com/owo.json。英文逗号分隔。', - '表情 CDN,預設為:https://owo.imaegoo.com/owo.json。英文逗號分隔。', - '表情 CDN 來源,預設為:https://owo.imaegoo.com/owo.json。使用英文逗號分隔。', - 'Emotion CDN. Default: https://owo.imaegoo.com/owo.json. Separate by comma.', - 'Emotion CDN. Default: https://owo.imaegoo.com/owo.json. Вергул билан ажратинг.' + '表情 CDN,英文逗号分隔。默认为:https://owo.imaegoo.com/owo.json', + '表情 CDN,英文逗號分隔。預設為:https://owo.imaegoo.com/owo.json', + '表情 CDN 來源,使用英文逗號分隔。預設為:https://owo.imaegoo.com/owo.json', + 'Emotion CDN. Separate by comma. Default: https://owo.imaegoo.com/owo.json', + 'Emotion CDN. Вергул билан ажратинг. Default: https://owo.imaegoo.com/owo.json' ], [S.ACI + '_FORBIDDEN_WORDS']: [ '违禁词配置,包含违禁词的内容会直接标记为垃圾评论。英文逗号分隔。', diff --git a/src/client/utils/index.js b/src/client/utils/index.js index 7d9ece897..2d6520b4a 100644 --- a/src/client/utils/index.js +++ b/src/client/utils/index.js @@ -4,7 +4,7 @@ import marked from './marked' import renderCode from './highlight' import { isUrl, call } from './api' import { isQQ, getQQAvatar } from './avatar' -import { initOwoEmotion, initMarkedOwo } from './emotion' +import { initOwoEmotions, initMarkedOwo } from './emotion' const isNotSet = (option) => { return option === undefined || option === null || option === '' @@ -168,7 +168,7 @@ export { getFuncVer, isQQ, getQQAvatar, - initOwoEmotion, + initOwoEmotions, initMarkedOwo, getCommentsCountApi, getRecentCommentsApi, diff --git a/src/client/view/components/TkSubmit.vue b/src/client/view/components/TkSubmit.vue index 4538ee0ab..297cf656d 100644 --- a/src/client/view/components/TkSubmit.vue +++ b/src/client/view/components/TkSubmit.vue @@ -53,7 +53,7 @@ import iconImage from '@fortawesome/fontawesome-free/svgs/regular/image.svg' import Clickoutside from 'element-ui/src/utils/clickoutside' import TkAvatar from './TkAvatar.vue' import TkMetaInput from './TkMetaInput.vue' -import { marked, call, logger, renderLinks, renderMath, renderCode, initOwoEmotion, initMarkedOwo, t, getUrl, blobToDataURL } from '../../utils' +import { marked, call, logger, renderLinks, renderMath, renderCode, initOwoEmotions, initMarkedOwo, t, getUrl, blobToDataURL } from '../../utils' import OwO from '../../lib/owo' const imageTypes = [ @@ -132,12 +132,7 @@ export default { }, async initOwo () { if (this.config.SHOW_EMOTION === 'true') { - const emotion_cdn = this.config.EMOTION_CDN || 'https://owo.imaegoo.com/owo.json' - const odata = {} - emotion_cdn.split(',').forEach((url) => { - const sub_odata = await initOwoEmotion(url.trim()) - Object.assign(odata, sub_odata) - }) + const odata = await initOwoEmotions(this.config.EMOTION_CDN || 'https://owo.imaegoo.com/owo.json') this.owo = new OwO({ logo: iconEmotion, // OwO button text, default: `OωO表情` container: this.$refs.owo, // OwO container, default: `document.getElementsByClassName('OwO')[0]`