mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-16 13:27:08 +00:00
fix: 修复和优化群聊文件读取逻辑
This commit is contained in:
parent
d254163fa7
commit
e61d4ff3fa
3 changed files with 17 additions and 6 deletions
|
|
@ -1674,8 +1674,8 @@ export class chatgpt extends plugin {
|
||||||
seq = e.source.message_id
|
seq = e.source.message_id
|
||||||
}
|
}
|
||||||
let msgs = e.isGroup ? await e.group.getChatHistory(seq, 1) : await e.friend.getChatHistory(seq, 1)
|
let msgs = e.isGroup ? await e.group.getChatHistory(seq, 1) : await e.friend.getChatHistory(seq, 1)
|
||||||
let sourceMsg = msgs[0]
|
let sourceMsg = msgs[msgs.length - 1]
|
||||||
let fileMsgElem = sourceMsg.message.find(msg => msg.type === 'file')
|
let fileMsgElem = sourceMsg.file || sourceMsg.message.find(msg => msg.type === 'file')
|
||||||
if (fileMsgElem) {
|
if (fileMsgElem) {
|
||||||
toSummaryFileContent = await extractContentFromFile(fileMsgElem, e)
|
toSummaryFileContent = await extractContentFromFile(fileMsgElem, e)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import common from '../../../lib/common/common.js'
|
|
||||||
|
|
||||||
export async function getChatHistoryGroup (e, num) {
|
export async function getChatHistoryGroup (e, num) {
|
||||||
// if (e.adapter === 'shamrock') {
|
// if (e.adapter === 'shamrock') {
|
||||||
|
|
@ -46,9 +45,15 @@ export async function getChatHistoryGroup (e, num) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
function pickMemberAsync (e, userId) {
|
async function pickMemberAsync (e, userId) {
|
||||||
|
let key = `CHATGPT:GroupMemberInfo:${e.group_id}:${userId}`
|
||||||
|
let cache = await redis.get(key)
|
||||||
|
if (cache) {
|
||||||
|
return JSON.parse(cache)
|
||||||
|
}
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
e.group.pickMember(userId, true, (sender) => {
|
e.group.pickMember(userId, true, (sender) => {
|
||||||
|
redis.set(key, JSON.stringify(sender), { EX: 86400 })
|
||||||
resolve(sender)
|
resolve(sender)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { translate } from './translate.js'
|
||||||
import uploadRecord from './uploadRecord.js'
|
import uploadRecord from './uploadRecord.js'
|
||||||
import Version from './version.js'
|
import Version from './version.js'
|
||||||
import fetch, { FormData, fileFromSync } from 'node-fetch'
|
import fetch, { FormData, fileFromSync } from 'node-fetch'
|
||||||
|
import https from "https";
|
||||||
let pdfjsLib
|
let pdfjsLib
|
||||||
try {
|
try {
|
||||||
pdfjsLib = (await import('pdfjs-dist')).default
|
pdfjsLib = (await import('pdfjs-dist')).default
|
||||||
|
|
@ -1034,10 +1035,15 @@ export function getUserSpeaker (userSetting) {
|
||||||
* @param url 要下载的文件链接
|
* @param url 要下载的文件链接
|
||||||
* @param destPath 目标路径,如received/abc.pdf. 目前如果文件名重复会覆盖。
|
* @param destPath 目标路径,如received/abc.pdf. 目前如果文件名重复会覆盖。
|
||||||
* @param absolute 是否是绝对路径,默认为false,此时拼接在data/chatgpt下
|
* @param absolute 是否是绝对路径,默认为false,此时拼接在data/chatgpt下
|
||||||
|
* @param ignoreCertificateError 忽略证书错误
|
||||||
* @returns {Promise<string>} 最终下载文件的存储位置
|
* @returns {Promise<string>} 最终下载文件的存储位置
|
||||||
*/
|
*/
|
||||||
export async function downloadFile (url, destPath, absolute = false) {
|
export async function downloadFile (url, destPath, absolute = false, ignoreCertificateError = true) {
|
||||||
let response = await fetch(url)
|
let response = await fetch(url, {
|
||||||
|
agent: new https.Agent({
|
||||||
|
rejectUnauthorized: !ignoreCertificateError
|
||||||
|
})
|
||||||
|
})
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
throw new Error(`download file http error: status: ${response.status}`)
|
throw new Error(`download file http error: status: ${response.status}`)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue