feat: upload private file

This commit is contained in:
linyuchen 2024-04-25 23:27:14 +08:00
parent ac852cc382
commit 05f0985f7f

View File

@ -1,27 +1,32 @@
import BaseAction from "../BaseAction";
import {getGroup} from "../../../common/data";
import {getGroup, getUidByUin} from "../../../common/data";
import {ActionName} from "../types";
import {SendMsgElementConstructor} from "../../../ntqqapi/constructor";
import {ChatType, SendFileElement} from "../../../ntqqapi/types";
import fs from "fs";
import {NTQQMsgApi} from "../../../ntqqapi/api/msg";
import {NTQQMsgApi, Peer} from "../../../ntqqapi/api/msg";
import {uri2local} from "../../../common/utils";
interface Payload{
group_id: number
user_id: number
group_id?: number
file: string
name: string
folder: string
}
export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
class GoCQHTTPUploadFileBase extends BaseAction<Payload, null> {
actionName = ActionName.GoCQHTTP_UploadGroupFile
protected async _handle(payload: Payload): Promise<null> {
const group = await getGroup(payload.group_id.toString());
if (!group){
throw new Error(`群组${payload.group_id}不存在`)
getPeer(payload: Payload): Peer {
if (payload.user_id){
return {chatType: ChatType.friend, peerUid: getUidByUin(payload.user_id.toString())}
}
return {chatType: ChatType.group, peerUid: payload.group_id.toString()}
}
protected async _handle(payload: Payload): Promise<null> {
let file = payload.file;
if (fs.existsSync(file)){
file = `file://${file}`
@ -31,7 +36,16 @@ export default class GoCQHTTPUploadGroupFile extends BaseAction<Payload, null> {
throw new Error(downloadResult.errMsg)
}
let sendFileEle: SendFileElement = await SendMsgElementConstructor.file(downloadResult.path, payload.name);
await NTQQMsgApi.sendMsg({chatType: ChatType.group, peerUid: group.groupCode}, [sendFileEle]);
await NTQQMsgApi.sendMsg(this.getPeer(payload), [sendFileEle]);
return null
}
}
export class GoCQHTTPUploadGroupFile extends GoCQHTTPUploadFileBase {
actionName = ActionName.GoCQHTTP_UploadGroupFile
}
export class GoCQHTTPUploadPrivateFile extends GoCQHTTPUploadFileBase {
actionName = ActionName.GoCQHTTP_UploadPrivateFile
}