twikoo-func 1.6.39 → 1.6.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "twikoo-func",
3
- "version": "1.6.39",
3
+ "version": "1.6.41",
4
4
  "description": "A simple comment system.",
5
5
  "author": "imaegoo <hello@imaegoo.com> (https://github.com/imaegoo)",
6
6
  "license": "MIT",
package/utils/image.js CHANGED
@@ -20,9 +20,15 @@ const fn = {
20
20
  if (config.IMAGE_CDN === '7bu') {
21
21
  await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: 'https://7bu.top' })
22
22
  } else if (config.IMAGE_CDN === 'smms') {
23
- await fn.uploadImageToSmms({ photo, fileName, config, res })
23
+ await fn.uploadImageToSmms({ photo, fileName, config, res, imageCdn: 'https://smms.app/api/v2/upload' })
24
24
  } else if (isUrl(config.IMAGE_CDN)) {
25
25
  await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN })
26
+ } else if (config.IMAGE_CDN === 'lskypro') {
27
+ await fn.uploadImageToLskyPro({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN_URL })
28
+ } else if (config.IMAGE_CDN === 'piclist') {
29
+ await fn.uploadImageToPicList({ photo, fileName, config, res, imageCdn: config.IMAGE_CDN_URL })
30
+ } else {
31
+ throw new Error('不支持的图片上传服务')
26
32
  }
27
33
  } catch (e) {
28
34
  logger.error(e)
@@ -31,11 +37,11 @@ const fn = {
31
37
  }
32
38
  return res
33
39
  },
34
- async uploadImageToSmms ({ photo, fileName, config, res }) {
40
+ async uploadImageToSmms ({ photo, fileName, config, res, imageCdn }) {
35
41
  // SM.MS 图床 https://sm.ms
36
42
  const formData = new FormData()
37
43
  formData.append('smfile', fn.base64UrlToReadStream(photo, fileName))
38
- const uploadResult = await axios.post('https://smms.app/api/v2/upload', formData, {
44
+ const uploadResult = await axios.post(imageCdn, formData, {
39
45
  headers: {
40
46
  ...formData.getHeaders(),
41
47
  Authorization: config.IMAGE_CDN_TOKEN
@@ -72,6 +78,24 @@ const fn = {
72
78
  throw new Error(uploadResult.data.message)
73
79
  }
74
80
  },
81
+ async uploadImageToPicList ({ photo, fileName, config, res, imageCdn }) {
82
+ // PicList https://piclist.cn/ 高效的云存储和图床平台管理工具
83
+ // 鉴权使用 query 参数 key
84
+ const formData = new FormData()
85
+ formData.append('file', fn.base64UrlToReadStream(photo, fileName))
86
+ let url = `${imageCdn}/upload`
87
+ // 如果填写了 key 则拼接 url
88
+ if (config.IMAGE_CDN_TOKEN) {
89
+ url += `?key=${config.IMAGE_CDN_TOKEN}`
90
+ }
91
+ const uploadResult = await axios.post(url, formData)
92
+ if (uploadResult.data.success) {
93
+ res.data = uploadResult.data
94
+ res.data.url = uploadResult.data.result[0]
95
+ } else {
96
+ throw new Error(uploadResult.data.message)
97
+ }
98
+ },
75
99
  base64UrlToReadStream (base64Url, fileName) {
76
100
  const base64 = base64Url.split(';base64,').pop()
77
101
  const writePath = path.resolve(os.tmpdir(), fileName)
package/utils/index.js CHANGED
@@ -67,7 +67,7 @@ const fn = {
67
67
  if (config.SHOW_UA !== 'false') {
68
68
  try {
69
69
  const ua = bowser.getParser(comment.ua)
70
- const os = fn.fixOS(ua.getOS())
70
+ const os = fn.fixOS(ua)
71
71
  displayOs = [os.name, os.versionName ? os.versionName : os.version].join(' ')
72
72
  displayBrowser = [ua.getBrowserName(), ua.getBrowserVersion()].join(' ')
73
73
  } catch (e) {
@@ -98,7 +98,8 @@ const fn = {
98
98
  updated: comment.updated
99
99
  }
100
100
  },
101
- fixOS (os) {
101
+ fixOS (ua) {
102
+ const os = ua.getOS()
102
103
  if (!os.versionName) {
103
104
  // fix version name of Win 11 & macOS ^11 & Android ^10
104
105
  if (os.name === 'Windows' && os.version === 'NT 11.0') {
@@ -109,7 +110,8 @@ const fn = {
109
110
  11: 'Big Sur',
110
111
  12: 'Monterey',
111
112
  13: 'Ventura',
112
- 14: 'Sonoma'
113
+ 14: 'Sonoma',
114
+ 15: 'Sequoia'
113
115
  }[majorPlatformVersion]
114
116
  } else if (os.name === 'Android') {
115
117
  const majorPlatformVersion = os.version.split('.')[0]
@@ -118,12 +120,28 @@ const fn = {
118
120
  11: 'Red Velvet Cake',
119
121
  12: 'Snow Cone',
120
122
  13: 'Tiramisu',
121
- 14: 'Upside Down Cake'
123
+ 14: 'Upside Down Cake',
124
+ 15: 'Vanilla Ice Cream',
125
+ 16: 'Baklava'
122
126
  }[majorPlatformVersion]
127
+ } else if (ua.test(/harmony/i)) {
128
+ os.name = 'Harmony'
129
+ os.version = fn.getFirstMatch(/harmony[\s/-](\d+(\.\d+)*)/i, ua.getUA())
130
+ os.versionName = ''
123
131
  }
124
132
  }
125
133
  return os
126
134
  },
135
+ /**
136
+ * Get first matched item for a string
137
+ * @param {RegExp} regexp
138
+ * @param {String} ua
139
+ * @return {Array|{index: number, input: string}|*|boolean|string}
140
+ */
141
+ getFirstMatch (regexp, ua) {
142
+ const match = ua.match(regexp)
143
+ return (match && match.length > 0 && match[1]) || ''
144
+ },
127
145
  // 获取回复人昵称 / Get replied user nick name
128
146
  ruser (pid, comments = []) {
129
147
  const comment = comments.find((item) => item._id === pid)