koishi-plugin-ll-douyin 0.1.1 → 0.1.2
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/lib/index.js +24 -6
- package/package.json +1 -1
- package/readme.md +3 -0
package/lib/index.js
CHANGED
|
@@ -42,7 +42,9 @@ exports.Config = Schema.object({
|
|
|
42
42
|
}).description('推送内容'),
|
|
43
43
|
|
|
44
44
|
video: Schema.object({
|
|
45
|
-
mode: Schema.union(['video', 'file'
|
|
45
|
+
mode: Schema.union(['video', 'file', 'link'])
|
|
46
|
+
.description('视频投递方式:video = 视频消息,file = 群文件,link = 只发封面 + 链接(最省流量,不会被视频审核卡)')
|
|
47
|
+
.default('video'),
|
|
46
48
|
delivery: Schema.union(['auto', 'direct', 'download']).description('直链投递 / 先下载再投递').default('auto'),
|
|
47
49
|
sizeLimitMb: Schema.number().description('体积上限(MB),超过则改发链接').min(0).default(100),
|
|
48
50
|
coverOnFallback: Schema.boolean().description('降级发链接时附带封面').default(true),
|
|
@@ -171,6 +173,17 @@ function apply(ctx, config) {
|
|
|
171
173
|
return `data:${mime};base64,${body.toString('base64')}`
|
|
172
174
|
}
|
|
173
175
|
|
|
176
|
+
/** 封面图元素,需要本地化时转 data URI,失败退回直链。 */
|
|
177
|
+
async function coverEl(url, localize) {
|
|
178
|
+
if (!url) return null
|
|
179
|
+
if (!localize) return h.image(url)
|
|
180
|
+
try {
|
|
181
|
+
return h.image(await asDataUri(url, 20 * MB, 'image/jpeg'))
|
|
182
|
+
} catch (e) {
|
|
183
|
+
return h.image(url)
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
174
187
|
async function buildPlan(post, platform) {
|
|
175
188
|
const opt = config.content
|
|
176
189
|
const lines = []
|
|
@@ -205,12 +218,17 @@ function apply(ctx, config) {
|
|
|
205
218
|
const url = config.video.preferNoWatermark
|
|
206
219
|
? postNoWatermarkUrl(post) || post.videoUrl
|
|
207
220
|
: post.videoUrl || postNoWatermarkUrl(post)
|
|
221
|
+
const limit = Math.max(config.video.sizeLimitMb, 0) * MB
|
|
208
222
|
|
|
209
|
-
|
|
223
|
+
// mode=link:不发视频本体,只发「封面 + 链接」
|
|
224
|
+
if (config.video.mode === 'link') {
|
|
225
|
+
lines.push(`🔗 ${link}`)
|
|
226
|
+
if (config.video.coverOnFallback && post.coverUrl) media.push(await coverEl(post.coverUrl, localize))
|
|
227
|
+
kind = 'link'
|
|
228
|
+
} else if (!url) {
|
|
210
229
|
lines.push(`🔗 ${link}`)
|
|
211
230
|
kind = 'link'
|
|
212
231
|
} else {
|
|
213
|
-
const limit = Math.max(config.video.sizeLimitMb, 0) * MB
|
|
214
232
|
let size = 0
|
|
215
233
|
if (limit > 0) {
|
|
216
234
|
try {
|
|
@@ -224,7 +242,7 @@ function apply(ctx, config) {
|
|
|
224
242
|
degraded = true
|
|
225
243
|
lines.push(`🎬 视频约 ${(size / MB).toFixed(1)}MB,超过 ${config.video.sizeLimitMb}MB 上限,改为发送链接:`)
|
|
226
244
|
lines.push(`🔗 ${link}`)
|
|
227
|
-
if (config.video.coverOnFallback && post.coverUrl) media.push(
|
|
245
|
+
if (config.video.coverOnFallback && post.coverUrl) media.push(await coverEl(post.coverUrl, localize))
|
|
228
246
|
kind = 'link'
|
|
229
247
|
} else {
|
|
230
248
|
kind = config.video.mode === 'file' ? 'file' : 'video'
|
|
@@ -237,7 +255,7 @@ function apply(ctx, config) {
|
|
|
237
255
|
degraded = true
|
|
238
256
|
lines.push(`🎬 视频下载失败(${e.message}),改为发送链接:`)
|
|
239
257
|
lines.push(`🔗 ${link}`)
|
|
240
|
-
if (config.video.coverOnFallback && post.coverUrl) media.push(
|
|
258
|
+
if (config.video.coverOnFallback && post.coverUrl) media.push(await coverEl(post.coverUrl, localize))
|
|
241
259
|
kind = 'link'
|
|
242
260
|
}
|
|
243
261
|
}
|
|
@@ -256,7 +274,7 @@ function apply(ctx, config) {
|
|
|
256
274
|
// 媒体发不出去时的兜底:文本 + 链接 + 封面
|
|
257
275
|
fallback: {
|
|
258
276
|
text: [text, `🔗 ${link}`].filter(Boolean).join('\n'),
|
|
259
|
-
media: post.coverUrl ? [
|
|
277
|
+
media: post.coverUrl ? [await coverEl(post.coverUrl, localize)] : [],
|
|
260
278
|
},
|
|
261
279
|
}
|
|
262
280
|
}
|
package/package.json
CHANGED
package/readme.md
CHANGED