Normalize imports, typings and formatting

Reorder and normalize imports, add missing type imports, and fix whitespace/formatting across multiple files. Notable updates: eslint.config.ts import ordering; core bridge APIs (group-album, misc, web) now import Json types; tests/highway pipeline import ordering and added type imports; protocol changes (element-builder, highway client/pipeline) reorganized imports and added proto type imports; many oidb service modules moved protobuf encode/decode imports for consistency; web group modules (album, essence, honor, notice, request-util) reordered imports, adjusted typings/indentation, and small whitespace fixes. These edits are stylistic and typing improvements and should not change runtime behavior.
This commit is contained in:
手瓜一十雪 committed 2026-05-24 13:39:35 +08:00
1 parent 80ee12ecc2
commit 456086599c
23 files changed
+83 -83

No files matched your search

+3 -3
View File
@@ -1,9 +1,9 @@
import js from '@eslint/js';
import globals from 'globals';
import reactHooks from 'eslint-plugin-react-hooks';
import reactRefresh from 'eslint-plugin-react-refresh';
import tseslint from 'typescript-eslint';
import { defineConfig, globalIgnores } from 'eslint/config';
import globals from 'globals';
import tseslint from 'typescript-eslint';
const tsconfigRootDir = decodeURIComponent(new URL('.', import.meta.url).pathname).replace(/^\/(.:\/)/, '$1');
@@ -102,4 +102,4 @@ export default defineConfig([
'react-hooks/set-state-in-effect': 'off',
},
},
]);
]);
+2 -2
View File
@@ -1,3 +1,4 @@
import type { JsonObject, JsonValue } from '@snowluma/common/json';
import type {
DeleteMediasRequest,
DeleteMediasResponse,
@@ -6,12 +7,11 @@ import type {
DoQunLikeRequest,
DoQunLikeResponse,
GetMediaListRequest,
MediaInfo,
GetMediaListResponse,
MediaInfo,
} from '@snowluma/proto-defs/oidb-actions/group-album';
import { getGroupAlbumList, uploadImageToGroupAlbum } from '@snowluma/protocol/web/group-album';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { JsonObject, JsonValue } from '@snowluma/common/json';
import type { BridgeContext } from '../bridge-context';
+1 -1
View File
@@ -1,9 +1,9 @@
import type { JsonObject, JsonValue } from '@snowluma/common/json';
import type {
MiniAppShareReq,
MiniAppShareResp,
} from '@snowluma/proto-defs/oidb-actions/base';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { JsonObject, JsonValue } from '@snowluma/common/json';
import type { BridgeContext } from '../bridge-context';
// Migrated OIDB cmds — facade methods are one-line forwarders.
import { ClickInlineKeyboardButton } from '@snowluma/protocol/oidb-services/misc/click-inline-keyboard-button';
+1 -1
View File
@@ -6,8 +6,8 @@ import {
deleteGroupNotice as deleteGroupNoticeHttp,
getGroupNoticeWebAPI,
setGroupNoticeWebAPI,
type SetNoticeRetSuccess,
uploadGroupNoticeImage,
type SetNoticeRetSuccess,
} from '@snowluma/protocol/web/group-notice';
import { RequestUtil } from '@snowluma/protocol/web/request-util';
import type { Bridge } from '../bridge';
+3 -3
View File
@@ -5,8 +5,8 @@
// The OIDB response is built with real protobuf encoding so we exercise
// the actual decode path inside the pipeline.
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { beforeEach, describe, expect, it, vi } from 'vitest';
vi.mock('@snowluma/protocol/highway', () => ({
fetchHighwaySession: vi.fn(async () => ({ sessionId: 'fake-session' })),
@@ -16,6 +16,8 @@ vi.mock('@snowluma/protocol/highway', () => ({
GROUP_IMAGE_CMD_ID: 1004,
}));
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import * as highway from '@snowluma/protocol/highway';
import {
finalizeMediaMsgInfo,
@@ -24,8 +26,6 @@ import {
runNtv2Upload,
type MediaSubFileUpload,
} from '@snowluma/protocol/highway/pipeline';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { EncodableMediaMsgInfo, NTV2UploadRichMediaReq, NTV2UploadRichMediaResp } from '@snowluma/proto-defs/highway';
interface FakeUploadResponse {
upload?: {
+6 -6
View File
@@ -1,17 +1,17 @@
import type {
MarkdownData,
MentionExtraSend,
} from '@snowluma/proto-defs/action';
import type { Elem, GroupFileExtra } from '@snowluma/proto-defs/element';
import { protobuf_encode } from '@snowluma/proton';
import { deflateSync } from 'zlib';
import { randomUUID } from 'crypto';
import { deflateSync } from 'zlib';
import type { BridgeContext } from './bridge-context';
import type { MessageElement } from './events';
import { uploadImageMsgInfo } from './highway/image-upload';
import { hexToBytes } from './highway/pipeline';
import { uploadPttMsgInfo } from './highway/ptt-upload';
import { uploadVideoMsgInfo } from './highway/video-upload';
import type {
MarkdownData,
MentionExtraSend,
} from '@snowluma/proto-defs/action';
import type { Elem, GroupFileExtra } from '@snowluma/proto-defs/element';
type ProtoElem = Partial<Elem>;
@@ -1,16 +1,16 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import net from 'net';
import type { BridgeContext } from '../bridge-context';
import type {
HighwayMsgInfoBody,
HttpConn0x6FF501Request,
HttpConn0x6FF501Response,
HighwayMsgInfoBody,
NTV2IPv4,
NTV2RichMediaHighwayExt,
NTV2UploadRespMsgInfo,
ReqDataHighwayHead,
RespDataHighwayHead,
} from '@snowluma/proto-defs/highway';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import net from 'net';
import type { BridgeContext } from '../bridge-context';
import { computeMd5, packHighwayFrame, unpackHighwayFrame } from './utils';
const HIGHWAY_APP_ID = 1600001604;
+5 -5
View File
@@ -1,18 +1,18 @@
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import crypto from 'crypto';
import { createLogger } from '@snowluma/common/logger';
import type { BridgeContext } from '../bridge-context';
import { makeOidbEnvelope } from '../bridge-oidb';
import type {
EncodableMediaMsgInfo,
HighwayMsgInfoBody,
NTV2ExtBizInfo,
NTV2UploadInfo,
NTV2UploadRespBody,
NTV2UploadRichMediaReq,
NTV2UploadRichMediaResp,
NTV2UploadRespBody,
} from '@snowluma/proto-defs/highway';
import { OidbBase } from '@snowluma/proto-defs/oidb';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import crypto from 'crypto';
import type { BridgeContext } from '../bridge-context';
import { makeOidbEnvelope } from '../bridge-oidb';
import { buildHighwayExtend, fetchHighwaySession, uploadHighwayHttp } from './highway-client';
const moduleLog = createLogger('Highway');
@@ -5,9 +5,9 @@
// while-loop until the server stops emitting a next cursor and
// concatenates results into the public FriendInfo[] shape.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbSvcTrpcTcp0xFD4_1Response } from '@snowluma/proto-defs/oidb';
import type { OidbFriendListRequest } from '@snowluma/proto-defs/oidb-actions/base';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace FetchFriendListPage {
@@ -6,9 +6,9 @@
// state that's per-Bridge (and is what stops Tencent risk-control
// from banning the account on busy clients — see #42).
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase, OidbSvcTrpcTcp0xFE7_3Response } from '@snowluma/proto-defs/oidb';
import type { OidbGroupMemberListRequest } from '@snowluma/proto-defs/oidb-actions/base';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export namespace FetchGroupMemberListPage {
@@ -12,9 +12,9 @@
// — the facade swallows the namespace-level exception and surfaces
// `null` so callers get a clean retcode.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { OidbStrangerStatusReq, OidbStrangerStatusResp } from '@snowluma/proto-defs/oidb-actions/base';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface StrangerStatus {
@@ -3,9 +3,9 @@
// means group). Pairs with the c2c-scope variant `GetPrivatePttUrl`
// (0x126D_200) which only differs in scene.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import {
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
@@ -2,9 +2,9 @@
// GetGroupPttUrl; `requestType=2 + businessType=2` swaps voice for
// video. The scene's `group` block carries the group uin.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import {
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
@@ -2,9 +2,9 @@
// `scene` is `c2c` rather than `group`. Needs the bot's own uid to
// fill the c2c.targetUid slot.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import {
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
@@ -2,9 +2,9 @@
// `scene.c2c.targetUid` is the bot's own uid; the server uses it as
// the read-side identity for the asset lookup.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { NTV2RichMediaReq, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import {
normalizeMediaNode, parseNtv2DownloadUrl, type NtMediaIndex,
@@ -2,9 +2,9 @@
// owning the button (so the bot can react). All identity fields go on
// the wire as uint_64 → callers pass JS numbers and we widen here.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x112eReq, Oidb0x112eResp } from '@snowluma/proto-defs/oidb-actions/base';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface InlineButtonClickResult {
@@ -3,11 +3,11 @@
// Self lookup needs the bot's own UID, hence the `identity` dependency.
// For other users we use `resolveUserUid` to translate the uin first.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0x7edReq, Oidb0x7edResp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { BridgeContext } from '../../bridge-context';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface LikeInfo {
[key: string]: import('@snowluma/common/json').JsonValue;
@@ -7,11 +7,11 @@
// protobuf field, so the namespace's `serialize` / `deserialize` do
// the JSON marshalling.
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { OidbBase } from '@snowluma/proto-defs/oidb';
import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-actions/base';
import { invokeOidb, type OidbSender } from '../../oidb-service';
import { protobuf_decode, protobuf_encode } from '@snowluma/proton';
import type { BridgeContext } from '../../bridge-context';
import { invokeOidb, type OidbSender } from '../../oidb-service';
export interface UnidirectionalFriendEntry {
[key: string]: import('@snowluma/common/json').JsonValue;
@@ -25,7 +25,7 @@ export namespace GetUnidirectionalFriendList {
* `OidbSvcTrpcTcp.0xNNNN_N` namespace. */
export const wireName = (): string => 'MQUpdateSvc_com_qq_ti.web.OidbSvc.0xe17_0';
export interface Params {}
export interface Params { }
export type Deps = OidbSender & Pick<BridgeContext, 'identity'>;
+5 -5
View File
@@ -1,9 +1,9 @@
import { RequestUtil, cookieToString, getBknFromCookie } from './request-util';
import { createHash } from 'crypto';
import { statSync, createReadStream, writeFileSync, unlinkSync } from 'fs';
import { basename, join } from 'path';
import { tmpdir } from 'os';
import type { JsonValue } from '@snowluma/common/json';
import { createHash } from 'crypto';
import { createReadStream, statSync, unlinkSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { basename, join } from 'path';
import { RequestUtil, cookieToString, getBknFromCookie } from './request-util';
// 群相册信息
export interface GroupAlbumInfo {
+7 -7
View File
@@ -1,17 +1,17 @@
import { RequestUtil, cookieToString, getBknFromCookie } from './request-util';
import { createLogger } from '@snowluma/common/logger';
import type { JsonObject } from '@snowluma/common/json';
import { createLogger } from '@snowluma/common/logger';
import { RequestUtil, cookieToString, getBknFromCookie } from './request-util';
const log = createLogger('Bridge.Web');
// 定义接口返回类型
export interface GroupEssenceMsgRet {
retcode: number;
data: {
is_end: boolean;
retcode: number;
data: {
is_end: boolean;
msg_list: JsonObject[]; // 具体结构视需要补充
[key: string]: JsonObject[] | boolean | string | number | null;
};
};
[key: string]: JsonObject | JsonObject[] | boolean | string | number | null;
}
@@ -69,4 +69,4 @@ export async function getGroupEssenceMsgAll(
}
return ret;
}
}
+7 -7
View File
@@ -1,5 +1,5 @@
import { RequestUtil, cookieToString } from './request-util';
import { createLogger } from '@snowluma/common/logger';
import { RequestUtil, cookieToString } from './request-util';
const log = createLogger('Bridge.Web');
@@ -24,11 +24,11 @@ interface HonorInitialState {
}
export enum WebHonorType {
TALKATIVE = 'talkative',
PERFORMER = 'performer',
LEGEND = 'legend',
EMOTION = 'emotion',
ALL = 'all',
TALKATIVE = 'talkative',
PERFORMER = 'performer',
LEGEND = 'legend',
EMOTION = 'emotion',
ALL = 'all',
}
@@ -70,4 +70,4 @@ export async function getHonorListWebAPI(cookieObject: Record<string, string>, g
groupCode, type, e instanceof Error ? (e.stack ?? e.message) : String(e));
return [];
}
}
}
+23 -23
View File
@@ -1,40 +1,40 @@
import { RequestUtil, cookieToString } from './request-util';
import https from 'node:https';
import { createLogger } from '@snowluma/common/logger';
import type { JsonValue } from '@snowluma/common/json';
import { createLogger } from '@snowluma/common/logger';
import https from 'node:https';
import { RequestUtil, cookieToString } from './request-util';
const log = createLogger('Bridge.Web');
export interface SetNoticeRetSuccess {
ec?: number;
em?: string;
ec?: number;
em?: string;
[key: string]: JsonValue | undefined;
}
export interface UploadImageRetSuccess {
ec?: number;
id?: string;
ec?: number;
id?: string;
[key: string]: JsonValue | undefined;
}
export interface WebApiGroupNoticeFeed {
fid: string;
u: number;
pubt: number;
msg: {
text: string;
pics?: Array<{ id: string; w: number; h: number }>;
};
settings: JsonValue;
read_num: number;
[key: string]: JsonValue;
fid: string;
u: number;
pubt: number;
msg: {
text: string;
pics?: Array<{ id: string; w: number; h: number }>;
};
settings: JsonValue;
read_num: number;
[key: string]: JsonValue;
}
export interface WebApiGroupNoticeRet {
ec: number;
em?: string;
feeds?: Record<string, WebApiGroupNoticeFeed>;
[key: string]: JsonValue | Record<string, WebApiGroupNoticeFeed> | undefined;
ec: number;
em?: string;
feeds?: Record<string, WebApiGroupNoticeFeed>;
[key: string]: JsonValue | Record<string, WebApiGroupNoticeFeed> | undefined;
}
export function calculateBkn(key: string): string {
@@ -174,7 +174,7 @@ export async function uploadGroupNoticeImage(
imageBuffer: Buffer
): Promise<{ id: string; width: number; height: number } | undefined> {
try {
const bkn = calculateBkn(cookieObject['skey']);
const bkn = calculateBkn(cookieObject['skey']);
const boundary = `-----------------------------${Date.now()}`;
const parts: Buffer[] = [];
@@ -271,4 +271,4 @@ export async function deleteGroupNotice(
log.warn('deleteGroupNotice failed (group=%s fid=%s): %s', groupCode, fid, e instanceof Error ? (e.stack ?? e.message) : String(e));
return false;
}
}
}
+3 -3
View File
@@ -1,5 +1,5 @@
import https from 'node:https';
import http from 'node:http';
import https from 'node:https';
type RequestBody = string | Buffer | Uint8Array | Record<string, unknown> | undefined;
@@ -53,8 +53,8 @@ export class RequestUtil {
}
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: RequestBody, headers: {
[key: string]: string;
} = {}, isJsonRet: boolean = true, isArgJson: boolean = true, maxRedirects: number = 5): Promise<T> {
[key: string]: string;
} = {}, isJsonRet: boolean = true, isArgJson: boolean = true, maxRedirects: number = 5): Promise<T> {
const option = new URL(url);
const protocol = url.startsWith('https://') ? https : http;
const options = {