From b67c88626c354540755ae5fab7a5d03fd6686b97 Mon Sep 17 00:00:00 2001 From: duzhuoshanwai Date: Sat, 4 Jan 2025 08:52:24 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=B7=BB=E5=8A=A0PicList=E5=9B=BE=E5=BA=8A?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/function/twikoo/utils/image.js | 27 ++++++++++++++++++++--- src/server/function/twikoo/utils/index.js | 9 ++++++-- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/server/function/twikoo/utils/image.js b/src/server/function/twikoo/utils/image.js index 5b93d3f33..23b84cb3e 100644 --- a/src/server/function/twikoo/utils/image.js +++ b/src/server/function/twikoo/utils/image.js @@ -1,7 +1,7 @@ const fs = require('fs') const os = require('os') const path = require('path') -const { isUrl } = require('.') +const { isLskyProUrl, isPicListUrl } = require('.') const { RES_CODE } = require('./constants') const { getAxios, getFormData } = require('./lib') const axios = getAxios() @@ -17,12 +17,15 @@ const fn = { throw new Error('未配置图片上传服务') } // tip: qcloud 图床走前端上传,其他图床走后端上传 + // LskyPro 和 PicList 填写时需要添加前缀 并在下面使用slice去除前缀 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 }) + } else if (isLskyProUrl(config.IMAGE_CDN)) { + await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN.slice('LskyPro '.length) }) + } else if (isPicListUrl(config.IMAGE_CDN)) { + await fn.uploadImageToPicList({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN.slice('PicList '.length) }) } } catch (e) { logger.error(e) @@ -72,6 +75,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..549a06c03 100644 --- a/src/server/function/twikoo/utils/index.js +++ b/src/server/function/twikoo/utils/index.js @@ -206,8 +206,13 @@ const fn = { return `https://${gravatarCdn}/avatar/${mailHash}?d=${defaultGravatar}` } }, - isUrl (s) { - return /^http(s)?:\/\//.test(s) + isLskyProUrl (s) { + const regex = /^LskyPro\s+http(s):\/\/[^\s]+$/ + return regex.test(s) + }, + isPicListUrl (s) { + const regex = /^PicList\s+http(s):\/\/[^\s]+$/ + return regex.test(s) }, isQQ (mail) { return /^[1-9][0-9]{4,10}$/.test(mail) || From fdb8fb1835b2978317b27d8443c38966fc4630f4 Mon Sep 17 00:00:00 2001 From: duzhuoshanwai Date: Sun, 5 Jan 2025 06:32:22 +0800 Subject: [PATCH 2/6] =?UTF-8?q?=E6=9B=B4=E6=96=B0PicList=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/client/utils/i18n/i18n.js | 21 ++++++++++++-- src/client/view/components/TkAdminConfig.vue | 1 + src/server/function/twikoo/utils/image.js | 29 ++++++++++++-------- 3 files changed, 37 insertions(+), 14 deletions(-) diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index 306082c20..05c1ba039 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 23b84cb3e..d590d5e6f 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 { isLskyProUrl, isPicListUrl } = require('.') const { RES_CODE } = require('./constants') const { getAxios, getFormData } = require('./lib') const axios = getAxios() @@ -18,14 +17,21 @@ const fn = { } // tip: qcloud 图床走前端上传,其他图床走后端上传 // LskyPro 和 PicList 填写时需要添加前缀 并在下面使用slice去除前缀 - 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 (isLskyProUrl(config.IMAGE_CDN)) { - await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN.slice('LskyPro '.length) }) - } else if (isPicListUrl(config.IMAGE_CDN)) { - await fn.uploadImageToPicList({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN.slice('PicList '.length) }) + 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) @@ -34,11 +40,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 @@ -76,6 +82,7 @@ const fn = { } }, async uploadImageToPicList ({ photo, fileName, config, res, imageCdn }) { + logger.info( photo + fileName ) // PicList https://piclist.cn/ 高效的云存储和图床平台管理工具 // 鉴权使用query参数key const formData = new FormData() From ddd70259f2bf1764b154fac66877651903635f3f Mon Sep 17 00:00:00 2001 From: duzhuoshanwai Date: Mon, 6 Jan 2025 05:33:21 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E4=B8=8D=E5=BF=85?= =?UTF-8?q?=E8=A6=81=E7=9A=84=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/function/twikoo/utils/image.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/function/twikoo/utils/image.js b/src/server/function/twikoo/utils/image.js index d590d5e6f..9f75838cb 100644 --- a/src/server/function/twikoo/utils/image.js +++ b/src/server/function/twikoo/utils/image.js @@ -16,7 +16,6 @@ const fn = { throw new Error('未配置图片上传服务') } // tip: qcloud 图床走前端上传,其他图床走后端上传 - // LskyPro 和 PicList 填写时需要添加前缀 并在下面使用slice去除前缀 switch (config.IMAGE_CDN) { case '7bu': await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: 'https://7bu.top' }) From 73fe3c500768ca3b22ef330972467b8ec4319927 Mon Sep 17 00:00:00 2001 From: duzhuoshanwai Date: Mon, 6 Jan 2025 10:09:47 +0800 Subject: [PATCH 4/6] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=B1=E8=AF=AF?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84=E8=B0=83=E8=AF=95=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/function/twikoo/utils/image.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/server/function/twikoo/utils/image.js b/src/server/function/twikoo/utils/image.js index 9f75838cb..e12bdb3c7 100644 --- a/src/server/function/twikoo/utils/image.js +++ b/src/server/function/twikoo/utils/image.js @@ -81,7 +81,6 @@ const fn = { } }, async uploadImageToPicList ({ photo, fileName, config, res, imageCdn }) { - logger.info( photo + fileName ) // PicList https://piclist.cn/ 高效的云存储和图床平台管理工具 // 鉴权使用query参数key const formData = new FormData() From 899db2e498ab21e12cdbb285d38cc001e475b2f7 Mon Sep 17 00:00:00 2001 From: duzhuoshanwai <65448395+duzhuoshanwai@users.noreply.github.com> Date: Mon, 6 Jan 2025 10:11:12 +0800 Subject: [PATCH 5/6] Update src/client/utils/i18n/i18n.js Co-authored-by: iMaeGoo --- src/client/utils/i18n/i18n.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/client/utils/i18n/i18n.js b/src/client/utils/i18n/i18n.js index 05c1ba039..9d7bbbfe2 100644 --- a/src/client/utils/i18n/i18n.js +++ b/src/client/utils/i18n/i18n.js @@ -484,7 +484,7 @@ export default { ], // 翻译来自 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('、')} 需要填寫`, // 繁体中文 `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(', ')}`, // 英文 From dfd13dc197be5c8e382fa8bd63e20b46a3e13045 Mon Sep 17 00:00:00 2001 From: duzhuoshanwai Date: Mon, 6 Jan 2025 10:14:39 +0800 Subject: [PATCH 6/6] =?UTF-8?q?=E7=A7=BB=E9=99=A4isLskyProUrl=E5=92=8CisPi?= =?UTF-8?q?cListUrl=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/function/twikoo/utils/index.js | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/server/function/twikoo/utils/index.js b/src/server/function/twikoo/utils/index.js index 549a06c03..200d3af64 100644 --- a/src/server/function/twikoo/utils/index.js +++ b/src/server/function/twikoo/utils/index.js @@ -206,14 +206,6 @@ const fn = { return `https://${gravatarCdn}/avatar/${mailHash}?d=${defaultGravatar}` } }, - isLskyProUrl (s) { - const regex = /^LskyPro\s+http(s):\/\/[^\s]+$/ - return regex.test(s) - }, - isPicListUrl (s) { - const regex = /^PicList\s+http(s):\/\/[^\s]+$/ - return regex.test(s) - }, isQQ (mail) { return /^[1-9][0-9]{4,10}$/.test(mail) || /^[1-9][0-9]{4,10}@qq.com$/i.test(mail)