Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/twikoojs/twikoo
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Jan 7, 2025
2 parents 7447196 + a076c93 commit 5f9f4a4
Show file tree
Hide file tree
Showing 19 changed files with 12,277 additions and 34 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
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.DS_Store
.babelrc
.editorconfig
.env
.eslintignore
.eslintrc.js
.github
Expand Down
2 changes: 1 addition & 1 deletion docs/.vitepress/theme/Twikoo.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ onMounted(() => {

<!-- Twikoo -->
<div id="twikoo"></div>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/[email protected].40/dist/twikoo.min.js" crossorigin="anonymous" ref="twikooJs"></component>
<component :is="'script'" src="https://cdn.jsdelivr.net/npm/[email protected].41/dist/twikoo.min.js" crossorigin="anonymous" ref="twikooJs"></component>
</div>
</template>
2 changes: 1 addition & 1 deletion docs/backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ exports.main = require('twikoo-func').main
8. 创建完成后,点击“twikoo"进入云函数详情页,进入“函数代码”标签,点击“文件 - 新建文件”,输入 `package.json`,回车
9. 复制以下代码、粘贴到代码框中,点击“保存并安装依赖”
``` json
{ "dependencies": { "twikoo-func": "1.6.40" } }
{ "dependencies": { "twikoo-func": "1.6.41" } }
```

## 腾讯云命令行部署
Expand Down
10 changes: 5 additions & 5 deletions docs/frontend.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ twikoo:

``` html
<div id="tcomment"></div>
<script src="https://cdn.jsdelivr.net/npm/[email protected].40/dist/twikoo.all.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected].41/dist/twikoo.all.min.js"></script>
<script>
twikoo.init({
envId: '您的环境id', // 腾讯云环境填 envId;Vercel 环境填地址(https://xxx.vercel.app)
Expand All @@ -115,10 +115,10 @@ twikoo.init({

如果遇到默认 CDN 加载速度缓慢,可更换其他 CDN 镜像。以下为可供选择的公共 CDN,其中一些 CDN 可能需要数天时间同步最新版本:

* `https://s4.zstatic.net/ajax/libs/twikoo/1.6.40/twikoo.all.min.js`
* `https://registry.npmmirror.com/twikoo/1.6.40/files/dist/twikoo.all.min.js`
* `https://lib.baomitu.com/twikoo/1.6.40/twikoo.all.min.js`
* `https://cdn.jsdelivr.net/npm/[email protected].40/dist/twikoo.all.min.js`
* `https://s4.zstatic.net/ajax/libs/twikoo/1.6.41/twikoo.all.min.js`
* `https://registry.npmmirror.com/twikoo/1.6.41/files/dist/twikoo.all.min.js`
* `https://lib.baomitu.com/twikoo/1.6.41/twikoo.all.min.js`
* `https://cdn.jsdelivr.net/npm/[email protected].41/dist/twikoo.all.min.js`

::: warning 注意
建议使用 CDN 引入 Twikoo 的用户在链接地址上锁定版本,以免将来 Twikoo 升级时受到非兼容性更新的影响。
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"keywords": [
"twikoojs",
Expand Down
21 changes: 18 additions & 3 deletions src/client/utils/i18n/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -476,6 +482,15 @@ export default {
`Расм юклаш учун расм тўшаги. Қуйидагилардан танланг: ${imageBedServices.join(', ')}`,
`画像のアップロードに使用する画像ホスティングサービス。次のうちから選択してください:${imageBedServices.join('、')}`
],
// 翻译来自 Deepseek
[S.ACI + '_IMAGE_CDN_URL']: [
`图床的 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('、')}` // 日语
],
[S.ACI + '_IMAGE_CDN_TOKEN']: [
'图床 token。qcloud 图床无需设置',
'图床 token。qcloud 图床无需设置',
Expand Down
2 changes: 1 addition & 1 deletion src/client/version.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
const version = '1.6.40'
const version = '1.6.41'

export { version }
3 changes: 2 additions & 1 deletion src/client/view/components/TkAdminConfig.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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: '' },
Expand All @@ -93,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
2 changes: 1 addition & 1 deletion src/server/aws-lambda/src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-aws-lambda",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/server/function/twikoo/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-func",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
30 changes: 27 additions & 3 deletions src/server/function/twikoo/utils/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ const fn = {
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 })
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 All @@ -31,11 +37,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
Expand Down Expand Up @@ -72,6 +78,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)
Expand Down
22 changes: 19 additions & 3 deletions src/server/function/twikoo/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const fn = {
if (config.SHOW_UA !== 'false') {
try {
const ua = bowser.getParser(comment.ua)
const os = fn.fixOS(ua.getOS())
const os = fn.fixOS(ua)
displayOs = [os.name, os.versionName ? os.versionName : os.version].join(' ')
displayBrowser = [ua.getBrowserName(), ua.getBrowserVersion()].join(' ')
} catch (e) {
Expand Down Expand Up @@ -98,7 +98,8 @@ const fn = {
updated: comment.updated
}
},
fixOS (os) {
fixOS (ua) {
const os = ua.getOS()
if (!os.versionName) {
// fix version name of Win 11 & macOS ^11 & Android ^10
if (os.name === 'Windows' && os.version === 'NT 11.0') {
Expand All @@ -120,12 +121,27 @@ const fn = {
12: 'Snow Cone',
13: 'Tiramisu',
14: 'Upside Down Cake',
15: 'Vanilla Ice Cream'
15: 'Vanilla Ice Cream',
16: 'Baklava'
}[majorPlatformVersion]
} else if (ua.test(/harmony/i)) {
os.name = 'Harmony'
os.version = fn.getFirstMatch(/harmony[\s/-](\d+(\.\d+)*)/i, ua.getUA())
os.versionName = ''
}
}
return os
},
/**
* Get first matched item for a string
* @param {RegExp} regexp
* @param {String} ua
* @return {Array|{index: number, input: string}|*|boolean|string}
*/
getFirstMatch (regexp, ua) {
const match = ua.match(regexp)
return (match && match.length > 0 && match[1]) || ''
},
// 获取回复人昵称 / Get replied user nick name
ruser (pid, comments = []) {
const comment = comments.find((item) => item._id === pid)
Expand Down
2 changes: 1 addition & 1 deletion src/server/netlify/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-netlify",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion src/server/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"dependencies": {
"commander": "^11.1.0",
"dotenv": "^16.4.1",
"tkserver": "1.6.40"
"tkserver": "1.6.41"
},
"devDependencies": {
"patch-package": "^8.0.0",
Expand Down
21 changes: 15 additions & 6 deletions src/server/self-hosted/mongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,22 @@ function allowCors (request, response) {

function getAllowedOrigin (request) {
const localhostRegex = /^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0)(:\d{1,5})?$/
if (localhostRegex.test(request.headers.origin)) {
return request.headers.origin
} else if (config.CORS_ALLOW_ORIGIN) {
// 许多用户设置安全域名时,喜欢带结尾的 "/",必须处理掉
return config.CORS_ALLOW_ORIGIN.replace(/\/$/, '')
if (localhostRegex.test(request.headers.origin)) { // 判断是否为本地主机,如是则允许跨域
return request.headers.origin // Allow
} else if (config.CORS_ALLOW_ORIGIN) { // 如设置了安全域名则检查
// 适配多条 CORS 规则
// 以逗号分隔 CORS
const corsList = config.CORS_ALLOW_ORIGIN.split(',')
// 遍历 CORS 列表
for (let i = 0; i < corsList.length; i++) {
const cors = corsList[i].replace(/\/$/, '') // 获取当前 CORS 并去除末尾的斜杠
if (cors === request.headers.origin) {
return request.headers.origin // Allow
}
}
return '' // 不在安全域名列表中则禁止跨域
} else {
return request.headers.origin
return request.headers.origin // 未设置安全域名直接 Allow
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/server/self-hosted/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tkserver",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"keywords": [
"twikoo",
Expand Down Expand Up @@ -31,7 +31,7 @@
"get-user-ip": "^1.0.1",
"lokijs": "^1.5.12",
"mongodb": "^6.3.0",
"twikoo-func": "1.6.40",
"twikoo-func": "1.6.41",
"uuid": "^8.3.2"
}
}
4 changes: 2 additions & 2 deletions src/server/vercel/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "twikoo-vercel",
"version": "1.6.40",
"version": "1.6.41",
"description": "A simple comment system.",
"author": "imaegoo <[email protected]> (https://github.com/imaegoo)",
"license": "MIT",
Expand All @@ -13,7 +13,7 @@
"dependencies": {
"get-user-ip": "^1.0.1",
"mongodb": "^6.3.0",
"twikoo-func": "1.6.40",
"twikoo-func": "1.6.41",
"uuid": "^8.3.2"
}
}
Loading

0 comments on commit 5f9f4a4

Please sign in to comment.