fix: 修复和优化群聊文件读取逻辑

This commit is contained in:
ikechan8370 2023-12-11 00:46:38 +08:00
parent d254163fa7
commit e61d4ff3fa
3 changed files with 17 additions and 6 deletions

View file

@ -14,6 +14,7 @@ import { translate } from './translate.js'
import uploadRecord from './uploadRecord.js'
import Version from './version.js'
import fetch, { FormData, fileFromSync } from 'node-fetch'
import https from "https";
let pdfjsLib
try {
pdfjsLib = (await import('pdfjs-dist')).default
@ -1034,10 +1035,15 @@ export function getUserSpeaker (userSetting) {
* @param url 要下载的文件链接
* @param destPath 目标路径如received/abc.pdf. 目前如果文件名重复会覆盖
* @param absolute 是否是绝对路径默认为false此时拼接在data/chatgpt下
* @param ignoreCertificateError 忽略证书错误
* @returns {Promise<string>} 最终下载文件的存储位置
*/
export async function downloadFile (url, destPath, absolute = false) {
let response = await fetch(url)
export async function downloadFile (url, destPath, absolute = false, ignoreCertificateError = true) {
let response = await fetch(url, {
agent: new https.Agent({
rejectUnauthorized: !ignoreCertificateError
})
})
if (!response.ok) {
throw new Error(`download file http error: status: ${response.status}`)
}