Skip to content

Commit

Permalink
fix: backward compatibility support URL format IMAGE_CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
imaegoo committed Jan 6, 2025
1 parent 7ff8fb0 commit 9a33c0b
Show file tree
Hide file tree
Showing 6 changed files with 12,131 additions and 23 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ typings/

# Yarn Integrity file
.yarn-integrity
yarn.lock

# dotenv environment variables file
.env
Expand Down
8 changes: 4 additions & 4 deletions src/client/utils/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,10 +484,10 @@ 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('')} 需要填寫`, // 繁体中文(台湾)
`The URL for the image bed set by IMAGE_CDN. Required if your IMAGE_CDN is one of these: ${customImageBedServices.join(', ')}`, // 英文
`图床的 URL,仅当 IMAGE_CDN ${customImageBedServices.join(' / ')} 时需要填写`, // 简体中文
`圖床的 URL,僅當 IMAGE_CDN 為 ${customImageBedServices.join(' / ')} 時需要填寫`, // 繁体中文
`圖床的 URL,僅當 IMAGE_CDN 為 ${customImageBedServices.join(' / ')} 時需要填寫`, // 繁体中文(台湾)
`The URL for the image bed. 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('、')}` // 日语
],
Expand Down
2 changes: 1 addition & 1 deletion src/client/view/components/TkAdminConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default {
{ key: 'AKISMET_KEY', desc: t('ADMIN_CONFIG_ITEM_AKISMET_KEY'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}8651783edxxx`, value: '' },
{ key: 'QCLOUD_SECRET_ID', desc: t('ADMIN_CONFIG_ITEM_QCLOUD_SECRET_ID'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}AKIDBgZDdnbTw9D4ey9qPkrkwtb2Do9EwIHw`, value: '' },
{ key: 'QCLOUD_SECRET_KEY', desc: t('ADMIN_CONFIG_ITEM_QCLOUD_SECRET_KEY'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}XrkOnvKWS7WeXbP1QZT76rPgtpWx73D7`, value: '', secret: true },
{ key: 'QCLOUD_CMS_BIZTYPE', desc: t('ADMIN_CONFIG_ITEM_QCLOUD_CMS_BIZTYPE'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}1787728329856520192`, value: ''},
{ key: 'QCLOUD_CMS_BIZTYPE', desc: t('ADMIN_CONFIG_ITEM_QCLOUD_CMS_BIZTYPE'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}1787728329856520192`, value: '' },
{ key: 'LIMIT_PER_MINUTE', desc: t('ADMIN_CONFIG_ITEM_LIMIT_PER_MINUTE'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}5`, value: '' },
{ key: 'LIMIT_PER_MINUTE_ALL', desc: t('ADMIN_CONFIG_ITEM_LIMIT_PER_MINUTE_ALL'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}5`, value: '' },
{ key: 'LIMIT_LENGTH', desc: t('ADMIN_CONFIG_ITEM_LIMIT_LENGTH'), ph: `${t('ADMIN_CONFIG_EXAMPLE')}100`, value: '' },
Expand Down
32 changes: 15 additions & 17 deletions src/server/function/twikoo/utils/image.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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()
Expand All @@ -16,21 +17,18 @@ const fn = {
throw new Error('未配置图片上传服务')
}
// tip: qcloud 图床走前端上传,其他图床走后端上传
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('不支持的图片上传服务')
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, imageCdn: 'https://smms.app/api/v2/upload' })
} else if (isUrl(config.IMAGE_CDN)) {
await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN })
} else if (config.IMAGE_CDN === 'lskypro') {
await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN_URL })
} else if (config.IMAGE_CDN === 'piclist') {
await fn.uploadImageToPicList({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN_URL })
} else {
throw new Error('不支持的图片上传服务')
}
} catch (e) {
logger.error(e)
Expand Down Expand Up @@ -82,11 +80,11 @@ const fn = {
},
async uploadImageToPicList ({ photo, fileName, config, res, imageCdn }) {
// PicList https://piclist.cn/ 高效的云存储和图床平台管理工具
// 鉴权使用query参数key
// 鉴权使用 query 参数 key
const formData = new FormData()
formData.append('file', fn.base64UrlToReadStream(photo, fileName))
let url = `${imageCdn}/upload`
// 如果填写了key则拼接url
// 如果填写了 key 则拼接 url
if (config.IMAGE_CDN_TOKEN) {
url += `?key=${config.IMAGE_CDN_TOKEN}`
}
Expand Down
3 changes: 3 additions & 0 deletions src/server/function/twikoo/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ 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)
Expand Down
Loading

0 comments on commit 9a33c0b

Please sign in to comment.