feat: Support custom filename and cover image for Flash Transfer (#1544)

* feat: support thumbnail for flash-transfer

* fix: fix get thumbnail path unknown type error

* Refactor flash module types and enums

Standardized TypeScript interface property formatting in flash.ts, flash data, and wrapper files. Introduced the UploadSceneType enum for upload scene types, replacing hardcoded numeric values. Improved type annotations and consistency across the flash API and related data structures.

* Update arg type in NodeQQNTWrapperUtil interface

Changed the type of the 'arg' parameter in the NodeQQNTWrapperUtil interface from optional number to 'number | null | undefined' for improved type clarity.

* Refactor flash scene type and update method params

Introduced BusiScene enum for sceneType in FileListInfoRequests to improve type safety. Renamed parameters in getFileThumbSavePathForSend for better clarity.

* Refactor downloadSceneType to use enum type

Replaced numeric downloadSceneType fields with the DownloadSceneType enum in relevant interfaces. Updated NodeIKernelFlashTransferService method signatures to use DownloadSceneType for download operations, improving type safety and code clarity.

* refactor: remove thumbnail dependency for QQ resource icons

* fix: remove useless console.log

---------

Co-authored-by: 手瓜一十雪 <nanaeonn@outlook.com>
This commit is contained in:
H3CoF6and手瓜一十雪 authored and GitHub committed 2026-01-25 09:51:43 +08:00
1 parent 0c358b111c
commit 3b99eb9658
7 files changed
+257 -127

No files matched your search

+48 -5
View File
@@ -4,6 +4,7 @@ import {
FileListResponse, FileListResponse,
FlashFileSetInfo, FlashFileSetInfo,
SendStatus, SendStatus,
UploadSceneType,
} from '@/napcat-core/data/flash'; } from '@/napcat-core/data/flash';
import { Peer } from '@/napcat-core/types'; import { Peer } from '@/napcat-core/types';
@@ -19,8 +20,10 @@ export class NTQQFlashApi {
/** /**
* 发起闪传上传任务 * 发起闪传上传任务
* @param fileListToUpload 上传文件绝对路径的列表,可以是文件夹!! * @param fileListToUpload 上传文件绝对路径的列表,可以是文件夹!!
* @param thumbnailPath
* @param filesetName
*/ */
async createFlashTransferUploadTask (fileListToUpload: string[]): Promise < GeneralCallResult & { async createFlashTransferUploadTask (fileListToUpload: string[], thumbnailPath: string, filesetName: string): Promise<GeneralCallResult & {
createFlashTransferResult: createFlashTransferResult; createFlashTransferResult: createFlashTransferResult;
seq: number; seq: number;
}> { }> {
@@ -31,13 +34,30 @@ export class NTQQFlashApi {
const fileUploadArg = { const fileUploadArg = {
screen: 1, // 1 screen: 1, // 1
name: filesetName,
uploaders: [{ uploaders: [{
uin: selfInfo.uin, uin: selfInfo.uin,
uid: selfInfo.uid, uid: selfInfo.uid,
sendEntrance: '', sendEntrance: '',
nickname: selfInfo.nick, nickname: selfInfo.nick,
}], }],
coverPath: thumbnailPath,
paths: fileListToUpload, paths: fileListToUpload,
excludePaths: [],
expireLeftTime: 0,
isNeedDelDeviceInfo: false,
isNeedDelLocation: false,
coverOriginalInfos: [
{
path: fileListToUpload[0] || '',
thumbnailPath,
},
],
uploadSceneType: UploadSceneType.KUPLOADSCENEAIOFILESELECTOR, // 不知道怎么枚举 先硬编码吧 (PC QQ 10)
detectPrivacyInfoResult: {
exists: false,
allDetectResults: new Map(),
},
}; };
const uploadResult = await flashService.createFlashTransferUploadTask(timestamp, fileUploadArg); const uploadResult = await flashService.createFlashTransferUploadTask(timestamp, fileUploadArg);
@@ -55,7 +75,7 @@ export class NTQQFlashApi {
* @param fileSetId * @param fileSetId
*/ */
async downloadFileSetBySetId (fileSetId: string): Promise<GeneralCallResult & { async downloadFileSetBySetId (fileSetId: string): Promise<GeneralCallResult & {
extraInfo: unknown extraInfo: unknown;
}> { }> {
const flashService = this.context.session.getFlashTransferService(); const flashService = this.context.session.getFlashTransferService();
@@ -182,8 +202,8 @@ export class NTQQFlashApi {
errCode: number, errCode: number,
errMsg: string, errMsg: string,
rsp: { rsp: {
sendStatus: SendStatus[] sendStatus: SendStatus[];
} };
}> { }> {
const flashService = this.context.session.getFlashTransferService(); const flashService = this.context.session.getFlashTransferService();
@@ -212,7 +232,7 @@ export class NTQQFlashApi {
* @param fileSetId * @param fileSetId
* @param options * @param options
*/ */
async getFileTransUrl (fileSetId: string, options: { fileName?: string; fileIndex?: number }): Promise < GeneralCallResult & { async getFileTransUrl (fileSetId: string, options: { fileName?: string; fileIndex?: number; }): Promise<GeneralCallResult & {
transferUrl: string; transferUrl: string;
}> { }> {
const flashService = this.context.session.getFlashTransferService(); const flashService = this.context.session.getFlashTransferService();
@@ -261,4 +281,27 @@ export class NTQQFlashApi {
}; };
} }
} }
async createFileThumbnail (filePath: string): Promise<any> {
const msgService = this.context.session.getMsgService();
const savePath = msgService.getFileThumbSavePathForSend(750, true);
const result = await this.core.util.createThumbnailImage(
'flashtransfer',
filePath,
savePath,
{
width: 520,
height: 520,
},
'jpeg',
null
);
if (result.result === 0) {
this.context.logger.log('获取缩略图成功!!');
result.targetPath = savePath;
return result;
}
return result;
}
} }
+134 -100
View File
@@ -1,5 +1,5 @@
export interface FlashBaseRequest { export interface FlashBaseRequest {
fileSetId: string fileSetId: string;
} }
export interface UploaderInfo { export interface UploaderInfo {
@@ -19,14 +19,14 @@ export interface thumbnailInfo {
} }
export interface SendTarget { export interface SendTarget {
destType: number // 1私聊 destType: number; // 1私聊
destUin?: string, destUin?: string,
destUid: string, destUid: string,
} }
export interface SendTargetRequests { export interface SendTargetRequests {
fileSetId: string fileSetId: string;
targets: SendTarget[] targets: SendTarget[];
} }
export interface DownloadStatusInfo { export interface DownloadStatusInfo {
@@ -53,13 +53,13 @@ export interface DownloadStatusInfo {
isAllFileAlreadyDownloaded: boolean, isAllFileAlreadyDownloaded: boolean,
saveFileSetDir: string, saveFileSetDir: string,
allWaitingStatusTask: boolean, allWaitingStatusTask: boolean,
downloadSceneType: number, downloadSceneType: DownloadSceneType,
retryCount: number, retryCount: number,
statisticInfo: { statisticInfo: {
downloadTaskId: string, downloadTaskId: string,
downloadFilesetName: string, downloadFilesetName: string,
downloadFileTypeDistribution: string, downloadFileTypeDistribution: string,
downloadFileSizeDistribution: string downloadFileSizeDistribution: string;
}, },
albumStorageFailImageNum: number, albumStorageFailImageNum: number,
albumStorageFailVideoNum: number, albumStorageFailVideoNum: number,
@@ -67,8 +67,8 @@ export interface DownloadStatusInfo {
albumStorageSucImageNum: number, albumStorageSucImageNum: number,
albumStorageSucVideoNum: number, albumStorageSucVideoNum: number,
albumStorageSucFileIdList: [], albumStorageSucFileIdList: [],
albumStorageFileNum: number albumStorageFileNum: number;
} };
} }
export interface physicalInfo { export interface physicalInfo {
@@ -95,94 +95,94 @@ export interface uploadInfo {
svrRrrCode: number, svrRrrCode: number,
errMsg: string, errMsg: string,
isNeedDelDeviceInfo: boolean, isNeedDelDeviceInfo: boolean,
thumbnailUploadState: number thumbnailUploadState: number;
isSecondHit: boolean, isSecondHit: boolean,
hasModifiedErr: boolean, hasModifiedErr: boolean,
} }
export interface folderUploadInfo { export interface folderUploadInfo {
totalUploadedFileSize: string totalUploadedFileSize: string;
successCount: number successCount: number;
failedCount: number failedCount: number;
} }
export interface folderDownloadInfo { export interface folderDownloadInfo {
totalDownloadedFileSize: string totalDownloadedFileSize: string;
totalFileSize: string totalFileSize: string;
totalDownloadFileCount: number totalDownloadFileCount: number;
successCount: number successCount: number;
failedCount: number failedCount: number;
pausedCount: number pausedCount: number;
cancelCount: number cancelCount: number;
downloadingCount: number downloadingCount: number;
partialDownloadCount: number partialDownloadCount: number;
curLevelDownloadedFileCount: number curLevelDownloadedFileCount: number;
curLevelUnDownloadedFileCount: number curLevelUnDownloadedFileCount: number;
} }
export interface compressFileFolderInfo { export interface compressFileFolderInfo {
downloadStatus: number downloadStatus: number;
saveFileDirPath: string saveFileDirPath: string;
totalFileCount: string totalFileCount: string;
totalFileSize: string totalFileSize: string;
} }
export interface albumStorgeInfo { export interface albumStorgeInfo {
status: number status: number;
localIdentifier: string localIdentifier: string;
errorCode: number errorCode: number;
timeCost: number timeCost: number;
} }
export interface FlashOneFileInfo { export interface FlashOneFileInfo {
fileSetId: string fileSetId: string;
cliFileId: string // client?? 或许可以换取url cliFileId: string; // client?? 或许可以换取url
compressedFileFolderId: string compressedFileFolderId: string;
archiveIndex: 0 archiveIndex: 0;
indexPath: string indexPath: string;
isDir: boolean // 文件或者文件夹!! isDir: boolean; // 文件或者文件夹!!
parentId: string parentId: string;
depth: number // 1 depth: number; // 1
cliFileIndex: number cliFileIndex: number;
fileType: number // 枚举!! 已完成枚举!! fileType: number; // 枚举!! 已完成枚举!!
name: string name: string;
namePinyin: string namePinyin: string;
isCover: boolean isCover: boolean;
isCoverOriginal: boolean isCoverOriginal: boolean;
fileSize: string fileSize: string;
fileCount: number fileCount: number;
thumbnail: thumbnailInfo thumbnail: thumbnailInfo;
physical: physicalInfo physical: physicalInfo;
srvFileId: string // service?? 服务器上面的id吗? srvFileId: string; // service?? 服务器上面的id吗?
srvParentFileId: string srvParentFileId: string;
svrLastUpdateTimestamp: string svrLastUpdateTimestamp: string;
downloadInfo: downloadInfo downloadInfo: downloadInfo;
saveFilePath: string saveFilePath: string;
search_relative_path: string search_relative_path: string;
disk_relative_path: string disk_relative_path: string;
uploadInfo: uploadInfo uploadInfo: uploadInfo;
status: number status: number;
uploadStatus: number // 3已上传成功 uploadStatus: number; // 3已上传成功
downloadStatus: number // 0未下载 downloadStatus: number; // 0未下载
folderUploadInfo: folderUploadInfo folderUploadInfo: folderUploadInfo;
folderDownloadInfo: folderDownloadInfo folderDownloadInfo: folderDownloadInfo;
sha1: string sha1: string;
bookmark: string bookmark: string;
compressFileFolderInfo: compressFileFolderInfo compressFileFolderInfo: compressFileFolderInfo;
uploadPauseReason: string uploadPauseReason: string;
downloadPauseReason: string downloadPauseReason: string;
filePhysicalSize: string filePhysicalSize: string;
thumbnail_sha1: string | null thumbnail_sha1: string | null;
thumbnail_size: string | null thumbnail_size: string | null;
needAlbumStorage: boolean needAlbumStorage: boolean;
albumStorageInfo: albumStorgeInfo albumStorageInfo: albumStorgeInfo;
} }
export interface fileListsInfo { export interface fileListsInfo {
parentId: string, parentId: string,
depth: number, // 1 depth: number, // 1
fileList: FlashOneFileInfo[], fileList: FlashOneFileInfo[],
paginationInfo: {} paginationInfo: {};
isEnd: boolean, isEnd: boolean,
isCache: boolean, isCache: boolean,
} }
@@ -200,30 +200,50 @@ export interface createFlashTransferResult {
expireTime: string, expireTime: string,
expireLeftTime: string, expireLeftTime: string,
} }
export enum UploadSceneType {
KUPLOADSCENEUNKNOWN,
KUPLOADSCENEFLOATWINDOWRIGHTCLICKMENU,
KUPLOADSCENEFLOATWINDOWDRAG,
KUPLOADSCENEFLOATWINDOWFILESELECTOR,
KUPLOADSCENEFLOATWINDOWSHORTCUTKEYCTRLCV,
KUPLOADSCENEH5LAUNCHCLIENTRIGHTCLICKMENU,
KUPLOADSCENEH5LAUNCHCLIENTDRAG,
KUPLOADSCENEH5LAUNCHCLIENTFILESELECTOR,
KUPLOADSCENEH5LAUNCHCLIENTSHORTCUTKEYCTRLCV,
KUPLOADSCENEAIODRAG,
KUPLOADSCENEAIOFILESELECTOR,
KUPLOADSCENEAIOSHORTCUTKEYCTRLCV
}
export interface StartFlashTaskRequests { export interface StartFlashTaskRequests {
screen?: number; // 1 PC-QQ screen: number; // 1 PC-QQ
name?: string;
uploaders: UploaderInfo[]; uploaders: UploaderInfo[];
permission?: {}; permission?: {};
coverPath?: string; coverPath?: string;
paths: string[]; // 文件的绝对路径,可以是文件夹 paths: string[]; // 文件的绝对路径,可以是文件夹
// excludePaths: []; excludePaths?: string[];
// expireLeftTime: 0, expireLeftTime?: number, // 0
// isNeedDelDeviceInfo: boolean, isNeedDelDeviceInfo: boolean,
// isNeedDelLocation: boolean, isNeedDelLocation: boolean,
// coverOriginalInfos: [], coverOriginalInfos?: {
// uploadSceneType: 10, // 不知道怎么枚举 先硬编码吧 path: string,
// detectPrivacyInfoResult: { thumbnailPath: string,
// exists: boolean, }[],
// allDetectResults: {} uploadSceneType: UploadSceneType, // 不知道怎么枚举 先硬编码吧 (PC QQ 10)
// } detectPrivacyInfoResult: {
exists: boolean,
allDetectResults: {};
};
}
export enum BusiScene {
KBUSISCENEINVALID,
KBUSISCENEFLASHSCENE
} }
export interface FileListInfoRequests { export interface FileListInfoRequests {
seq: number, // 0 seq: number, // 0
fileSetId: string, fileSetId: string,
isUseCache: boolean, isUseCache: boolean,
sceneType: number, // 1 sceneType: BusiScene, // 1
reqInfos: { reqInfos: {
count: number, // 18 ?? 硬编码吧 不懂 count: number, // 18 ?? 硬编码吧 不懂
paginationInfo: {}, paginationInfo: {},
@@ -238,10 +258,24 @@ export interface FileListInfoRequests {
sortField: number, sortField: number,
sortOrder: number, sortOrder: number,
}[], }[],
isNeedPhysicalInfoReady: boolean isNeedPhysicalInfoReady: boolean;
}[] }[];
}
export enum DownloadSceneType {
KDOWNLOADSCENEUNKNOWN,
KDOWNLOADSCENEARKC2C,
KDOWNLOADSCENEARKC2CDETAILPAGE,
KDOWNLOADSCENEARKGROUP,
KDOWNLOADSCENEARKGROUPDETAILPAGE,
KDOWNLOADSCENELINKC2C,
KDOWNLOADSCENELINKGROUP,
KDOWNLOADSCENELINKCHANNEL,
KDOWNLOADSCENELINKTEMPCHAT,
KDOWNLOADSCENELINKOTHERINQQ,
KDOWNLOADSCENESCANQRCODE,
KDWONLOADSCENEFLASHTRANSFERCENTERCLIENT,
KDWONLOADSCENEFLASHTRANSFERCENTERSCHEMA
} }
export interface FlashFileSetInfo { export interface FlashFileSetInfo {
fileSetId: string, fileSetId: string,
name: string, name: string,
@@ -258,23 +292,23 @@ export interface FlashFileSetInfo {
urls: [ urls: [
{ {
spec: number, // 2 spec: number, // 2
url: string url: string;
} }
], ],
localCachePath: string localCachePath: string;
}, },
uploaders: [ uploaders: [
{ {
uin: string, uin: string,
nickname: string, nickname: string,
uid: string, uid: string,
sendEntrance: string sendEntrance: string;
} }
], ],
expireLeftTime: number, expireLeftTime: number,
aiClusteringStatus: { aiClusteringStatus: {
firstClusteringList: [], firstClusteringList: [],
shouldPull: boolean shouldPull: boolean;
}, },
createTime: number, createTime: number,
expireTime: number, expireTime: number,
@@ -284,7 +318,7 @@ export interface FlashFileSetInfo {
uploadInfo: { uploadInfo: {
totalUploadedFileSize: number, totalUploadedFileSize: number,
successCount: number, successCount: number,
failedCount: number failedCount: number;
}, },
downloadInfo: { downloadInfo: {
totalDownloadedFileSize: 0, totalDownloadedFileSize: 0,
@@ -296,7 +330,7 @@ export interface FlashFileSetInfo {
cancelCount: 0, cancelCount: 0,
status: 0, status: 0,
curLevelDownloadedFileCount: number, curLevelDownloadedFileCount: number,
curLevelUnDownloadedFileCount: 0 curLevelUnDownloadedFileCount: 0;
}, },
transferType: number, transferType: number,
isLocalCreate: true, isLocalCreate: true,
@@ -306,12 +340,12 @@ export interface FlashFileSetInfo {
downloadStatus: 0, downloadStatus: 0,
downloadPauseReason: 0, downloadPauseReason: 0,
saveFileSetDir: string, saveFileSetDir: string,
uploadSceneType: 10, uploadSceneType: UploadSceneType,
downloadSceneType: 0, // 0 PC-QQ 103 web downloadSceneType: DownloadSceneType, // 0 PC-QQ 103 web
retryCount: number, retryCount: number,
isMergeShareUpload: 0, isMergeShareUpload: 0,
isRemoveDeviceInfo: boolean, isRemoveDeviceInfo: boolean,
isRemoveLocation: boolean isRemoveLocation: boolean;
} }
export interface SendStatus { export interface SendStatus {
@@ -320,5 +354,5 @@ export interface SendStatus {
target: { target: {
destType: number, destType: number,
destUid: string, destUid: string,
} };
} }
+1
View File
@@ -74,6 +74,7 @@ export function loadQQWrapper (execPath: string | undefined, QQVersion: string):
} }
const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi }; const nativemodule: { exports: WrapperNodeApi; } = { exports: {} as WrapperNodeApi };
process.dlopen(nativemodule, wrapperNodePath); process.dlopen(nativemodule, wrapperNodePath);
process.env['NAPCAT_WRAPPER_PATH'] = wrapperNodePath;
return nativemodule.exports; return nativemodule.exports;
} }
export function getMajorPath (execPath: string, QQVersion: string): string { export function getMajorPath (execPath: string, QQVersion: string): string {
@@ -10,6 +10,7 @@ import {
DownloadStatusInfo, DownloadStatusInfo,
SendTargetRequests, SendTargetRequests,
FlashOneFileInfo, FlashOneFileInfo,
DownloadSceneType,
} from '../data/flash'; } from '../data/flash';
export interface NodeIKernelFlashTransferService { export interface NodeIKernelFlashTransferService {
@@ -134,23 +135,23 @@ export interface NodeIKernelFlashTransferService {
/** /**
* 开始下载file set的函数 同开始上传 * 开始下载file set的函数 同开始上传
* @param fileSetId * @param fileSetId
* @param chatType 聊天类型 //因为没有peer,其实可以硬编码为1 (好友私聊) * @param downloadSceneType 下载类型 //因为没有peer,其实可以硬编码为1 (好友私聊)
* @param arg // 默认为false * @param arg // 默认为false
*/ */
startFileSetDownload(fileSetId:string, chatType: number, arg: { isIncludeCompressInnerFiles: boolean }): Promise < GeneralCallResult & { startFileSetDownload (fileSetId: string, downloadSceneType: DownloadSceneType, downloadOptionParams: { isIncludeCompressInnerFiles: boolean; }): Promise<GeneralCallResult & {
extraInfo: 0 extraInfo: 0;
}>; // 3 arg }>; // 3 arg
stopFileSetDownload(fileSetId: string, arg1: { isIncludeCompressInnerFiles: boolean }): Promise < GeneralCallResult & { stopFileSetDownload (fileSetId: string, downloadOptionParams: { isIncludeCompressInnerFiles: boolean; }): Promise<GeneralCallResult & {
extraInfo: 0 extraInfo: 0;
}>; // 2 arg 结束不可重启!! }>; // 2 arg 结束不可重启!!
pauseFileSetDownload(fileSetId: string, arg1: { isIncludeCompressInnerFiles: boolean }): Promise < GeneralCallResult & { pauseFileSetDownload (fileSetId: string, downloadOptionParams: { isIncludeCompressInnerFiles: boolean; }): Promise<GeneralCallResult & {
extraInfo: 0 extraInfo: 0;
}>; // 2 arg }>; // 2 arg
resumeFileSetDownload(fileSetId: string, arg1: { isIncludeCompressInnerFiles: boolean }): Promise < GeneralCallResult & { resumeFileSetDownload (fileSetId: string, downloadOptionParams: { isIncludeCompressInnerFiles: boolean; }): Promise<GeneralCallResult & {
extraInfo: 0 extraInfo: 0;
}>; // 2 arg }>; // 2 arg
startFileListDownLoad (...args: unknown[]): unknown; // 4 arg // 大概率是选择set里面的部分文件进行下载,没必要,不想写 startFileListDownLoad (...args: unknown[]): unknown; // 4 arg // 大概率是选择set里面的部分文件进行下载,没必要,不想写
@@ -170,7 +171,7 @@ export interface NodeIKernelFlashTransferService {
startFileTransferUrl (fileInfo: FlashOneFileInfo): Promise<{ startFileTransferUrl (fileInfo: FlashOneFileInfo): Promise<{
ret: number, ret: number,
url: string, url: string,
expireTimestampSeconds: string expireTimestampSeconds: string;
}>; // 1 arg }>; // 1 arg
startFileListDownLoadBySessionId (...args: unknown[]): unknown; // 2 arg startFileListDownLoadBySessionId (...args: unknown[]): unknown; // 2 arg
@@ -206,8 +207,8 @@ export interface NodeIKernelFlashTransferService {
errCode: number, errCode: number,
errMsg: string, errMsg: string,
rsp: { rsp: {
sendStatus: SendStatus[] sendStatus: SendStatus[];
} };
}>; // 1 arg 估计是file set id }>; // 1 arg 估计是file set id
addFlashTransferTaskInfoListener (...args: unknown[]): unknown; // 1 arg addFlashTransferTaskInfoListener (...args: unknown[]): unknown; // 1 arg
@@ -222,8 +223,8 @@ export interface NodeIKernelFlashTransferService {
result: number; result: number;
errMs: string; errMs: string;
fileSetId: string; fileSetId: string;
fileList: [] fileList: [];
} };
}>; // 1 arg }>; // 1 arg
getLocalFileListByStatuses (...args: unknown[]): unknown; // 1 arg getLocalFileListByStatuses (...args: unknown[]): unknown; // 1 arg
@@ -336,7 +336,7 @@ export interface NodeIKernelMsgService {
assembleMobileQQRichMediaFilePath (...args: unknown[]): unknown; assembleMobileQQRichMediaFilePath (...args: unknown[]): unknown;
getFileThumbSavePathForSend (...args: unknown[]): unknown; getFileThumbSavePathForSend (thumbSize: number, createNeed: boolean): string;
getFileThumbSavePath (...args: unknown[]): unknown; getFileThumbSavePath (...args: unknown[]): unknown;
+17 -4
View File
@@ -1,5 +1,6 @@
import { NodeIDependsAdapter, NodeIDispatcherAdapter, NodeIGlobalAdapter } from './adapters'; import { NodeIDependsAdapter, NodeIDispatcherAdapter, NodeIGlobalAdapter } from './adapters';
import { import {
GeneralCallResult,
NodeIKernelAvatarService, NodeIKernelAvatarService,
NodeIKernelBuddyService, NodeIKernelBuddyService,
NodeIKernelGroupService, NodeIKernelGroupService,
@@ -27,7 +28,7 @@ import { NodeIKernelMSFService } from './services/NodeIKernelMSFService';
import { NodeIkernelTestPerformanceService } from './services/NodeIkernelTestPerformanceService'; import { NodeIkernelTestPerformanceService } from './services/NodeIkernelTestPerformanceService';
import { NodeIKernelECDHService } from './services/NodeIKernelECDHService'; import { NodeIKernelECDHService } from './services/NodeIKernelECDHService';
import { NodeIO3MiscService } from './services/NodeIO3MiscService'; import { NodeIO3MiscService } from './services/NodeIO3MiscService';
import { NodeIKernelFlashTransferService } from "./services/NodeIKernelFlashTransferService"; import { NodeIKernelFlashTransferService } from './services/NodeIKernelFlashTransferService';
export interface NodeQQNTWrapperUtil { export interface NodeQQNTWrapperUtil {
get (): NodeQQNTWrapperUtil; get (): NodeQQNTWrapperUtil;
@@ -80,7 +81,7 @@ export interface NodeQQNTWrapperUtil {
runProcess (arg0: string, arg1: boolean): unknown; runProcess (arg0: string, arg1: boolean): unknown;
runProcessArgs(arg0: string, arg1: { [key: string]: string }, arg2: boolean): unknown; runProcessArgs (arg0: string, arg1: { [key: string]: string; }, arg2: boolean): unknown;
calcThumbSize (arg0: number, arg1: number, arg2: unknown): unknown; calcThumbSize (arg0: number, arg1: number, arg2: unknown): unknown;
@@ -139,6 +140,18 @@ export interface NodeQQNTWrapperUtil {
getNvidiaDriverVersion (): unknown; getNvidiaDriverVersion (): unknown;
isNull (): unknown; isNull (): unknown;
createThumbnailImage (
serviceName: string,
filePath: string,
targetPath: string,
imgSize: {
width: number,
height: number;
},
fileFormat: string,
arg: number | null | undefined, // null undefined都行
): Promise<GeneralCallResult & { targetPath?: string; }>;
} }
export interface NodeIQQNTStartupSessionWrapper { export interface NodeIQQNTStartupSessionWrapper {
create (): NodeIQQNTStartupSessionWrapper; create (): NodeIQQNTStartupSessionWrapper;
@@ -271,7 +284,7 @@ export interface EnginInitDesktopConfig {
global_path_config: { global_path_config: {
desktopGlobalPath: string; desktopGlobalPath: string;
}; };
thumb_config: { maxSide: 324; minSide: 48; longLimit: 6; density: 2 }; thumb_config: { maxSide: 324; minSide: 48; longLimit: 6; density: 2; };
} }
export interface NodeIQQNTWrapperEngine { export interface NodeIQQNTWrapperEngine {
@@ -284,7 +297,7 @@ export interface WrapperNodeApi {
NodeIO3MiscService: NodeIO3MiscService; NodeIO3MiscService: NodeIO3MiscService;
NodeQQNTWrapperUtil: NodeQQNTWrapperUtil; NodeQQNTWrapperUtil: NodeQQNTWrapperUtil;
NodeIQQNTWrapperSession: NodeIQQNTWrapperSession; NodeIQQNTWrapperSession: NodeIQQNTWrapperSession;
NodeIQQNTStartupSessionWrapper: NodeIQQNTStartupSessionWrapper NodeIQQNTStartupSessionWrapper: NodeIQQNTStartupSessionWrapper;
NodeIQQNTWrapperEngine: NodeIQQNTWrapperEngine; NodeIQQNTWrapperEngine: NodeIQQNTWrapperEngine;
NodeIKernelLoginService: NodeIKernelLoginService; NodeIKernelLoginService: NodeIKernelLoginService;
@@ -1,6 +1,12 @@
import { OneBotAction } from '@/napcat-onebot/action/OneBotAction'; import { OneBotAction } from '@/napcat-onebot/action/OneBotAction';
import { ActionName } from '@/napcat-onebot/action/router'; import { ActionName } from '@/napcat-onebot/action/router';
import { Static, Type } from '@sinclair/typebox'; import { Static, Type, Optional } from '@sinclair/typebox';
import path from 'node:path';
const richMediaList = [
'.mp4', '.mov', '.avi', '.wmv', '.mpeg', '.mpg', '.flv', '.mkv',
'.png', '.gif', '.jpg', '.jpeg', '.webp', '.bmp',
];
// 不全部使用json因为:一个文件解析Form-data会变字符串!!! 但是api文档就写List // 不全部使用json因为:一个文件解析Form-data会变字符串!!! 但是api文档就写List
const SchemaData = Type.Object({ const SchemaData = Type.Object({
@@ -8,6 +14,8 @@ const SchemaData = Type.Object({
Type.Array(Type.String()), Type.Array(Type.String()),
Type.String(), Type.String(),
]), ]),
name: Optional(Type.String()),
thumb_path: Optional(Type.String()),
}); });
type Payload = Static<typeof SchemaData>; type Payload = Static<typeof SchemaData>;
@@ -16,9 +24,39 @@ export class CreateFlashTask extends OneBotAction<Payload, unknown> {
override payloadSchema = SchemaData; override payloadSchema = SchemaData;
async _handle (payload: Payload) { async _handle (payload: Payload) {
// todo fileset的名字和缩略图还没实现!!
const fileList = Array.isArray(payload.files) ? payload.files : [payload.files]; const fileList = Array.isArray(payload.files) ? payload.files : [payload.files];
let thumbPath: string = '';
return await this.core.apis.FlashApi.createFlashTransferUploadTask(fileList); if (fileList.length === 1) {
// 我是真没hook到那种合并的缩略图是哪个方法产生的,暂时不实现(怀疑是js直接canvas渲染的!!) // 确认了猜想
const filePath = fileList[0];
if (filePath === undefined) {
return {};
}
const ext = path.extname(filePath).toLowerCase();
if (richMediaList.includes(ext)) {
try {
const res = await this.core.apis.FlashApi.createFileThumbnail(filePath);
if (res && typeof res === 'object' && 'result' in res && res.result === 0) {
thumbPath = res.targetPath as string;
}
} catch (_e) {
}
}
}
function toPlatformPath (inputPath: string) {
const unifiedPath = inputPath.replace(/[\\/]/g, path.sep);
return path.normalize(unifiedPath);
}
let normalPath: string;
if (payload.thumb_path !== undefined) {
normalPath = path.normalize(payload.thumb_path);
} else {
normalPath = toPlatformPath(thumbPath);
}
return await this.core.apis.FlashApi.createFlashTransferUploadTask(fileList, normalPath, payload.name || '');
} }
} }