Merge branch 'main' into dev

This commit is contained in:
linyuchen 2024-03-25 19:01:34 +08:00
commit 3303b30c4c
5 changed files with 30 additions and 21 deletions

View File

@ -47,7 +47,7 @@ export class NTQQFileApi {
} }
// 上传文件到QQ的文件夹 // 上传文件到QQ的文件夹
static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC) { static async uploadFile(filePath: string, elementType: ElementType = ElementType.PIC, elementSubType: number = 0) {
const md5 = await NTQQFileApi.getFileMd5(filePath); const md5 = await NTQQFileApi.getFileMd5(filePath);
let ext = (await NTQQFileApi.getFileType(filePath))?.ext let ext = (await NTQQFileApi.getFileType(filePath))?.ext
if (ext) { if (ext) {
@ -66,7 +66,7 @@ export class NTQQFileApi {
md5HexStr: md5, md5HexStr: md5,
fileName: fileName, fileName: fileName,
elementType: elementType, elementType: elementType,
elementSubType: 0, elementSubType,
thumbSize: 0, thumbSize: 0,
needCreate: true, needCreate: true,
downloadType: 1, downloadType: 1,
@ -81,7 +81,8 @@ export class NTQQFileApi {
md5, md5,
fileName, fileName,
path: mediaPath, path: mediaPath,
fileSize fileSize,
ext
} }
} }

View File

@ -62,32 +62,32 @@ export class SendMsgElementConstructor {
} }
} }
static async pic(picPath: string, summary: string = ""): Promise<SendPicElement> { static async pic(picPath: string, summary: string = "", subType: 0|1=0): Promise<SendPicElement> {
const {md5, fileName, path, fileSize} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC); const {md5, fileName, path, fileSize, ext} = await NTQQFileApi.uploadFile(picPath, ElementType.PIC, subType);
if (fileSize === 0) { if (fileSize === 0) {
throw "文件异常大小为0"; throw "文件异常大小为0";
} }
const imageSize = await NTQQFileApi.getImageSize(picPath); const imageSize = await NTQQFileApi.getImageSize(picPath);
const picElement = { const picElement = {
md5HexStr: md5, md5HexStr: md5,
fileSize: fileSize, fileSize: fileSize.toString(),
picWidth: imageSize.width, picWidth: imageSize.width,
picHeight: imageSize.height, picHeight: imageSize.height,
fileName: fileName, fileName: md5 + ext,
sourcePath: path, sourcePath: path,
original: true, original: true,
picType: isGIF(picPath) ? PicType.gif : PicType.jpg, picType: isGIF(picPath) ? PicType.gif : PicType.jpg,
picSubType: 0, picSubType: subType,
fileUuid: "", fileUuid: "",
fileSubId: "", fileSubId: "",
thumbFileSize: 0, thumbFileSize: 0,
summary, summary
}; };
log("图片信息", picElement)
return { return {
elementType: ElementType.PIC, elementType: ElementType.PIC,
elementId: "", elementId: "",
picElement picElement,
}; };
} }

View File

@ -49,24 +49,29 @@ export enum PicType {
jpg = 1000 jpg = 1000
} }
export enum PicSubType {
normal = 0, // 普通图片,大图
face = 1 // 表情包小图
}
export interface SendPicElement { export interface SendPicElement {
elementType: ElementType.PIC, elementType: ElementType.PIC,
elementId: "", elementId: "",
picElement: { picElement: {
md5HexStr: string, md5HexStr: string,
fileSize: number, fileSize: number | string,
picWidth: number, picWidth: number,
picHeight: number, picHeight: number,
fileName: string, fileName: string,
sourcePath: string, sourcePath: string,
original: boolean, original: boolean,
picType: PicType, picType: PicType,
picSubType: number, picSubType: PicSubType,
fileUuid: string, fileUuid: string,
fileSubId: string, fileSubId: string,
thumbFileSize: number, thumbFileSize: number,
summary: string, summary: string,
} },
} }
export interface SendReplyElement { export interface SendReplyElement {
@ -248,6 +253,7 @@ export interface MarketFaceElement {
], ],
"apngSupportSize": null "apngSupportSize": null
} }
export interface VideoElement { export interface VideoElement {
"filePath": string, "filePath": string,
"fileName": string, "fileName": string,

View File

@ -2,7 +2,7 @@ import {
AtType, AtType,
ChatType, ChatType,
ElementType, ElementType,
Group, Group, PicSubType,
RawMessage, RawMessage,
SendArkElement, SendArkElement,
SendMessageElement SendMessageElement
@ -188,7 +188,7 @@ export async function createSendElements(messageData: OB11MessageData[], group:
} else if (sendMsg.type === OB11MessageDataType.voice) { } else if (sendMsg.type === OB11MessageDataType.voice) {
sendElements.push(await SendMsgElementConstructor.ptt(path)); sendElements.push(await SendMsgElementConstructor.ptt(path));
} else if (sendMsg.type === OB11MessageDataType.image) { } else if (sendMsg.type === OB11MessageDataType.image) {
sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || "")); sendElements.push(await SendMsgElementConstructor.pic(path, sendMsg.data.summary || "", <PicSubType>parseInt(sendMsg.data?.subType?.toString()) || 0));
} }
} }
} }

View File

@ -1,4 +1,4 @@
import {RawMessage} from "../ntqqapi/types"; import {PicSubType, RawMessage} from "../ntqqapi/types";
import {EventType} from "./event/OB11BaseEvent"; import {EventType} from "./event/OB11BaseEvent";
export interface OB11User { export interface OB11User {
@ -134,11 +134,13 @@ interface OB11MessageFileBase {
} }
} }
export interface OB11MessageImage extends OB11MessageFileBase { export interface OB11MessageImage extends OB11MessageFileBase {
type: OB11MessageDataType.image type: OB11MessageDataType.image
data: OB11MessageFileBase['data'] & { data: OB11MessageFileBase['data'] & {
summary ? : string; // 图片摘要 summary ? : string; // 图片摘要
} subType?: PicSubType
},
} }
export interface OB11MessageRecord extends OB11MessageFileBase { export interface OB11MessageRecord extends OB11MessageFileBase {