@napuketto/adapter 0.13.1 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/kurobot/index.mjs +1 -1
- package/dist/milky/index.d.mts +5 -1
- package/dist/milky/index.d.mts.map +1 -1
- package/dist/milky/index.mjs +198 -203
- package/dist/milky/index.mjs.map +1 -1
- package/dist/onebot11/index.d.mts +5 -1
- package/dist/onebot11/index.d.mts.map +1 -1
- package/dist/onebot11/index.mjs +101 -4
- package/dist/onebot11/index.mjs.map +1 -1
- package/dist/raw-message-D2vA27kj.mjs +31 -0
- package/dist/raw-message-D2vA27kj.mjs.map +1 -0
- package/dist/satori/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/raw-message-C1E7jbjl.mjs +0 -18
- package/dist/raw-message-C1E7jbjl.mjs.map +0 -1
package/dist/kurobot/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { y as BaseProtocolAdapter } from "../core-CMqpb5-m.mjs";
|
|
2
|
-
import { t as forEachRawMessage } from "../raw-message-
|
|
2
|
+
import { t as forEachRawMessage } from "../raw-message-D2vA27kj.mjs";
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import { ChatType, toCanonicalElements } from "@napuketto/kernel";
|
|
5
5
|
import { z } from "zod";
|
package/dist/milky/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* 装配方(loader assemble-protocols)动态 import 本入口。
|
|
6
6
|
*/
|
|
7
7
|
import { D as ActionRegistry, S as BaseProtocolAdapter, w as ProtocolConfig } from "../index-DDPMbC_c.mjs";
|
|
8
|
-
import { BuddyEventChannel, ChatType, FriendApi, GroupApi, GroupCache, GroupEventChannel, GroupNotifyApi, KernelErrorCode, LoginEventChannel, MsgApi, MsgEventChannel, Peer, ProfileApi, ProfileLikeApi, RawMessage, RecentContactApi, RecentContactEventChannel, RichMediaApi, TicketApi, WebApi } from "@napuketto/kernel";
|
|
8
|
+
import { BuddyEventChannel, ChatType, FlashTransferApi, FriendApi, GroupApi, GroupCache, GroupEventChannel, GroupNotifyApi, KernelErrorCode, LoginEventChannel, MsgApi, MsgEventChannel, Peer, ProfileApi, ProfileLikeApi, RawMessage, RecentContactApi, RecentContactEventChannel, RichMediaApi, TicketApi, WebApi } from "@napuketto/kernel";
|
|
9
9
|
import { ZodType, z } from "zod";
|
|
10
10
|
import { EventBroadcaster } from "@napuketto/network";
|
|
11
11
|
/** 合并转发 resId → 定位信息(get_forwarded_messages 取 peer 用)。 */
|
|
@@ -96,6 +96,8 @@ interface MilkyApiOptions {
|
|
|
96
96
|
webApi: WebApi;
|
|
97
97
|
groupNotifyApi: GroupNotifyApi;
|
|
98
98
|
richMediaApi: RichMediaApi;
|
|
99
|
+
/** kernel 闪传 API(upload_group_file / upload_private_file 的投递通道)。 */
|
|
100
|
+
flashTransferApi: FlashTransferApi;
|
|
99
101
|
/** P2 批次二:会话列表(get_peer_pins 数据源)。 */
|
|
100
102
|
recentContactApi: RecentContactApi;
|
|
101
103
|
/** 登录身份(get_login_info / self_id / target_user_uid 用)。 */
|
|
@@ -125,6 +127,8 @@ declare class MilkyApi {
|
|
|
125
127
|
readonly webApi: WebApi;
|
|
126
128
|
readonly groupNotifyApi: GroupNotifyApi;
|
|
127
129
|
readonly richMediaApi: RichMediaApi;
|
|
130
|
+
/** kernel 闪传 API(文件投递:分享卡片,见 flash-transfer.ts 语义说明)。 */
|
|
131
|
+
readonly flashTransferApi: FlashTransferApi;
|
|
128
132
|
readonly recentContactApi: RecentContactApi;
|
|
129
133
|
readonly self: {
|
|
130
134
|
uin: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/milky/helper/state/seq-index.ts","../../src/milky/action/error-map.ts","../../src/milky/action/base-action.ts","../../src/milky/config.ts","../../src/milky/transport.ts","../../src/milky/api.ts","../../src/milky/action/index.ts","../../src/milky/adapter.ts"],"mappings":";;;;;;;;;;;UAuBiB;EACb,UAAU;EACV;EACA;;cAGS;;mBAEQ;;mBAEA;;mBAEA;;EAGjB,OAAO,KAAK;;EAeZ,aAAa,UAAU,UAAU,iBAAiB;;;;;EAQlD,iBACI,mBACD;IAAc;IAAoB;IAAkB;;;UAgB/C;;;;;EAQR,cAAc,eAAe,OAAO;;EAepC,eAAe,gBAAgB;;UAKvB;;;KClGA,oBAAoB,OAAO;;UCItB,kBAAkB;EAC/B;EACA;EACA,MAAM;EACN;;uBAYkB,YAAY,UAAU;oBACtB;oBACA,QAAQ,QAAQ;8BACN,cAAc;qBAEvB,QAAQ,SAAS,WAAW,QAAQ;;EAGjD,OAAO,mBAAmB,QAAQ,kBAAkB;;;qBC5BjD,mBAAiB,EAAA;;;;;;;;;;;GAe5B,EAAA,KAAA;;KAGU,cAAc,EAAE,aAAa;;UCQxB;EACb,MAAM,cAAc;EACpB,KAAK,cAAc;EACnB,KAAK,cAAc;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/milky/helper/state/seq-index.ts","../../src/milky/action/error-map.ts","../../src/milky/action/base-action.ts","../../src/milky/config.ts","../../src/milky/transport.ts","../../src/milky/api.ts","../../src/milky/action/index.ts","../../src/milky/adapter.ts"],"mappings":";;;;;;;;;;;UAuBiB;EACb,UAAU;EACV;EACA;;cAGS;;mBAEQ;;mBAEA;;mBAEA;;EAGjB,OAAO,KAAK;;EAeZ,aAAa,UAAU,UAAU,iBAAiB;;;;;EAQlD,iBACI,mBACD;IAAc;IAAoB;IAAkB;;;UAgB/C;;;;;EAQR,cAAc,eAAe,OAAO;;EAepC,eAAe,gBAAgB;;UAKvB;;;KClGA,oBAAoB,OAAO;;UCItB,kBAAkB;EAC/B;EACA;EACA,MAAM;EACN;;uBAYkB,YAAY,UAAU;oBACtB;oBACA,QAAQ,QAAQ;8BACN,cAAc;qBAEvB,QAAQ,SAAS,WAAW,QAAQ;;EAGjD,OAAO,mBAAmB,QAAQ,kBAAkB;;;qBC5BjD,mBAAiB,EAAA;;;;;;;;;;;GAe5B,EAAA,KAAA;;KAGU,cAAc,EAAE,aAAa;;UCQxB;EACb,MAAM,cAAc;EACpB,KAAK,cAAc;EACnB,KAAK,cAAc;;;UCTN;EACb,QAAQ;EACR,UAAU;EACV,WAAW;EACX,YAAY;;EAEZ,gBAAgB;EAChB,WAAW;EACX,QAAQ;EACR,gBAAgB;EAChB,cAAc;;EAEd,kBAAkB;;EAElB,kBAAkB;;EAElB;IAAQ;IAAa;IAAkB;;;EAEvC,aAAa;;EAEb;;EAEA;;EAEA;;EAEA,SAAS;;cAGA;WACA,QAAQ;WACR,UAAU;WACV,WAAW;WACX,YAAY;WACZ,gBAAgB;WAChB,WAAW;WACX,QAAQ;WACR,gBAAgB;WAChB,cAAc;;WAEd,kBAAkB;WAClB,kBAAkB;WAClB;IAAQ;IAAa;IAAkB;;WACvC,YAAY;WACZ;WACA;WACA;;WAEA,QAAQ;;WAER,UAAU;EAEnB,YAAY,MAAM,iBAAiB,UAAU;;EAsB7C,SAAS,iBAAiB,QAAQ;;EAKlC,SAAS,iBAAiB,QAAQ;;;;;EAQ5B,kBAAkB,uBAAuB;;;;;EAiBzC,YAAY,oCAAoC,aAAa,QAAQ;;;;;EAqBrE,kBACF,MAAM,MACN,aACA,UAAU,mBACX;;EAeG,kBACF,MAAM,MACN,gBACD;IAAU;IAAqB;;;;iBC3FtB,0BAA0B;EACtC,KAAK;IACL,eAAe;;UCfF,4BAA4B;EACzC,QAAQ,eAAe;EACvB,aAAa;;EAEb,YAAY;;EAEZ,eAAe;;EAEf,eAAe;;EAEf,uBAAuB;;EAEvB,eAAe;;EAEf,SAAS;;qBAUA,8BAA8B,oBAAoB;WAClD;mBAEQ;mBACA;mBACA;mBACA;mBACA;;mBAEA;;mBAEA;;mBAEA;;mBAEA;;UAET;mBACS;mBACA;mBACA;;WAER,UAAU,kBAAkB;UAC7B;UACA;EAER,YAAY,MAAM;;UAsBJ;;UA2BA;;UAMA;;UASN;;UA6BA;;UAoBA;;UAiCA;;UAQM;;UAuBA;;UAeN;;UASM;;UAWN;;UAkBM;;UASA;;UAgBA;;UAkBN;;UAWM;;UAaN;;;;;UAsBA;;UAeA;;UAiBA;;UAkBA;;UAmCA;;UASA;;UA2BA;;UAgBM;;UAwBN;;UAsBA;;UAoBA;;UAQA;;UAOA;;UAiBA;;UAUA;;UAcA"}
|
package/dist/milky/index.mjs
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { S as ActionRegistry, a as extractSysMsgEnvelope, c as narrowSysMsgBlobs, d as textOf, f as toHex, l as nodeAt, m as varintOf, p as varintAt, r as decodeProtoTree, u as recognizeSysMsg, y as BaseProtocolAdapter } from "../core-CMqpb5-m.mjs";
|
|
2
2
|
import { a as MS_TO_SEC$2, i as narrowBuddyReqs, n as extractEssenceSetSysMsg, o as resolveUin, r as narrowEssenceGroupArg, t as diffEssenceList } from "../essence-DzYnP60o.mjs";
|
|
3
3
|
import { n as firstUntranslatedGrayTip, t as collectGrayTipUids } from "../gray-tip-ByF-MKeV.mjs";
|
|
4
|
-
import {
|
|
4
|
+
import { r as subscribeRawMessages, t as forEachRawMessage } from "../raw-message-D2vA27kj.mjs";
|
|
5
5
|
import { ChatType, GrayTipSubType, GroupApi, GroupNotifyMsgStatus, GroupNotifyMsgType, NTGroupRequestOperateTypes, TicketApi, TipGroupElementType, isKernelError, kernelError, toCanonicalElements } from "@napuketto/kernel";
|
|
6
6
|
import { mkdir, rename, writeFile } from "node:fs/promises";
|
|
7
7
|
import { join } from "node:path";
|
|
8
8
|
import { detectFileType, downloadUrl, inferExtension } from "@napuketto/media";
|
|
9
9
|
import { z } from "zod";
|
|
10
10
|
import { randomUUID } from "node:crypto";
|
|
11
|
-
import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
|
|
12
11
|
import { fileURLToPath } from "node:url";
|
|
12
|
+
import { HttpClient, HttpServer, createSseResponse, isWsOpen } from "@napuketto/network";
|
|
13
13
|
// src/milky/api.ts
|
|
14
14
|
var MilkyApi = class {
|
|
15
15
|
msgApi;
|
|
@@ -21,6 +21,8 @@ var MilkyApi = class {
|
|
|
21
21
|
webApi;
|
|
22
22
|
groupNotifyApi;
|
|
23
23
|
richMediaApi;
|
|
24
|
+
/** kernel 闪传 API(文件投递:分享卡片,见 flash-transfer.ts 语义说明)。 */
|
|
25
|
+
flashTransferApi;
|
|
24
26
|
recentContactApi;
|
|
25
27
|
self;
|
|
26
28
|
groupCache;
|
|
@@ -41,6 +43,7 @@ var MilkyApi = class {
|
|
|
41
43
|
this.webApi = opts.webApi;
|
|
42
44
|
this.groupNotifyApi = opts.groupNotifyApi;
|
|
43
45
|
this.richMediaApi = opts.richMediaApi;
|
|
46
|
+
this.flashTransferApi = opts.flashTransferApi;
|
|
44
47
|
this.recentContactApi = opts.recentContactApi;
|
|
45
48
|
this.self = opts.self;
|
|
46
49
|
this.groupCache = opts.groupCache;
|
|
@@ -920,6 +923,184 @@ function picUrlOf(b) {
|
|
|
920
923
|
const url = b.pic?.url;
|
|
921
924
|
return typeof url === "string" && url !== "" ? url : null;
|
|
922
925
|
}
|
|
926
|
+
// src/milky/action/group-file.ts
|
|
927
|
+
const groupIdField = { group_id: z.number().int().min(10001) };
|
|
928
|
+
const fileIdField = { file_id: z.string().min(1) };
|
|
929
|
+
const optStr = z.string().nullable().optional();
|
|
930
|
+
/** get_group_files:获取群文件列表(根目录或指定文件夹;过滤 parent 匹配项)。 */
|
|
931
|
+
var GetGroupFilesAction = class extends MilkyApiAction {
|
|
932
|
+
name = "get_group_files";
|
|
933
|
+
schema = z.object({
|
|
934
|
+
...groupIdField,
|
|
935
|
+
parent_folder_id: optStr
|
|
936
|
+
});
|
|
937
|
+
async _handle(payload) {
|
|
938
|
+
const groupCode = String(payload.group_id);
|
|
939
|
+
const parent = payload.parent_folder_id ?? "";
|
|
940
|
+
const items = await this.api.richMediaApi.getGroupFileList(groupCode, parent);
|
|
941
|
+
const files = [];
|
|
942
|
+
const folders = [];
|
|
943
|
+
for (const item of items) if (item.fileInfo !== void 0) files.push(fileToEntity(item.fileInfo, payload.group_id));
|
|
944
|
+
else if (item.folderInfo !== void 0) folders.push(folderToEntity(item.folderInfo, payload.group_id));
|
|
945
|
+
return {
|
|
946
|
+
files,
|
|
947
|
+
folders
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
/** move_group_file:移动文件(target_folder_id 空 = 移到根目录;parent 入参仅 schema 兼容)。 */
|
|
952
|
+
var MoveGroupFileAction = class extends MilkyApiAction {
|
|
953
|
+
name = "move_group_file";
|
|
954
|
+
schema = z.object({
|
|
955
|
+
...groupIdField,
|
|
956
|
+
...fileIdField,
|
|
957
|
+
parent_folder_id: optStr,
|
|
958
|
+
target_folder_id: optStr
|
|
959
|
+
});
|
|
960
|
+
async _handle(payload) {
|
|
961
|
+
await this.api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
|
|
962
|
+
return {};
|
|
963
|
+
}
|
|
964
|
+
};
|
|
965
|
+
/** rename_group_file:重命名文件。 */
|
|
966
|
+
var RenameGroupFileAction = class extends MilkyApiAction {
|
|
967
|
+
name = "rename_group_file";
|
|
968
|
+
schema = z.object({
|
|
969
|
+
...groupIdField,
|
|
970
|
+
...fileIdField,
|
|
971
|
+
parent_folder_id: optStr,
|
|
972
|
+
new_file_name: z.string().min(1)
|
|
973
|
+
});
|
|
974
|
+
async _handle(payload) {
|
|
975
|
+
await this.api.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_file_name);
|
|
976
|
+
return {};
|
|
977
|
+
}
|
|
978
|
+
};
|
|
979
|
+
/** delete_group_file:删除文件。 */
|
|
980
|
+
var DeleteGroupFileAction = class extends MilkyApiAction {
|
|
981
|
+
name = "delete_group_file";
|
|
982
|
+
schema = z.object({
|
|
983
|
+
...groupIdField,
|
|
984
|
+
...fileIdField
|
|
985
|
+
});
|
|
986
|
+
async _handle(payload) {
|
|
987
|
+
await this.api.richMediaApi.deleteGroupFile(String(payload.group_id), [payload.file_id]);
|
|
988
|
+
return {};
|
|
989
|
+
}
|
|
990
|
+
};
|
|
991
|
+
/**
|
|
992
|
+
* persist_group_file:转存文件(RichMediaApi.transGroupFile,转存语义待对齐)。
|
|
993
|
+
*/
|
|
994
|
+
var PersistGroupFileAction = class extends MilkyApiAction {
|
|
995
|
+
name = "persist_group_file";
|
|
996
|
+
schema = z.object({
|
|
997
|
+
...groupIdField,
|
|
998
|
+
...fileIdField
|
|
999
|
+
});
|
|
1000
|
+
async _handle(payload) {
|
|
1001
|
+
await this.api.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
|
|
1002
|
+
return {};
|
|
1003
|
+
}
|
|
1004
|
+
};
|
|
1005
|
+
/** create_group_folder:创建文件夹(返回 folder_id)。 */
|
|
1006
|
+
var CreateGroupFolderAction = class extends MilkyApiAction {
|
|
1007
|
+
name = "create_group_folder";
|
|
1008
|
+
schema = z.object({
|
|
1009
|
+
...groupIdField,
|
|
1010
|
+
folder_name: z.string().min(1)
|
|
1011
|
+
});
|
|
1012
|
+
async _handle(payload) {
|
|
1013
|
+
return { folder_id: await this.api.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
|
|
1014
|
+
}
|
|
1015
|
+
};
|
|
1016
|
+
/** delete_group_folder:删除文件夹。 */
|
|
1017
|
+
var DeleteGroupFolderAction = class extends MilkyApiAction {
|
|
1018
|
+
name = "delete_group_folder";
|
|
1019
|
+
schema = z.object({
|
|
1020
|
+
...groupIdField,
|
|
1021
|
+
folder_id: z.string().min(1)
|
|
1022
|
+
});
|
|
1023
|
+
async _handle(payload) {
|
|
1024
|
+
await this.api.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
|
|
1025
|
+
return {};
|
|
1026
|
+
}
|
|
1027
|
+
};
|
|
1028
|
+
/** GroupFileItemInfo → GroupFileEntity(fileSize 原生为字符串;无源字段兜底)。 */
|
|
1029
|
+
function fileToEntity(info, groupId) {
|
|
1030
|
+
return {
|
|
1031
|
+
group_id: groupId,
|
|
1032
|
+
file_id: info.fileId,
|
|
1033
|
+
file_name: info.fileName,
|
|
1034
|
+
parent_folder_id: info.parent ?? "",
|
|
1035
|
+
file_size: Number(info.fileSize) || 0,
|
|
1036
|
+
uploaded_time: Number(info.uploadTime) || 0,
|
|
1037
|
+
expire_time: null,
|
|
1038
|
+
uploader_id: Number(info.uploaderUin) || 0,
|
|
1039
|
+
downloaded_times: 0
|
|
1040
|
+
};
|
|
1041
|
+
}
|
|
1042
|
+
/** GroupFolderInfo → GroupFolderEntity(元数据无类型字段防御读取,缺省 0)。 */
|
|
1043
|
+
function folderToEntity(info, groupId) {
|
|
1044
|
+
const num = (key) => {
|
|
1045
|
+
const v = info[key];
|
|
1046
|
+
return typeof v === "number" ? v : Number(v) || 0;
|
|
1047
|
+
};
|
|
1048
|
+
return {
|
|
1049
|
+
group_id: groupId,
|
|
1050
|
+
folder_id: info.folderId,
|
|
1051
|
+
parent_folder_id: info.folderUid ?? "",
|
|
1052
|
+
folder_name: info.folderName,
|
|
1053
|
+
created_time: num("createTime"),
|
|
1054
|
+
last_modified_time: num("modifyTime"),
|
|
1055
|
+
creator_id: 0,
|
|
1056
|
+
file_count: num("totalFileCount")
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
/**
|
|
1060
|
+
* upload_group_file:上传并投递文件(**闪传通道**:分享链接卡片,见文件头语义说明)。
|
|
1061
|
+
* file_id 返回闪传文件集 id(非群文件 fileId)。
|
|
1062
|
+
*/
|
|
1063
|
+
var UploadGroupFileAction = class extends MilkyApiAction {
|
|
1064
|
+
name = "upload_group_file";
|
|
1065
|
+
schema = z.object({
|
|
1066
|
+
...groupIdField,
|
|
1067
|
+
parent_folder_id: optStr,
|
|
1068
|
+
file_uri: z.string().min(1),
|
|
1069
|
+
file_name: z.string().min(1)
|
|
1070
|
+
});
|
|
1071
|
+
async _handle(payload) {
|
|
1072
|
+
const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
|
|
1073
|
+
const peer = {
|
|
1074
|
+
chatType: ChatType.GROUP,
|
|
1075
|
+
peerUid: String(payload.group_id)
|
|
1076
|
+
};
|
|
1077
|
+
return { file_id: (await this.api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
1078
|
+
}
|
|
1079
|
+
};
|
|
1080
|
+
/** get_group_file_download_url:群文件下载链接(url 字段待实机确认,仅根目录)。 */
|
|
1081
|
+
var GetGroupFileDownloadUrlAction = class extends MilkyApiAction {
|
|
1082
|
+
name = "get_group_file_download_url";
|
|
1083
|
+
schema = z.object({
|
|
1084
|
+
...groupIdField,
|
|
1085
|
+
...fileIdField
|
|
1086
|
+
});
|
|
1087
|
+
async _handle(payload) {
|
|
1088
|
+
return { download_url: await this.api.richMediaApi.getGroupFileDownloadUrl(String(payload.group_id), payload.file_id) };
|
|
1089
|
+
}
|
|
1090
|
+
};
|
|
1091
|
+
/** rename_group_folder:重命名群文件夹(renameGroupFile 同款形态,待校准)。 */
|
|
1092
|
+
var RenameGroupFolderAction = class extends MilkyApiAction {
|
|
1093
|
+
name = "rename_group_folder";
|
|
1094
|
+
schema = z.object({
|
|
1095
|
+
...groupIdField,
|
|
1096
|
+
folder_id: z.string().min(1),
|
|
1097
|
+
new_folder_name: z.string().min(1)
|
|
1098
|
+
});
|
|
1099
|
+
async _handle(payload) {
|
|
1100
|
+
await this.api.richMediaApi.renameGroupFolder(String(payload.group_id), payload.folder_id, payload.new_folder_name);
|
|
1101
|
+
return {};
|
|
1102
|
+
}
|
|
1103
|
+
};
|
|
923
1104
|
// src/milky/helper/message/segments.ts
|
|
924
1105
|
/**
|
|
925
1106
|
* Milky 消息段 ↔ canonical 元素转换(纯函数,ADR-008)
|
|
@@ -1268,7 +1449,7 @@ function toMessageReceiveEvent(msg, ctx) {
|
|
|
1268
1449
|
}
|
|
1269
1450
|
/** 撤回 grayTip → message_recall 事件(非撤回 grayTip 返回 null)。 */
|
|
1270
1451
|
function toMessageRecallEvent(msg, ctx) {
|
|
1271
|
-
const revoke = (msg.elements.find((el) => el.grayTipElement
|
|
1452
|
+
const revoke = (msg.elements.find((el) => el.grayTipElement != null)?.grayTipElement)?.revokeElement;
|
|
1272
1453
|
if (revoke === void 0) return null;
|
|
1273
1454
|
const scene = chatTypeToScene(msg.chatType);
|
|
1274
1455
|
const operatorUin = ctx.uidToUin?.get(revoke.operatorUid) ?? revoke.operatorUid;
|
|
@@ -1289,7 +1470,7 @@ function toMessageRecallEvent(msg, ctx) {
|
|
|
1289
1470
|
/** 群文件上传事件(群场景文件消息 → group_file_upload,替代 message_receive)。 */
|
|
1290
1471
|
function toGroupFileUploadEvent(msg, selfUin) {
|
|
1291
1472
|
if (msg.chatType !== ChatType.GROUP) return null;
|
|
1292
|
-
const file = msg.elements.find((el) => el.fileElement
|
|
1473
|
+
const file = msg.elements.find((el) => el.fileElement != null)?.fileElement;
|
|
1293
1474
|
if (file === void 0) return null;
|
|
1294
1475
|
return {
|
|
1295
1476
|
time: Math.floor(Number(msg.msgTime) / MS_TO_SEC$1),
|
|
@@ -1618,7 +1799,7 @@ const peerMessageFields = {
|
|
|
1618
1799
|
/** 单条消息 → 接收段(canonical 映射 + forward 段注入,forward 不经 canonical)。 */
|
|
1619
1800
|
function receiveSegmentsOf(msg, uidToUin) {
|
|
1620
1801
|
const segments = canonicalToIncomingSegments(toCanonicalElements(msg), { ...uidToUin.size > 0 ? { uidToUin } : {} });
|
|
1621
|
-
const fwd = msg.elements.find((el) => el.multiForwardMsgElement
|
|
1802
|
+
const fwd = msg.elements.find((el) => el.multiForwardMsgElement != null)?.multiForwardMsgElement;
|
|
1622
1803
|
if (fwd !== void 0) segments.push(incomingForwardSegment(fwd.resId, fwd.fileName));
|
|
1623
1804
|
return segments;
|
|
1624
1805
|
}
|
|
@@ -1648,7 +1829,11 @@ var GetResourceTempUrlAction = class extends MilkyApiAction {
|
|
|
1648
1829
|
throw kernelError(`资源 ${id} 无临时链接(resource_id 非链接形态)`, "NOT_FOUND");
|
|
1649
1830
|
}
|
|
1650
1831
|
};
|
|
1651
|
-
/**
|
|
1832
|
+
/**
|
|
1833
|
+
* upload_private_file:上传并投递私聊文件(**闪传通道**:分享链接卡片)。
|
|
1834
|
+
* file_id 返回闪传文件集 id(非文件消息 fileUuid)。语义降级同 upload_group_file:
|
|
1835
|
+
* 对端收到的是分享链接卡片而不是 fileElement 文件消息(kernel design §15)。
|
|
1836
|
+
*/
|
|
1652
1837
|
var UploadPrivateFileAction = class extends MilkyApiAction {
|
|
1653
1838
|
name = "upload_private_file";
|
|
1654
1839
|
schema = z.object({
|
|
@@ -1659,197 +1844,7 @@ var UploadPrivateFileAction = class extends MilkyApiAction {
|
|
|
1659
1844
|
async _handle(payload) {
|
|
1660
1845
|
const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
|
|
1661
1846
|
const peer = await this.api.resolvePeer("friend", payload.user_id);
|
|
1662
|
-
return { file_id: await
|
|
1663
|
-
}
|
|
1664
|
-
};
|
|
1665
|
-
/**
|
|
1666
|
-
* 发送文件消息并回查 file_id:sendMessage(canonical file 元素,kernel 走
|
|
1667
|
-
* prepareFileElement 链)→ fetchMsgsByMsgId 取 fileElement.fileUuid(缺省 msgId)。
|
|
1668
|
-
* upload_private/group_file 共用。
|
|
1669
|
-
*/
|
|
1670
|
-
async function sendFileMessage(api, peer, path, fileName) {
|
|
1671
|
-
const { msgId } = await api.msgApi.sendMessage(peer, [{
|
|
1672
|
-
type: "file",
|
|
1673
|
-
path,
|
|
1674
|
-
name: fileName
|
|
1675
|
-
}]);
|
|
1676
|
-
const [sent] = await api.msgApi.fetchMsgsByMsgId(peer, [msgId]);
|
|
1677
|
-
const uuid = (sent?.elements.find((e) => e.fileElement !== void 0))?.fileElement?.fileUuid;
|
|
1678
|
-
return uuid !== void 0 && uuid !== "" ? uuid : msgId;
|
|
1679
|
-
}
|
|
1680
|
-
// src/milky/action/group-file.ts
|
|
1681
|
-
const groupIdField = { group_id: z.number().int().min(10001) };
|
|
1682
|
-
const fileIdField = { file_id: z.string().min(1) };
|
|
1683
|
-
const optStr = z.string().nullable().optional();
|
|
1684
|
-
/** get_group_files:获取群文件列表(根目录或指定文件夹;过滤 parent 匹配项)。 */
|
|
1685
|
-
var GetGroupFilesAction = class extends MilkyApiAction {
|
|
1686
|
-
name = "get_group_files";
|
|
1687
|
-
schema = z.object({
|
|
1688
|
-
...groupIdField,
|
|
1689
|
-
parent_folder_id: optStr
|
|
1690
|
-
});
|
|
1691
|
-
async _handle(payload) {
|
|
1692
|
-
const groupCode = String(payload.group_id);
|
|
1693
|
-
const parent = payload.parent_folder_id ?? "";
|
|
1694
|
-
const items = await this.api.richMediaApi.getGroupFileList(groupCode, parent);
|
|
1695
|
-
const files = [];
|
|
1696
|
-
const folders = [];
|
|
1697
|
-
for (const item of items) if (item.fileInfo !== void 0) files.push(fileToEntity(item.fileInfo, payload.group_id));
|
|
1698
|
-
else if (item.folderInfo !== void 0) folders.push(folderToEntity(item.folderInfo, payload.group_id));
|
|
1699
|
-
return {
|
|
1700
|
-
files,
|
|
1701
|
-
folders
|
|
1702
|
-
};
|
|
1703
|
-
}
|
|
1704
|
-
};
|
|
1705
|
-
/** move_group_file:移动文件(target_folder_id 空 = 移到根目录;parent 入参仅 schema 兼容)。 */
|
|
1706
|
-
var MoveGroupFileAction = class extends MilkyApiAction {
|
|
1707
|
-
name = "move_group_file";
|
|
1708
|
-
schema = z.object({
|
|
1709
|
-
...groupIdField,
|
|
1710
|
-
...fileIdField,
|
|
1711
|
-
parent_folder_id: optStr,
|
|
1712
|
-
target_folder_id: optStr
|
|
1713
|
-
});
|
|
1714
|
-
async _handle(payload) {
|
|
1715
|
-
await this.api.richMediaApi.moveGroupFile(String(payload.group_id), [payload.file_id], payload.target_folder_id ?? "");
|
|
1716
|
-
return {};
|
|
1717
|
-
}
|
|
1718
|
-
};
|
|
1719
|
-
/** rename_group_file:重命名文件。 */
|
|
1720
|
-
var RenameGroupFileAction = class extends MilkyApiAction {
|
|
1721
|
-
name = "rename_group_file";
|
|
1722
|
-
schema = z.object({
|
|
1723
|
-
...groupIdField,
|
|
1724
|
-
...fileIdField,
|
|
1725
|
-
parent_folder_id: optStr,
|
|
1726
|
-
new_file_name: z.string().min(1)
|
|
1727
|
-
});
|
|
1728
|
-
async _handle(payload) {
|
|
1729
|
-
await this.api.richMediaApi.renameGroupFile(String(payload.group_id), payload.file_id, payload.new_file_name);
|
|
1730
|
-
return {};
|
|
1731
|
-
}
|
|
1732
|
-
};
|
|
1733
|
-
/** delete_group_file:删除文件。 */
|
|
1734
|
-
var DeleteGroupFileAction = class extends MilkyApiAction {
|
|
1735
|
-
name = "delete_group_file";
|
|
1736
|
-
schema = z.object({
|
|
1737
|
-
...groupIdField,
|
|
1738
|
-
...fileIdField
|
|
1739
|
-
});
|
|
1740
|
-
async _handle(payload) {
|
|
1741
|
-
await this.api.richMediaApi.deleteGroupFile(String(payload.group_id), [payload.file_id]);
|
|
1742
|
-
return {};
|
|
1743
|
-
}
|
|
1744
|
-
};
|
|
1745
|
-
/**
|
|
1746
|
-
* persist_group_file:转存文件(RichMediaApi.transGroupFile,转存语义待对齐)。
|
|
1747
|
-
*/
|
|
1748
|
-
var PersistGroupFileAction = class extends MilkyApiAction {
|
|
1749
|
-
name = "persist_group_file";
|
|
1750
|
-
schema = z.object({
|
|
1751
|
-
...groupIdField,
|
|
1752
|
-
...fileIdField
|
|
1753
|
-
});
|
|
1754
|
-
async _handle(payload) {
|
|
1755
|
-
await this.api.richMediaApi.transGroupFile(String(payload.group_id), payload.file_id);
|
|
1756
|
-
return {};
|
|
1757
|
-
}
|
|
1758
|
-
};
|
|
1759
|
-
/** create_group_folder:创建文件夹(返回 folder_id)。 */
|
|
1760
|
-
var CreateGroupFolderAction = class extends MilkyApiAction {
|
|
1761
|
-
name = "create_group_folder";
|
|
1762
|
-
schema = z.object({
|
|
1763
|
-
...groupIdField,
|
|
1764
|
-
folder_name: z.string().min(1)
|
|
1765
|
-
});
|
|
1766
|
-
async _handle(payload) {
|
|
1767
|
-
return { folder_id: await this.api.richMediaApi.createGroupFolder(String(payload.group_id), payload.folder_name) };
|
|
1768
|
-
}
|
|
1769
|
-
};
|
|
1770
|
-
/** delete_group_folder:删除文件夹。 */
|
|
1771
|
-
var DeleteGroupFolderAction = class extends MilkyApiAction {
|
|
1772
|
-
name = "delete_group_folder";
|
|
1773
|
-
schema = z.object({
|
|
1774
|
-
...groupIdField,
|
|
1775
|
-
folder_id: z.string().min(1)
|
|
1776
|
-
});
|
|
1777
|
-
async _handle(payload) {
|
|
1778
|
-
await this.api.richMediaApi.deleteGroupFolder(String(payload.group_id), payload.folder_id);
|
|
1779
|
-
return {};
|
|
1780
|
-
}
|
|
1781
|
-
};
|
|
1782
|
-
/** GroupFileItemInfo → GroupFileEntity(fileSize 原生为字符串;无源字段兜底)。 */
|
|
1783
|
-
function fileToEntity(info, groupId) {
|
|
1784
|
-
return {
|
|
1785
|
-
group_id: groupId,
|
|
1786
|
-
file_id: info.fileId,
|
|
1787
|
-
file_name: info.fileName,
|
|
1788
|
-
parent_folder_id: info.parent ?? "",
|
|
1789
|
-
file_size: Number(info.fileSize) || 0,
|
|
1790
|
-
uploaded_time: Number(info.uploadTime) || 0,
|
|
1791
|
-
expire_time: null,
|
|
1792
|
-
uploader_id: Number(info.uploaderUin) || 0,
|
|
1793
|
-
downloaded_times: 0
|
|
1794
|
-
};
|
|
1795
|
-
}
|
|
1796
|
-
/** GroupFolderInfo → GroupFolderEntity(元数据无类型字段防御读取,缺省 0)。 */
|
|
1797
|
-
function folderToEntity(info, groupId) {
|
|
1798
|
-
const num = (key) => {
|
|
1799
|
-
const v = info[key];
|
|
1800
|
-
return typeof v === "number" ? v : Number(v) || 0;
|
|
1801
|
-
};
|
|
1802
|
-
return {
|
|
1803
|
-
group_id: groupId,
|
|
1804
|
-
folder_id: info.folderId,
|
|
1805
|
-
parent_folder_id: info.folderUid ?? "",
|
|
1806
|
-
folder_name: info.folderName,
|
|
1807
|
-
created_time: num("createTime"),
|
|
1808
|
-
last_modified_time: num("modifyTime"),
|
|
1809
|
-
creator_id: 0,
|
|
1810
|
-
file_count: num("totalFileCount")
|
|
1811
|
-
};
|
|
1812
|
-
}
|
|
1813
|
-
/** upload_group_file:上传群文件(消息发送链;parent_folder_id 暂不参与定位)。 */
|
|
1814
|
-
var UploadGroupFileAction = class extends MilkyApiAction {
|
|
1815
|
-
name = "upload_group_file";
|
|
1816
|
-
schema = z.object({
|
|
1817
|
-
...groupIdField,
|
|
1818
|
-
parent_folder_id: optStr,
|
|
1819
|
-
file_uri: z.string().min(1),
|
|
1820
|
-
file_name: z.string().min(1)
|
|
1821
|
-
});
|
|
1822
|
-
async _handle(payload) {
|
|
1823
|
-
const path = await resolveUriToPath(payload.file_uri, this.api.mediaDir);
|
|
1824
|
-
const peer = {
|
|
1825
|
-
chatType: ChatType.GROUP,
|
|
1826
|
-
peerUid: String(payload.group_id)
|
|
1827
|
-
};
|
|
1828
|
-
return { file_id: await sendFileMessage(this.api, peer, path, payload.file_name) };
|
|
1829
|
-
}
|
|
1830
|
-
};
|
|
1831
|
-
/** get_group_file_download_url:群文件下载链接(url 字段待实机确认,仅根目录)。 */
|
|
1832
|
-
var GetGroupFileDownloadUrlAction = class extends MilkyApiAction {
|
|
1833
|
-
name = "get_group_file_download_url";
|
|
1834
|
-
schema = z.object({
|
|
1835
|
-
...groupIdField,
|
|
1836
|
-
...fileIdField
|
|
1837
|
-
});
|
|
1838
|
-
async _handle(payload) {
|
|
1839
|
-
return { download_url: await this.api.richMediaApi.getGroupFileDownloadUrl(String(payload.group_id), payload.file_id) };
|
|
1840
|
-
}
|
|
1841
|
-
};
|
|
1842
|
-
/** rename_group_folder:重命名群文件夹(renameGroupFile 同款形态,待校准)。 */
|
|
1843
|
-
var RenameGroupFolderAction = class extends MilkyApiAction {
|
|
1844
|
-
name = "rename_group_folder";
|
|
1845
|
-
schema = z.object({
|
|
1846
|
-
...groupIdField,
|
|
1847
|
-
folder_id: z.string().min(1),
|
|
1848
|
-
new_folder_name: z.string().min(1)
|
|
1849
|
-
});
|
|
1850
|
-
async _handle(payload) {
|
|
1851
|
-
await this.api.richMediaApi.renameGroupFolder(String(payload.group_id), payload.folder_id, payload.new_folder_name);
|
|
1852
|
-
return {};
|
|
1847
|
+
return { file_id: (await this.api.flashTransferApi.sendFile(peer, [path], { name: payload.file_name })).fileSetId };
|
|
1853
1848
|
}
|
|
1854
1849
|
};
|
|
1855
1850
|
// src/milky/action/profile.ts
|
|
@@ -2248,7 +2243,7 @@ function createMilkyActionRegistry(opts) {
|
|
|
2248
2243
|
/** 单条 C2C 文件消息 → 事件载荷(非 C2C / 无 fileElement / 无 fileUuid → null)。 */
|
|
2249
2244
|
function toFriendFileUploadData(msg, selfUin, uidToUin) {
|
|
2250
2245
|
if (msg.chatType !== ChatType.C2C) return null;
|
|
2251
|
-
const file = msg.elements.find((el) => el.fileElement
|
|
2246
|
+
const file = msg.elements.find((el) => el.fileElement != null)?.fileElement;
|
|
2252
2247
|
if (file === void 0 || typeof file.fileUuid !== "string" || file.fileUuid === "") return null;
|
|
2253
2248
|
const isSelf = msg.sendType === 2 || String(msg.senderUin) === selfUin;
|
|
2254
2249
|
const userUin = msg.senderUin !== "" ? Number(msg.senderUin) : resolveUin(msg.senderUid, uidToUin);
|
|
@@ -2280,7 +2275,7 @@ function envelope(msg, ctx, eventType, data) {
|
|
|
2280
2275
|
}
|
|
2281
2276
|
/** 单个 grayTip → Milky notice 事件(null = 不可翻译)。 */
|
|
2282
2277
|
function translateGrayTip(msg, g, ctx) {
|
|
2283
|
-
if (g.aioOpGrayTipElement
|
|
2278
|
+
if (g.aioOpGrayTipElement != null) return aioOpToEvent(msg, g, ctx);
|
|
2284
2279
|
if (g.subElementType === GrayTipSubType.GROUP) return groupElementToEvent(msg, g.groupElement, ctx);
|
|
2285
2280
|
return null;
|
|
2286
2281
|
}
|
|
@@ -3037,7 +3032,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3037
3032
|
await this.fillMentionUids(elements, ctx);
|
|
3038
3033
|
this.fillReplyMeta(elements, ctx);
|
|
3039
3034
|
await this.fillGroupEntities(msg, ctx);
|
|
3040
|
-
const forward = msg.elements.find((el) => el.multiForwardMsgElement
|
|
3035
|
+
const forward = msg.elements.find((el) => el.multiForwardMsgElement != null)?.multiForwardMsgElement;
|
|
3041
3036
|
if (forward !== void 0) ctx.forwardSegments = [incomingForwardSegment(forward.resId, forward.fileName)];
|
|
3042
3037
|
return toMessageReceiveEvent(msg, ctx);
|
|
3043
3038
|
}
|
|
@@ -3064,7 +3059,7 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3064
3059
|
}
|
|
3065
3060
|
/** 转发 resId → 定位登记(get_forwarded_messages 反查用)。 */
|
|
3066
3061
|
recordForward(msg) {
|
|
3067
|
-
const forward = msg.elements.find((el) => el.multiForwardMsgElement
|
|
3062
|
+
const forward = msg.elements.find((el) => el.multiForwardMsgElement != null)?.multiForwardMsgElement;
|
|
3068
3063
|
if (forward !== void 0 && forward.resId !== "") this.seqIndex.recordForward(forward.resId, {
|
|
3069
3064
|
chatType: msg.chatType,
|
|
3070
3065
|
peerUid: msg.peerUid,
|
|
@@ -3274,11 +3269,11 @@ var NapukettoMilkyAdapter = class extends BaseProtocolAdapter {
|
|
|
3274
3269
|
};
|
|
3275
3270
|
/** 是否含 grayTip 元素(与 OB11 收链路同判据)。 */
|
|
3276
3271
|
function hasGrayTip(msg) {
|
|
3277
|
-
return msg.elements.some((el) => el.grayTipElement
|
|
3272
|
+
return msg.elements.some((el) => el.grayTipElement != null);
|
|
3278
3273
|
}
|
|
3279
3274
|
/** 撤回 grayTip 元素(非撤回消息返回 undefined)。 */
|
|
3280
3275
|
function findRevokeElement(msg) {
|
|
3281
|
-
return msg.elements.find((el) => el.grayTipElement?.revokeElement
|
|
3276
|
+
return msg.elements.find((el) => el.grayTipElement?.revokeElement != null)?.grayTipElement?.revokeElement;
|
|
3282
3277
|
}
|
|
3283
3278
|
/** 字符串截断(raw 日志防刷屏)。 */
|
|
3284
3279
|
function truncate(raw) {
|