MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / processMessageRangeToLocal

Method processMessageRangeToLocal

save/save.ts:1010–1062  ·  view source on GitHub ↗
(
    chatId: string,
    startId: number,
    endId: number,
    replyMsg: Api.Message
  )

Source from the content-addressed store, hash-verified

1008 }
1009
1010 private async writeLocalSaveIndex(savedFiles: LocalSavedFile[]): Promise<{ indexPath: string; relativeIndexPath: string } | null> {
1011 if (savedFiles.length === 0) {
1012 return null;
1013 }
1014
1015 const rootDir = this.getLocalSaveRoot();
1016 await fs.mkdir(rootDir, { recursive: true });
1017
1018 const timestamp = new Date().toISOString().replace(/[:.]/g, "-");
1019 const indexPath = this.buildUniquePath(rootDir, `index_${timestamp}.json`);
1020 const groupedChats = new Map<string, { chatTitle: string; items: LocalSavedFile[] }>();
1021
1022 for (const savedFile of savedFiles) {
1023 const current = groupedChats.get(savedFile.sourceChatId) || {
1024 chatTitle: savedFile.sourceChatTitle,
1025 items: [],
1026 };
1027 current.items.push(savedFile);
1028 groupedChats.set(savedFile.sourceChatId, current);
1029 }
1030
1031 const payload = {
1032 generatedAt: new Date().toISOString(),
1033 totalFiles: savedFiles.length,
1034 chats: Array.from(groupedChats.entries()).map(([chatId, group]) => ({
1035 chatId,
1036 chatTitle: group.chatTitle,
1037 count: group.items.length,
1038 files: group.items
1039 .slice()
1040 .sort((a, b) => a.sourceMessageId - b.sourceMessageId)
1041 .map((item) => ({
1042 sourceMessageId: item.sourceMessageId,
1043 sourceLink: item.sourceLink,
1044 mediaType: item.mediaType,
1045 groupedId: item.groupedId || null,
1046 filePath: item.relativeFilePath,
1047 metadataPath: item.relativeMetadataPath,
1048 })),
1049 })),
1050 };
1051
1052 await fs.writeFile(indexPath, JSON.stringify(payload, null, 2), "utf8");
1053 return {
1054 indexPath,
1055 relativeIndexPath: path.relative(process.cwd(), indexPath) || indexPath,
1056 };
1057 }
1058
1059 private async handleCommand(msg: MessageContext): Promise<void> {
1060 try {
1061 const client = await getGlobalClient();
1062 if (!client) {
1063 await this.safeEditMessage(msg, "❌ 客户端未初始化", true);
1064 return;
1065 }

Callers 1

handleCommandMethod · 0.95

Calls 4

safeEditMessageMethod · 0.95
getMessageMethod · 0.95
processMessageToLocalMethod · 0.95
htmlEscapeFunction · 0.70

Tested by

no test coverage detected