From 63784497a94234526eb65b36ff7f4f323a5b540d Mon Sep 17 00:00:00 2001 From: duzhuoshanwai <65448395+duzhuoshanwai@users.noreply.github.com> Date: Mon, 6 Jan 2025 14:35:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0PicList=E5=9B=BE=E5=BA=8A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20(#777)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 添加PicList图床支持 * 更新PicList相关配置项 * 移除不必要的注释 * 删除失误上传的调试信息 * Update src/client/utils/i18n/i18n.js Co-authored-by: iMaeGoo * 移除isLskyProUrl和isPicListUrl函数 --------- Co-authored-by: iMaeGoo --- src/client/utils/i18n/i18n.js | 21 ++++++++-- src/client/view/components/TkAdminConfig.vue | 1 + src/server/function/twikoo/utils/image.js | 44 ++++++++++++++++---- src/server/function/twikoo/utils/index.js | 3 -- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index 306082c20..9d7bbbfe2 100644 --- a/src/client/utils/i18n/i18n.js +++ b/src/client/utils/i18n/i18n.js @@ -88,9 +88,15 @@ const highlightPlugins = [ const imageBedServices = [ 'qcloud', - '7bu', - 'https://7bu.top', - 'smms' + '7bu (https://7bu.top)', + 'smms (https://sm.ms)', + 'lskypro', + 'piclist' +].map(s => `"${s}"`) + +const customImageBedServices = [ + 'lskypro', + 'piclist' ].map(s => `"${s}"`) const defaultGravatar = [ @@ -476,6 +482,15 @@ export default { `Расм юклаш учун расм тўшаги. Қуйидагилардан танланг: ${imageBedServices.join(', ')}`, `画像のアップロードに使用する画像ホスティングサービス。次のうちから選択してください:${imageBedServices.join('、')}` ], + // 翻译来自 Deepseek + [S.ACI + '_IMAGE_CDN_URL']: [ + `IMAGE_CDN 设置的图床的 URL,如果你的 IMAGE_CDN 是这些:${customImageBedServices.join('、')} 需要填写`, // 简体中文 + `IMAGE_CDN 設定的圖床的URL, 如果你的IMAGE_CDN是這些: ${customImageBedServices.join('、')} 需要填寫`, // 繁体中文 + `IMAGE_CDN 設定的圖床的URL, 如果你的IMAGE_CDN是這些: ${customImageBedServices.join('、')} 需要填寫`, // 繁体中文(台湾) + `The URL for the image bed set by IMAGE_CDN. Required if your IMAGE_CDN is one of these: ${customImageBedServices.join(', ')}`, // 英文 + `IMAGE_CDN томонидан белгиланган расм тўшаги URL. Агар сизнинг IMAGE_CDN шулардан бири бўлса: ${customImageBedServices.join(', ')}`, // 乌兹别克语 + `IMAGE_CDNで設定した画像ホスティングサービスのURL。IMAGE_CDNが以下のいずれかの場合は入力が必要です:${customImageBedServices.join('、')}` // 日语 + ], [S.ACI + '_IMAGE_CDN_TOKEN']: [ '图床 token。qcloud 图床无需设置', '图床 token。qcloud 图床无需设置', diff --git a/src/client/view/components/TkAdminConfig.vue b/src/client/view/components/TkAdminConfig.vue index e1343c2ba..d5d883e01 100644 --- a/src/client/view/components/TkAdminConfig.vue +++ b/src/client/view/components/TkAdminConfig.vue @@ -71,6 +71,7 @@ export default { items: [ { key: 'SHOW_IMAGE', desc: t('ADMIN_CONFIG_ITEM_SHOW_IMAGE'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}false`, value: '' }, { key: 'IMAGE_CDN', desc: t('ADMIN_CONFIG_ITEM_IMAGE_CDN'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}qcloud`, value: '' }, + { key: 'IMAGE_CDN_URL', desc: t('ADMIN_CONFIG_ITEM_IMAGE_CDN_URL'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}https://piclist.example.com`, value: '' }, { key: 'IMAGE_CDN_TOKEN', desc: t('ADMIN_CONFIG_ITEM_IMAGE_CDN_TOKEN'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}example`, value: '' }, { key: 'SHOW_EMOTION', desc: t('ADMIN_CONFIG_ITEM_SHOW_EMOTION'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}false`, value: '' }, { key: 'EMOTION_CDN', desc: t('ADMIN_CONFIG_ITEM_EMOTION_CDN'), ph: '', value: '' }, diff --git a/src/server/function/twikoo/utils/image.js b/src/server/function/twikoo/utils/image.js index 5b93d3f33..e12bdb3c7 100644 --- a/src/server/function/twikoo/utils/image.js +++ b/src/server/function/twikoo/utils/image.js @@ -1,7 +1,6 @@ const fs = require('fs') const os = require('os') const path = require('path') -const { isUrl } = require('.') const { RES_CODE } = require('./constants') const { getAxios, getFormData } = require('./lib') const axios = getAxios() @@ -17,12 +16,21 @@ const fn = { throw new Error('未配置图片上传服务') } // tip: qcloud 图床走前端上传,其他图床走后端上传 - if (config.IMAGE_CDN === '7bu') { - await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: 'https://7bu.top' }) - } else if (config.IMAGE_CDN === 'smms') { - await fn.uploadImageToSmms({ photo, fileName, config, res }) - } else if (isUrl(config.IMAGE_CDN)) { - await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN }) + switch (config.IMAGE_CDN) { + case '7bu': + await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: 'https://7bu.top' }) + break + case 'smms': + await fn.uploadImageToSmms({ photo, fileName, config, res, imageCdn: 'https://smms.app/api/v2/upload' }) + break + case 'lskypro': + await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN_URL }) + break + case 'piclist': + await fn.uploadImageToPicList({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN_URL }) + break + default: + throw new Error('不支持的图片上传服务') } } catch (e) { logger.error(e) @@ -31,11 +39,11 @@ const fn = { } return res }, - async uploadImageToSmms ({ photo, fileName, config, res }) { + async uploadImageToSmms ({ photo, fileName, config, res, imageCdn }) { // SM.MS 图床 https://sm.ms const formData = new FormData() formData.append('smfile', fn.base64UrlToReadStream(photo, fileName)) - const uploadResult = await axios.post('https://smms.app/api/v2/upload', formData, { + const uploadResult = await axios.post(imageCdn, formData, { headers: { ...formData.getHeaders(), Authorization: config.IMAGE_CDN_TOKEN @@ -72,6 +80,24 @@ const fn = { throw new Error(uploadResult.data.message) } }, + async uploadImageToPicList ({ photo, fileName, config, res, imageCdn }) { + // PicList https://piclist.cn/ 高效的云存储和图床平台管理工具 + // 鉴权使用query参数key + const formData = new FormData() + formData.append('file', fn.base64UrlToReadStream(photo, fileName)) + let url = `${imageCdn}/upload` + // 如果填写了key则拼接url + if (config.IMAGE_CDN_TOKEN) { + url += `?key=${config.IMAGE_CDN_TOKEN}` + } + const uploadResult = await axios.post(url, formData) + if (uploadResult.data.success) { + res.data = uploadResult.data + res.data.url = uploadResult.data.result[0] + } else { + throw new Error(uploadResult.data.message) + } + }, base64UrlToReadStream (base64Url, fileName) { const base64 = base64Url.split(';base64,').pop() const writePath = path.resolve(os.tmpdir(), fileName) diff --git a/src/server/function/twikoo/utils/index.js b/src/server/function/twikoo/utils/index.js index 64b6448d1..200d3af64 100644 --- a/src/server/function/twikoo/utils/index.js +++ b/src/server/function/twikoo/utils/index.js @@ -206,9 +206,6 @@ const fn = { return `https://${gravatarCdn}/avatar/${mailHash}?d=${defaultGravatar}` } }, - isUrl (s) { - return /^http(s)?:\/\//.test(s) - }, isQQ (mail) { return /^[1-9][0-9]{4,10}$/.test(mail) || /^[1-9][0-9]{4,10}@qq.com$/i.test(mail)