koishi-plugin-chat-patch 2.4.0 → 2.4.5
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/client/vue/composables/useChatData.ts +0 -1
- package/client/vue/composables/useImageCache.ts +162 -21
- package/client/vue/composables/useVideoCache.ts +16 -21
- package/client/vue/types.ts +0 -1
- package/dist/index.js +2 -2
- package/lib/config.d.ts +0 -1
- package/lib/file-manager.d.ts +2 -1
- package/lib/index.js +96 -64
- package/lib/message-handler.d.ts +1 -1
- package/package.json +3 -3
- package/src/api-handlers.ts +103 -65
- package/src/config.ts +0 -2
- package/src/file-manager.ts +7 -2
- package/src/message-handler.ts +12 -7
package/src/message-handler.ts
CHANGED
|
@@ -168,7 +168,10 @@ export class MessageHandler {
|
|
|
168
168
|
|
|
169
169
|
public async downloadAndCacheMedia(url: string, type: 'image' | 'media' | 'avatar') {
|
|
170
170
|
try {
|
|
171
|
-
if (!url || url.startsWith('data:')
|
|
171
|
+
if (!url || url.startsWith('data:')) return url
|
|
172
|
+
|
|
173
|
+
// 如果已经是 Vite @fs 路径,直接返回
|
|
174
|
+
if (url.includes('/vite/@fs/')) return url
|
|
172
175
|
|
|
173
176
|
let folder = 'media'
|
|
174
177
|
if (type === 'image') folder = 'images'
|
|
@@ -185,15 +188,17 @@ export class MessageHandler {
|
|
|
185
188
|
const filename = `${hash}${ext}`
|
|
186
189
|
const filePath = require('node:path').join(dir, filename)
|
|
187
190
|
|
|
188
|
-
if (require('node:fs').existsSync(filePath)) {
|
|
189
|
-
|
|
191
|
+
if (!require('node:fs').existsSync(filePath)) {
|
|
192
|
+
const buffer = await this.ctx.http.get(url, { responseType: 'arraybuffer' })
|
|
193
|
+
require('node:fs').writeFileSync(filePath, Buffer.from(buffer))
|
|
190
194
|
}
|
|
191
195
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
+
// 返回 Vite @fs 路径格式,让浏览器通过 Vite 开发服务器加载本地文件
|
|
197
|
+
// Windows 路径需要转换为正斜杠
|
|
198
|
+
const normalizedPath = filePath.replace(/\\/g, '/')
|
|
199
|
+
return `/vite/@fs/${normalizedPath}`
|
|
196
200
|
} catch (e) {
|
|
201
|
+
this.logger.warn('下载并缓存媒体失败:', e)
|
|
197
202
|
return url
|
|
198
203
|
}
|
|
199
204
|
}
|