mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
commit
1876dd29ac
@ -4,7 +4,7 @@
|
|||||||
"name": "LLOneBot",
|
"name": "LLOneBot",
|
||||||
"slug": "LLOneBot",
|
"slug": "LLOneBot",
|
||||||
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
|
"description": "实现 OneBot 11 协议,用于 QQ 机器人开发",
|
||||||
"version": "3.32.7",
|
"version": "3.32.8",
|
||||||
"icon": "./icon.webp",
|
"icon": "./icon.webp",
|
||||||
"authors": [
|
"authors": [
|
||||||
{
|
{
|
||||||
|
@ -91,17 +91,26 @@ interface FetchFileRes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchFile(url: string, headersInit?: Record<string, string>): Promise<FetchFileRes> {
|
export async function fetchFile(url: string, headersInit?: Record<string, string>): Promise<FetchFileRes> {
|
||||||
const headers: Record<string, string> = {
|
const headers = new Headers({
|
||||||
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
|
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
|
||||||
'Host': new URL(url).hostname,
|
'Host': new URL(url).hostname,
|
||||||
...headersInit
|
...headersInit
|
||||||
}
|
})
|
||||||
const raw = await fetch(url, { headers }).catch((err) => {
|
let raw = await fetch(url, { headers }).catch((err) => {
|
||||||
if (err.cause) {
|
if (err.cause) {
|
||||||
throw err.cause
|
throw err.cause
|
||||||
}
|
}
|
||||||
throw err
|
throw err
|
||||||
})
|
})
|
||||||
|
if (raw.status === 403 && !headers.has('Referer')) {
|
||||||
|
headers.set('Referer', url)
|
||||||
|
raw = await fetch(url, { headers }).catch((err) => {
|
||||||
|
if (err.cause) {
|
||||||
|
throw err.cause
|
||||||
|
}
|
||||||
|
throw err
|
||||||
|
})
|
||||||
|
}
|
||||||
if (!raw.ok) throw new Error(`statusText: ${raw.statusText}`)
|
if (!raw.ok) throw new Error(`statusText: ${raw.statusText}`)
|
||||||
return {
|
return {
|
||||||
data: Buffer.from(await raw.arrayBuffer()),
|
data: Buffer.from(await raw.arrayBuffer()),
|
||||||
@ -133,7 +142,7 @@ export async function uri2local(uri: string, filename?: string, needExt?: boolea
|
|||||||
|
|
||||||
if (type === FileUriType.RemoteURL) {
|
if (type === FileUriType.RemoteURL) {
|
||||||
try {
|
try {
|
||||||
const res = await fetchFile(uri, { 'Referer': uri })
|
const res = await fetchFile(uri)
|
||||||
const match = res.url.match(/.+\/([^/?]*)(?=\?)?/)
|
const match = res.url.match(/.+\/([^/?]*)(?=\?)?/)
|
||||||
if (match?.[1]) {
|
if (match?.[1]) {
|
||||||
filename ??= match[1].replace(/[/\\:*?"<>|]/g, '_')
|
filename ??= match[1].replace(/[/\\:*?"<>|]/g, '_')
|
||||||
|
@ -127,7 +127,6 @@ class MessageUniqueWrapper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined
|
|
||||||
}
|
}
|
||||||
|
|
||||||
getShortIdByMsgId(msgId: string): number | undefined {
|
getShortIdByMsgId(msgId: string): number | undefined {
|
||||||
|
@ -1 +1 @@
|
|||||||
export const version = '3.32.7'
|
export const version = '3.32.8'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user