mirror of
https://github.com/NapNeko/NapCatQQ.git
synced 2025-07-19 12:03:37 +00:00
fix: #757
This commit is contained in:
@@ -195,7 +195,7 @@ export interface OneBot11GroupUpload extends NoticeBase {
|
|||||||
name: string
|
name: string
|
||||||
/** 文件大小(字节数) */
|
/** 文件大小(字节数) */
|
||||||
size: number
|
size: number
|
||||||
/** busid(目前不清楚有什么作用) */
|
/** busid 无作用 */
|
||||||
busid: number
|
busid: number
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,8 @@ export class NTQQFileApi {
|
|||||||
core: NapCatCore;
|
core: NapCatCore;
|
||||||
rkeyManager: RkeyManager;
|
rkeyManager: RkeyManager;
|
||||||
packetRkey: Array<{ rkey: string; time: number; type: number; ttl: bigint }> | undefined;
|
packetRkey: Array<{ rkey: string; time: number; type: number; ttl: bigint }> | undefined;
|
||||||
|
private fetchRkeyFailures: number = 0;
|
||||||
|
private readonly MAX_RKEY_FAILURES: number = 8;
|
||||||
|
|
||||||
constructor(context: InstanceContext, core: NapCatCore) {
|
constructor(context: InstanceContext, core: NapCatCore) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
@@ -45,6 +47,22 @@ export class NTQQFileApi {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async fetchRkeyWithRetry() {
|
||||||
|
if (this.fetchRkeyFailures >= this.MAX_RKEY_FAILURES) {
|
||||||
|
throw new Error('Native.FetchRkey 已被禁用');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
let ret = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
||||||
|
this.fetchRkeyFailures = 0; // Reset failures on success
|
||||||
|
return ret;
|
||||||
|
} catch (error) {
|
||||||
|
this.fetchRkeyFailures++;
|
||||||
|
this.context.logger.logError('FetchRkey 失败', (error as Error).message);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async copyFile(filePath: string, destPath: string) {
|
async copyFile(filePath: string, destPath: string) {
|
||||||
await this.core.util.copyFile(filePath, destPath);
|
await this.core.util.copyFile(filePath, destPath);
|
||||||
}
|
}
|
||||||
@@ -182,7 +200,6 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
context.deleteAfterSentFiles.push(thumbPath);
|
context.deleteAfterSentFiles.push(thumbPath);
|
||||||
|
|
||||||
const thumbSize = (await fsPromises.stat(thumbPath)).size;
|
const thumbSize = (await fsPromises.stat(thumbPath)).size;
|
||||||
const thumbMd5 = await calculateFileMD5(thumbPath);
|
const thumbMd5 = await calculateFileMD5(thumbPath);
|
||||||
context.deleteAfterSentFiles.push(thumbPath);
|
context.deleteAfterSentFiles.push(thumbPath);
|
||||||
@@ -421,7 +438,7 @@ export class NTQQFileApi {
|
|||||||
const rkey_expired_private = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000;
|
const rkey_expired_private = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000;
|
||||||
const rkey_expired_group = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000;
|
const rkey_expired_group = !this.packetRkey || this.packetRkey[0].time + Number(this.packetRkey[0].ttl) < Date.now() / 1000;
|
||||||
if (rkey_expired_private || rkey_expired_group) {
|
if (rkey_expired_private || rkey_expired_group) {
|
||||||
this.packetRkey = await this.core.apis.PacketApi.pkt.operation.FetchRkey();
|
this.packetRkey = await this.fetchRkeyWithRetry();
|
||||||
}
|
}
|
||||||
if (this.packetRkey && this.packetRkey.length > 0) {
|
if (this.packetRkey && this.packetRkey.length > 0) {
|
||||||
rkeyData.group_rkey = this.packetRkey[1]?.rkey.slice(6) ?? '';
|
rkeyData.group_rkey = this.packetRkey[1]?.rkey.slice(6) ?? '';
|
||||||
@@ -430,7 +447,7 @@ export class NTQQFileApi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
this.context.logger.logError('获取rkey失败', (error as Error).message);
|
this.context.logger.logDebug('获取native.rkey失败', (error as Error).message);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rkeyData.online_rkey) {
|
if (!rkeyData.online_rkey) {
|
||||||
@@ -439,11 +456,11 @@ export class NTQQFileApi {
|
|||||||
rkeyData.group_rkey = tempRkeyData.group_rkey;
|
rkeyData.group_rkey = tempRkeyData.group_rkey;
|
||||||
rkeyData.private_rkey = tempRkeyData.private_rkey;
|
rkeyData.private_rkey = tempRkeyData.private_rkey;
|
||||||
rkeyData.online_rkey = tempRkeyData.expired_time > Date.now() / 1000;
|
rkeyData.online_rkey = tempRkeyData.expired_time > Date.now() / 1000;
|
||||||
} catch (e) {
|
} catch (error: unknown) {
|
||||||
this.context.logger.logDebug('获取rkey失败 Fallback Old Mode', e);
|
this.context.logger.logDebug('获取remote.rkey失败', (error as Error).message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// 进行 fallback.rkey 模式
|
||||||
return rkeyData;
|
return rkeyData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,7 +22,6 @@ import { OB11GroupEssenceEvent } from '@/onebot/event/notice/OB11GroupEssenceEve
|
|||||||
import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent';
|
import { OB11GroupTitleEvent } from '@/onebot/event/notice/OB11GroupTitleEvent';
|
||||||
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
import { OB11GroupUploadNoticeEvent } from '../event/notice/OB11GroupUploadNoticeEvent';
|
||||||
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
import { OB11GroupNameEvent } from '../event/notice/OB11GroupNameEvent';
|
||||||
import { pathToFileURL } from 'node:url';
|
|
||||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
import { OB11GroupIncreaseEvent } from '../event/notice/OB11GroupIncreaseEvent';
|
||||||
|
|
||||||
@@ -202,8 +201,7 @@ export class OneBotGroupApi {
|
|||||||
id: FileNapCatOneBotUUID.encode({
|
id: FileNapCatOneBotUUID.encode({
|
||||||
chatType: ChatType.KCHATTYPEGROUP,
|
chatType: ChatType.KCHATTYPEGROUP,
|
||||||
peerUid: msg.peerUid,
|
peerUid: msg.peerUid,
|
||||||
}, msg.msgId, elementWrapper.elementId, elementWrapper?.fileElement?.fileUuid, element.fileName),
|
}, msg.msgId, elementWrapper.elementId, elementWrapper?.fileElement?.fileUuid, element.fileMd5 ?? element.fileUuid),
|
||||||
url: pathToFileURL(element.filePath).href,
|
|
||||||
name: element.fileName,
|
name: element.fileName,
|
||||||
size: parseInt(element.fileSize),
|
size: parseInt(element.fileSize),
|
||||||
busid: element.fileBizId ?? 0,
|
busid: element.fileBizId ?? 0,
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
import { FileNapCatOneBotUUID } from '@/common/file-uuid';
|
||||||
import { MessageUnique } from '@/common/message-unique';
|
import { MessageUnique } from '@/common/message-unique';
|
||||||
import { pathToFileURL } from 'node:url';
|
|
||||||
import {
|
import {
|
||||||
NTMsgAtType,
|
NTMsgAtType,
|
||||||
ChatType,
|
ChatType,
|
||||||
@@ -146,7 +145,6 @@ export class OneBotMsgApi {
|
|||||||
data: {
|
data: {
|
||||||
file: file,
|
file: file,
|
||||||
path: element.filePath,
|
path: element.filePath,
|
||||||
url: pathToFileURL(element.filePath).href,
|
|
||||||
file_id: file,
|
file_id: file,
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
},
|
},
|
||||||
@@ -334,7 +332,7 @@ export class OneBotMsgApi {
|
|||||||
data: {
|
data: {
|
||||||
file: fileCode,
|
file: fileCode,
|
||||||
path: videoDownUrl,
|
path: videoDownUrl,
|
||||||
url: videoDownUrl ?? pathToFileURL(element.filePath).href,
|
url: videoDownUrl,
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@@ -352,7 +350,6 @@ export class OneBotMsgApi {
|
|||||||
data: {
|
data: {
|
||||||
file: fileCode,
|
file: fileCode,
|
||||||
path: element.filePath,
|
path: element.filePath,
|
||||||
url: pathToFileURL(element.filePath).href,
|
|
||||||
file_size: element.fileSize,
|
file_size: element.fileSize,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@@ -6,7 +6,6 @@ export interface GroupUploadFile {
|
|||||||
name: string,
|
name: string,
|
||||||
size: number,
|
size: number,
|
||||||
busid: number,
|
busid: number,
|
||||||
url:string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
|
export class OB11GroupUploadNoticeEvent extends OB11GroupNoticeEvent {
|
||||||
|
Reference in New Issue
Block a user