Merge upstream/dev into feat/onebot

This commit is contained in:
H3CoF6 committed 2026-05-19 02:40:14 +08:00
commit 0d40a03f28
122 files changed
+7842 -1099

No files matched your search

@@ -66,6 +66,9 @@ export async function getStrangerStatus(bridge: Bridge, uin: number): Promise<St
request: {
schema: OidbStrangerStatusReqSchema,
value: { uin, key: [{ key: 27372 }] },
// Same UIN-form flag fetchUserProfile sets — without it newer
// QQ NT rejects with `[oidb] one of uid/openid is invaild`.
isUid: true,
},
response: { schema: OidbStrangerStatusRespSchema },
});
+34 -3
View File
@@ -28,12 +28,23 @@ const forwardResCache = new Map<string, ForwardNodePayload[]>();
async function buildForwardPushBody(
bridge: Bridge,
node: ForwardNodePayload,
groupId?: number,
userUid?: string,
): Promise<Record<string, unknown>> {
const fromUin = node.userUin > 0 ? node.userUin : toInt(bridge.identity.uin);
if (fromUin <= 0) throw new Error('forward node user uin is invalid');
const nickname = node.nickname.trim() || String(fromUin);
const elems = await buildSendElems(node.elements);
// image/record/video upload inside a forward node must be scoped to the
// forward's recipient: group → groupId, private → recipient uid.
// Without this the OIDB upload (0x11c4/0x11c5) has no scene and the
// element builder throws "private image target uid is missing".
const sendCtx = groupId !== undefined
? { bridge, groupId }
: userUid
? { bridge, userUid }
: { bridge };
const elems = await buildSendElems(node.elements, sendCtx);
const now = Math.floor(Date.now() / 1000);
const random = Math.floor(Math.random() * 0x7fffffff) >>> 0;
const seq = Math.floor(Math.random() * 9000000) + 1000000;
@@ -62,12 +73,32 @@ async function buildForwardPushBody(
};
}
export async function uploadForwardNodes(bridge: Bridge, nodes: ForwardNodePayload[], groupId?: number): Promise<string> {
export async function uploadForwardNodes(
bridge: Bridge,
nodes: ForwardNodePayload[],
groupId?: number,
userId?: number,
): Promise<string> {
if (!Array.isArray(nodes) || nodes.length === 0) {
throw new Error('forward nodes are required');
}
const msgBody = await Promise.all(nodes.map(node => buildForwardPushBody(bridge, node)));
// For a private forward to `userId`, any image/record/video inside a node
// needs the recipient's uid as upload scene. Resolve it once up-front,
// and only when at least one node actually contains media (saves an RPC
// for text-only forwards).
let userUid: string | undefined;
if (groupId === undefined && userId !== undefined && userId > 0) {
const hasMedia = nodes.some(node => node.elements.some(
e => e.type === 'image' || e.type === 'record' || e.type === 'video',
));
if (hasMedia) {
const resolved = await bridge.resolveUserUid(userId);
if (resolved) userUid = resolved;
}
}
const msgBody = await Promise.all(nodes.map(node => buildForwardPushBody(bridge, node, groupId, userUid)));
const longMsgResult = protoEncode({
action: [
{
@@ -9,7 +9,7 @@ import type { Bridge } from '../bridge';
import { protoEncode } from '../../protobuf/decode';
import { runOidb } from '../bridge-oidb';
import { fetchHighwaySession, uploadHighwayHttp } from '../highway/highway-client';
import { computeHashes, computeMd5, loadBinarySource } from '../highway/utils';
import { computeHashes, computeMd5, FILE_UPLOAD_MAX_BYTES, loadBinarySource } from '../highway/utils';
import {
OidbGroupFileCountViewReqSchema,
OidbGroupFileCountViewRespSchema,
@@ -288,7 +288,9 @@ export async function uploadGroupFile(
folderId = '/',
uploadFile = true,
): Promise<UploadFileResult> {
const loaded = await loadBinarySource(source, 'file');
// Group/private files may legitimately be up to 4 GiB on QQ's wire,
// so override the default 1 GiB cap with the protocol ceiling.
const loaded = await loadBinarySource(source, 'file', FILE_UPLOAD_MAX_BYTES);
if (!loaded.bytes.length) throw new Error('group file is empty');
const fileName = normalizeUploadFileName(name, loaded.fileName);
@@ -366,7 +368,9 @@ export async function uploadPrivateFile(
name = '',
uploadFile = true,
): Promise<UploadFileResult> {
const loaded = await loadBinarySource(source, 'file');
// Group/private files may legitimately be up to 4 GiB on QQ's wire,
// so override the default 1 GiB cap with the protocol ceiling.
const loaded = await loadBinarySource(source, 'file', FILE_UPLOAD_MAX_BYTES);
if (!loaded.bytes.length) throw new Error('private file is empty');
const targetUid = await bridge.resolveUserUid(userId);