Enforce no-explicit-any; allow in tests
Enable @typescript-eslint/no-explicit-any as an error in the ESLint config to tighten typing across the codebase, and add an override to disable this rule for test files. Also apply non-functional cleanup in packages/proton/src/runtime.ts: reorder/imports and adjust formatting/indentation and string alignment for readability — no behavioral changes.
This commit is contained in:
1 parent
acc5084647
commit
80ee12ecc2
36 files changed
+229
-147
No files matched your search
@@ -35,13 +35,13 @@ export interface SendContext {
|
||||
|
||||
function makeTextElem(text: string): ProtoElem {
|
||||
return {
|
||||
text: { str: text } as any,
|
||||
text: { str: text },
|
||||
};
|
||||
}
|
||||
|
||||
function makeFaceElem(faceId: number): ProtoElem {
|
||||
return {
|
||||
face: { index: faceId } as any,
|
||||
face: { index: faceId },
|
||||
};
|
||||
}
|
||||
|
||||
@@ -83,14 +83,14 @@ function makeMentionElem(element: MessageElement, ctx?: SendContext): ProtoElem
|
||||
text: {
|
||||
str,
|
||||
pbReserve: extra,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function makeReplyElem(element: MessageElement): ProtoElem {
|
||||
const seq = element.replySeq! & 0xFFFFFFFF;
|
||||
|
||||
const srcMsg: any = {
|
||||
const srcMsg: NonNullable<Elem['srcMsg']> = {
|
||||
origSeqs: [seq],
|
||||
};
|
||||
|
||||
@@ -116,7 +116,7 @@ function makeJsonElem(element: MessageElement): ProtoElem {
|
||||
richMsg: {
|
||||
serviceId: 1,
|
||||
template1: payload,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ function makeXmlElem(element: MessageElement): ProtoElem {
|
||||
richMsg: {
|
||||
serviceId: element.subType === 0 ? 35 : (element.subType ?? 35),
|
||||
template1: payload,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ function makeMarkdownElem(element: MessageElement): ProtoElem {
|
||||
serviceType: 45,
|
||||
pbElem: data,
|
||||
businessType: 1,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ function makeForwardElem(element: MessageElement): ProtoElem {
|
||||
return {
|
||||
lightApp: {
|
||||
data: payload,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ async function makeImageElem(ctx: SendContext, element: MessageElement): Promise
|
||||
serviceType: 48,
|
||||
pbElem: msgInfo,
|
||||
businessType: isGroup ? 20 : 10,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -255,7 +255,7 @@ async function makePttElem(ctx: SendContext, element: MessageElement): Promise<P
|
||||
serviceType: 48,
|
||||
pbElem: msgInfo,
|
||||
businessType: isGroup ? 22 : 12,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -324,7 +324,7 @@ function makeGroupFileElem(element: MessageElement, ctx?: SendContext): ProtoEle
|
||||
transElem: {
|
||||
elemType: 24,
|
||||
elemValue,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -345,7 +345,7 @@ async function makeVideoElem(ctx: SendContext, element: MessageElement): Promise
|
||||
serviceType: 48,
|
||||
pbElem: msgInfo,
|
||||
businessType: isGroup ? 21 : 11,
|
||||
} as any,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,10 @@ import type { BridgeContext } from '../bridge-context';
|
||||
import type {
|
||||
HttpConn0x6FF501Request,
|
||||
HttpConn0x6FF501Response,
|
||||
HighwayMsgInfoBody,
|
||||
NTV2IPv4,
|
||||
NTV2RichMediaHighwayExt,
|
||||
NTV2UploadRespMsgInfo,
|
||||
ReqDataHighwayHead,
|
||||
RespDataHighwayHead,
|
||||
} from '@snowluma/proto-defs/highway';
|
||||
@@ -91,8 +94,8 @@ function makeHighwayHead(
|
||||
|
||||
export function buildHighwayExtend(
|
||||
uKey: string,
|
||||
msgInfo: any,
|
||||
ipv4s: any[],
|
||||
msgInfo: NTV2UploadRespMsgInfo,
|
||||
ipv4s: NTV2IPv4[],
|
||||
sha1: Uint8Array | Uint8Array[],
|
||||
fileIndex = 0,
|
||||
): Uint8Array {
|
||||
@@ -100,7 +103,7 @@ export function buildHighwayExtend(
|
||||
if (msgInfoBody.length === 0) throw new Error('upload response missing msg_info body');
|
||||
|
||||
const selected = msgInfoBody[fileIndex] ?? msgInfoBody[0];
|
||||
const networkIpv4s: any[] = [];
|
||||
const networkIpv4s: NonNullable<NonNullable<NTV2RichMediaHighwayExt['network']>['ipv4s']> = [];
|
||||
for (const ipv4 of ipv4s ?? []) {
|
||||
const ip = ipv4.outIp ?? 0;
|
||||
const port = ipv4.outPort ?? 0;
|
||||
@@ -113,7 +116,7 @@ export function buildHighwayExtend(
|
||||
fileUuid: selected?.index?.fileUuid ?? '',
|
||||
uKey,
|
||||
network: { ipv4s: networkIpv4s },
|
||||
msgInfoBody: msgInfoBody.map((b: any) => ({
|
||||
msgInfoBody: msgInfoBody.map((b: HighwayMsgInfoBody) => ({
|
||||
index: b.index, picture: b.picture, fileExist: b.fileExist, hashSum: b.hashSum,
|
||||
})),
|
||||
blockSize: HIGHWAY_BLOCK_SIZE,
|
||||
|
||||
@@ -5,8 +5,12 @@ import type { BridgeContext } from '../bridge-context';
|
||||
import { makeOidbEnvelope } from '../bridge-oidb';
|
||||
import type {
|
||||
EncodableMediaMsgInfo,
|
||||
HighwayMsgInfoBody,
|
||||
NTV2ExtBizInfo,
|
||||
NTV2UploadInfo,
|
||||
NTV2UploadRichMediaReq,
|
||||
NTV2UploadRichMediaResp,
|
||||
NTV2UploadRespBody,
|
||||
} from '@snowluma/proto-defs/highway';
|
||||
import { OidbBase } from '@snowluma/proto-defs/oidb';
|
||||
import { buildHighwayExtend, fetchHighwaySession, uploadHighwayHttp } from './highway-client';
|
||||
@@ -64,11 +68,11 @@ export interface NtV2UploadParams {
|
||||
/** `reqHead.scene.businessType` (1=image, 3=voice, 2=video). */
|
||||
businessType: number;
|
||||
/** `upload.uploadInfo` array. Each entry is `{ fileInfo, subFileType }`. */
|
||||
uploadInfo: unknown[];
|
||||
uploadInfo: NTV2UploadInfo[];
|
||||
/** `upload.compatQmsgSceneType`. */
|
||||
compatQmsgSceneType: number;
|
||||
/** `upload.extBizInfo` — type-specific bytes/flags. */
|
||||
extBizInfo: unknown;
|
||||
extBizInfo: NTV2ExtBizInfo;
|
||||
/** Sub-file Highway PUTs to perform after the OIDB response. */
|
||||
uploads: MediaSubFileUpload[];
|
||||
/** Used in error messages. Defaults to 'media'. */
|
||||
@@ -107,7 +111,7 @@ export function hexToBytes(hex: string): Uint8Array {
|
||||
* Sessions are cached across sub-file uploads — video does two PUTs but
|
||||
* only fetches the Highway session once.
|
||||
*/
|
||||
export async function runNtv2Upload(params: NtV2UploadParams): Promise<any> {
|
||||
export async function runNtv2Upload(params: NtV2UploadParams): Promise<NTV2UploadRespBody> {
|
||||
const { bridge, isGroup, targetIdOrUid, oidbCmd, serviceCmd, uploads } = params;
|
||||
const label = params.label ?? 'media';
|
||||
const raw = bridge.identity?.uin;
|
||||
@@ -118,7 +122,7 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<any> {
|
||||
|
||||
// Build the full body once. Pulling this in here means each format file
|
||||
// only specifies the seven fields that actually vary.
|
||||
const body: any = {
|
||||
const body: NTV2UploadRichMediaReq = {
|
||||
reqHead: {
|
||||
common: { requestId: params.requestId, command: 100 },
|
||||
scene: {
|
||||
@@ -157,7 +161,7 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<any> {
|
||||
throw new Error(`OIDB error ${resp.errorCode}: ${resp.errorMsg ?? ''}`);
|
||||
}
|
||||
|
||||
const uploadBody: any = resp.body;
|
||||
const uploadBody = resp.body;
|
||||
if (!uploadBody) throw new Error(`${label} upload response body missing`);
|
||||
if (uploadBody.respHead?.retCode && uploadBody.respHead.retCode !== 0) {
|
||||
throw new Error(uploadBody.respHead.message ?? `${label} upload failed`);
|
||||
@@ -186,11 +190,13 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<any> {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!target) continue;
|
||||
|
||||
const extend = buildHighwayExtend(
|
||||
uKey,
|
||||
upload.msgInfo,
|
||||
target.ipv4s ?? [],
|
||||
sub.sha1 as any, // sha1 may be Uint8Array | Uint8Array[]; the helper accepts both
|
||||
sub.sha1,
|
||||
sub.subFileIndex ?? 0,
|
||||
);
|
||||
log.debug('%s OIDB requires bytes, PUT %d bytes (sub=%s)', label, sub.bytes.length, String(sub.source));
|
||||
@@ -218,16 +224,16 @@ export async function runNtv2Upload(params: NtV2UploadParams): Promise<any> {
|
||||
* pic alone unless the server populates it.
|
||||
*/
|
||||
export function finalizeMediaMsgInfo(
|
||||
upload: any,
|
||||
upload: NTV2UploadRespBody,
|
||||
defaultPic?: { bizType: number; textSummary: string },
|
||||
): Uint8Array {
|
||||
if (!upload?.msgInfo) throw new Error('upload response missing msgInfo');
|
||||
|
||||
const msgInfoBody = (upload.msgInfo.msgInfoBody ?? []).map((b: any) => ({
|
||||
const msgInfoBody = (upload.msgInfo.msgInfoBody ?? []).map((b: HighwayMsgInfoBody) => ({
|
||||
index: b.index, picture: b.picture, fileExist: b.fileExist, hashSum: b.hashSum,
|
||||
}));
|
||||
|
||||
const extBizInfo: any = {};
|
||||
const extBizInfo: NonNullable<EncodableMediaMsgInfo['extBizInfo']> = {};
|
||||
if (upload.msgInfo.extBizInfo?.pic) {
|
||||
extBizInfo.pic = { ...upload.msgInfo.extBizInfo.pic };
|
||||
if (defaultPic) {
|
||||
|
||||
@@ -23,7 +23,7 @@ export namespace FetchFriendListPage {
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbFriendListRequest => {
|
||||
const body: any = {
|
||||
const body: OidbFriendListRequest = {
|
||||
friendCount: 300,
|
||||
field4: 0,
|
||||
field6: 1,
|
||||
|
||||
@@ -25,7 +25,7 @@ export namespace FetchGroupMemberListPage {
|
||||
export type Deps = OidbSender;
|
||||
|
||||
export const serialize = (_ctx: Deps, p: Params): OidbGroupMemberListRequest => {
|
||||
const body: any = {
|
||||
const body: OidbGroupMemberListRequest = {
|
||||
groupUin: p.groupId,
|
||||
field2: 5,
|
||||
field3: 2,
|
||||
|
||||
@@ -41,7 +41,7 @@ export namespace GetStrangerStatus {
|
||||
export const deserialize = (_ctx: Deps, body: OidbStrangerStatusResp): StrangerStatus | null => {
|
||||
const raw = body.data?.status?.value;
|
||||
if (raw === undefined || raw === null) return null;
|
||||
const extBig = typeof raw === 'bigint' ? raw : BigInt(raw as any);
|
||||
const extBig = typeof raw === 'bigint' ? raw : BigInt(raw);
|
||||
if (extBig <= 10n) {
|
||||
return { status: Number(extBig) * 10, ext_status: 0 };
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ export namespace GetGroupPttUrl {
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
node: normalizeMediaNode(p.node),
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ export namespace GetGroupVideoUrl {
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
node: normalizeMediaNode(p.node),
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ export namespace GetPrivatePttUrl {
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
node: normalizeMediaNode(p.node),
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -30,7 +30,7 @@ export namespace GetPrivateVideoUrl {
|
||||
client: { agentType: 2 },
|
||||
},
|
||||
download: {
|
||||
node: normalizeMediaNode(p.node) as any,
|
||||
node: normalizeMediaNode(p.node),
|
||||
download: { video: { busiType: 0, sceneType: 0 } },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
// differ. The response is parsed into a `domain + urlPath +
|
||||
// rKeyParam` triple → composed into `https://<domain><path><rKey>`.
|
||||
|
||||
import type { NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import type { NTV2IndexNode, NTV2RichMediaResp } from '@snowluma/proto-defs/oidb-actions/media';
|
||||
import { ensureRetCodeZero } from '../shared';
|
||||
|
||||
export function parseNtv2DownloadUrl(body: NTV2RichMediaResp): string {
|
||||
@@ -24,7 +24,7 @@ export function parseNtv2DownloadUrl(body: NTV2RichMediaResp): string {
|
||||
/** Normalize a MediaIndexNode-shaped object into the wire-fields the
|
||||
* NTV2RichMedia `download.node` slot expects: `info{...}` /
|
||||
* `fileUuid` / `storeId` / `uploadTime` / `ttl` / `subType`. */
|
||||
export function normalizeMediaNode(node: NtMediaIndex): Record<string, unknown> {
|
||||
export function normalizeMediaNode(node: NtMediaIndex): NTV2IndexNode {
|
||||
const fileUuid = typeof node.fileUuid === 'string' ? node.fileUuid : '';
|
||||
if (!fileUuid) throw new Error('media node fileUuid is required');
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ import type { Oidb0x112eReq, Oidb0x112eResp } from '@snowluma/proto-defs/oidb-ac
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
|
||||
export interface InlineButtonClickResult {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
result: number;
|
||||
errMsg: string;
|
||||
status: 0;
|
||||
|
||||
@@ -10,15 +10,18 @@ import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export interface LikeInfo {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
uid: string;
|
||||
time: number;
|
||||
favoriteInfo: {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
total_count: number;
|
||||
last_time: number;
|
||||
today_count: number;
|
||||
userInfos: never[];
|
||||
};
|
||||
voteInfo: {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
total_count: number;
|
||||
new_count: number;
|
||||
new_nearby_count: number;
|
||||
|
||||
@@ -13,6 +13,10 @@ import type { Oidb0xe17Req, Oidb0xe17Resp } from '@snowluma/proto-defs/oidb-acti
|
||||
import { invokeOidb, type OidbSender } from '../../oidb-service';
|
||||
import type { BridgeContext } from '../../bridge-context';
|
||||
|
||||
export interface UnidirectionalFriendEntry {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
}
|
||||
|
||||
export namespace GetUnidirectionalFriendList {
|
||||
export const command = 0xE17;
|
||||
export const subCommand = 0;
|
||||
@@ -35,9 +39,9 @@ export namespace GetUnidirectionalFriendList {
|
||||
return { jsonBody: JSON.stringify(reqObj) };
|
||||
};
|
||||
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0xe17Resp): unknown[] => {
|
||||
export const deserialize = (_ctx: Deps, body: Oidb0xe17Resp): UnidirectionalFriendEntry[] => {
|
||||
if (!body || !body.jsonBody) throw new Error('get unidirectional friend list empty');
|
||||
const parsed = JSON.parse(body.jsonBody);
|
||||
const parsed = JSON.parse(body.jsonBody) as { rpt_block_list?: UnidirectionalFriendEntry[] };
|
||||
return parsed.rpt_block_list || [];
|
||||
};
|
||||
|
||||
@@ -47,6 +51,6 @@ export namespace GetUnidirectionalFriendList {
|
||||
export const decode = (bytes: Uint8Array): OidbBase<Oidb0xe17Resp> =>
|
||||
protobuf_decode<OidbBase<Oidb0xe17Resp>>(bytes);
|
||||
|
||||
export const invoke = (deps: Deps): Promise<unknown[]> =>
|
||||
export const invoke = (deps: Deps): Promise<UnidirectionalFriendEntry[]> =>
|
||||
invokeOidb(deps, GetUnidirectionalFriendList, {});
|
||||
}
|
||||
@@ -3,6 +3,7 @@ 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';
|
||||
|
||||
// 群相册信息
|
||||
export interface GroupAlbumInfo {
|
||||
@@ -10,13 +11,13 @@ export interface GroupAlbumInfo {
|
||||
name: string;
|
||||
picNum: number;
|
||||
createTime: number;
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
|
||||
// 获取群相册列表返回
|
||||
export interface GroupAlbumListRet {
|
||||
album: GroupAlbumInfo[];
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue | GroupAlbumInfo[];
|
||||
}
|
||||
|
||||
// 相册媒体信息
|
||||
@@ -24,7 +25,7 @@ export interface AlbumMediaInfo {
|
||||
photoId: string;
|
||||
url: string;
|
||||
uploadTime: number;
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,7 +151,7 @@ async function uploadAlbumSlice(
|
||||
session: string,
|
||||
filePath: string,
|
||||
// 移除 offset 和 chunkSize 参数,改为在内部控制
|
||||
imgMd5: string,
|
||||
_imgMd5: string,
|
||||
skey: string,
|
||||
pskey: string,
|
||||
uin: string
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { RequestUtil, cookieToString, getBknFromCookie } from './request-util';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { JsonObject } from '@snowluma/common/json';
|
||||
|
||||
const log = createLogger('Bridge.Web');
|
||||
|
||||
@@ -8,10 +9,10 @@ export interface GroupEssenceMsgRet {
|
||||
retcode: number;
|
||||
data: {
|
||||
is_end: boolean;
|
||||
msg_list: any[]; // 具体结构视需要补充
|
||||
[key: string]: any;
|
||||
msg_list: JsonObject[]; // 具体结构视需要补充
|
||||
[key: string]: JsonObject[] | boolean | string | number | null;
|
||||
};
|
||||
[key: string]: any;
|
||||
[key: string]: JsonObject | JsonObject[] | boolean | string | number | null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,6 +3,26 @@ import { createLogger } from '@snowluma/common/logger';
|
||||
|
||||
const log = createLogger('Bridge.Web');
|
||||
|
||||
export interface WebHonorItem {
|
||||
[key: string]: import('@snowluma/common/json').JsonValue;
|
||||
user_id: number | string | null;
|
||||
nickname: string;
|
||||
avatar: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
interface RawHonorItem {
|
||||
uin?: number | string;
|
||||
name?: string;
|
||||
avatar?: string;
|
||||
desc?: string;
|
||||
}
|
||||
|
||||
interface HonorInitialState {
|
||||
talkativeList?: RawHonorItem[];
|
||||
actorList?: RawHonorItem[];
|
||||
}
|
||||
|
||||
export enum WebHonorType {
|
||||
TALKATIVE = 'talkative',
|
||||
PERFORMER = 'performer',
|
||||
@@ -12,8 +32,8 @@ export enum WebHonorType {
|
||||
}
|
||||
|
||||
|
||||
async function fetchHonorData(cookieObject: Record<string, string>, groupCode: string, type: number) {
|
||||
let resJson;
|
||||
async function fetchHonorData(cookieObject: Record<string, string>, groupCode: string, type: number): Promise<RawHonorItem[] | undefined> {
|
||||
let resJson: HonorInitialState | undefined;
|
||||
try {
|
||||
const res = await RequestUtil.HttpGetText(
|
||||
`https://qun.qq.com/interactive/honorlist?${new URLSearchParams({
|
||||
@@ -26,7 +46,7 @@ async function fetchHonorData(cookieObject: Record<string, string>, groupCode: s
|
||||
);
|
||||
const match = /window\.__INITIAL_STATE__=(.*?);/.exec(res);
|
||||
if (match?.[1]) {
|
||||
resJson = JSON.parse(match[1].trim());
|
||||
resJson = JSON.parse(match[1].trim()) as HonorInitialState;
|
||||
}
|
||||
return type === 1 ? resJson?.talkativeList : resJson?.actorList;
|
||||
} catch (e) {
|
||||
@@ -34,16 +54,16 @@ async function fetchHonorData(cookieObject: Record<string, string>, groupCode: s
|
||||
}
|
||||
}
|
||||
|
||||
export async function getHonorListWebAPI(cookieObject: Record<string, string>, groupCode: string, type: number) {
|
||||
export async function getHonorListWebAPI(cookieObject: Record<string, string>, groupCode: string, type: number): Promise<WebHonorItem[]> {
|
||||
try {
|
||||
const data = await fetchHonorData(cookieObject, groupCode, type);
|
||||
if (!data) return [];
|
||||
|
||||
return data.map((item: any) => ({
|
||||
user_id: item?.uin,
|
||||
nickname: item?.name,
|
||||
avatar: item?.avatar,
|
||||
description: item?.desc,
|
||||
return data.map((item) => ({
|
||||
user_id: item?.uin ?? null,
|
||||
nickname: item?.name ?? '',
|
||||
avatar: item?.avatar ?? '',
|
||||
description: item?.desc ?? '',
|
||||
}));
|
||||
} catch (e) {
|
||||
log.warn('getHonorListWebAPI failed (group=%s type=%d): %s',
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { RequestUtil, cookieToString } from './request-util';
|
||||
import https from 'node:https';
|
||||
import { createLogger } from '@snowluma/common/logger';
|
||||
import type { JsonValue } from '@snowluma/common/json';
|
||||
|
||||
const log = createLogger('Bridge.Web');
|
||||
|
||||
export interface SetNoticeRetSuccess {
|
||||
ec?: number;
|
||||
em?: string;
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue | undefined;
|
||||
}
|
||||
|
||||
export interface UploadImageRetSuccess {
|
||||
ec?: number;
|
||||
id?: string;
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue | undefined;
|
||||
}
|
||||
|
||||
export interface WebApiGroupNoticeFeed {
|
||||
@@ -24,16 +25,16 @@ export interface WebApiGroupNoticeFeed {
|
||||
text: string;
|
||||
pics?: Array<{ id: string; w: number; h: number }>;
|
||||
};
|
||||
settings: any;
|
||||
settings: JsonValue;
|
||||
read_num: number;
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue;
|
||||
}
|
||||
|
||||
export interface WebApiGroupNoticeRet {
|
||||
ec: number;
|
||||
em?: string;
|
||||
feeds?: Record<string, WebApiGroupNoticeFeed>;
|
||||
[key: string]: any;
|
||||
[key: string]: JsonValue | Record<string, WebApiGroupNoticeFeed> | undefined;
|
||||
}
|
||||
|
||||
export function calculateBkn(key: string): string {
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import https from 'node:https';
|
||||
import http from 'node:http';
|
||||
|
||||
type RequestBody = string | Buffer | Uint8Array | Record<string, unknown> | undefined;
|
||||
|
||||
export class RequestUtil {
|
||||
static async HttpsGetCookies(url: string): Promise<{ [key: string]: string; }> {
|
||||
const client = url.startsWith('https') ? https : http;
|
||||
@@ -50,7 +52,7 @@ export class RequestUtil {
|
||||
});
|
||||
}
|
||||
|
||||
static async HttpGetJson<T>(url: string, method: string = 'GET', data?: any, headers: {
|
||||
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> {
|
||||
const option = new URL(url);
|
||||
@@ -91,8 +93,8 @@ export class RequestUtil {
|
||||
} else {
|
||||
reject(new Error(`Unexpected status code: ${res.statusCode}`));
|
||||
}
|
||||
} catch (parseError: any) {
|
||||
reject(new Error(parseError.message));
|
||||
} catch (parseError: unknown) {
|
||||
reject(new Error(parseError instanceof Error ? parseError.message : String(parseError)));
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -105,7 +107,7 @@ export class RequestUtil {
|
||||
});
|
||||
}
|
||||
|
||||
static async HttpGetText(url: string, method: string = 'GET', data?: any, headers: { [key: string]: string; } = {}) {
|
||||
static async HttpGetText(url: string, method: string = 'GET', data?: RequestBody, headers: { [key: string]: string; } = {}) {
|
||||
return this.HttpGetJson<string>(url, method, data, headers, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user