build: fix2

This commit is contained in:
手瓜一十雪 2024-09-11 23:40:05 +08:00
parent 374fc64427
commit f312368df2
4 changed files with 21 additions and 5 deletions

View File

@ -242,7 +242,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und
const filenameTemp = tempName + fileExt; const filenameTemp = tempName + fileExt;
const filePath = path.join(dir, filenameTemp); const filePath = path.join(dir, filenameTemp);
fs.copyFileSync(HandledUri, filePath); fs.copyFileSync(HandledUri, filePath);
console.log('复制文件到临时文件', HandledUri, filePath); //console.log('复制文件到临时文件', HandledUri, filePath);
return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath }; return { success: true, errMsg: '', fileName: filename, ext: fileExt, path: filePath };
} }
//接下来都要有文件名 //接下来都要有文件名
@ -250,7 +250,7 @@ export async function uri2local(dir: string, uri: string, filename: string | und
if (UriType == FileUriType.Remote) { if (UriType == FileUriType.Remote) {
const pathInfo = path.parse(decodeURIComponent(new URL(HandledUri).pathname)); const pathInfo = path.parse(decodeURIComponent(new URL(HandledUri).pathname));
if (pathInfo.name) { if (pathInfo.name) {
filename = pathInfo.name; filename = pathInfo.name.substring(0, 50);//过长截断
if (pathInfo.ext) { if (pathInfo.ext) {
filename += pathInfo.ext; filename += pathInfo.ext;
} }

View File

@ -4,6 +4,8 @@ import { ChatType, Peer, SendFileElement } from '@/core/entities';
import fs from 'fs'; import fs from 'fs';
import { uri2local } from '@/common/file'; import { uri2local } from '@/common/file';
import { FromSchema, JSONSchema } from 'json-schema-to-ts'; import { FromSchema, JSONSchema } from 'json-schema-to-ts';
import { MessageContext } from '@/onebot/api';
import { ContextMode, createContext } from '../msg/SendMsg';
const SchemaData = { const SchemaData = {
type: 'object', type: 'object',
@ -42,7 +44,15 @@ export default class GoCQHTTPUploadPrivateFile extends BaseAction<Payload, null>
if (!downloadResult.success) { if (!downloadResult.success) {
throw new Error(downloadResult.errMsg); throw new Error(downloadResult.errMsg);
} }
const sendFileEle: SendFileElement = await this.core.apis.FileApi.createValidSendFileElement(downloadResult.path, payload.name);
let msgContext: MessageContext = {
peer: await createContext(this.core, {
user_id: payload.user_id.toString(),
group_id: undefined,
}, ContextMode.Private),
deleteAfterSentFiles: []
}
const sendFileEle: SendFileElement = await this.core.apis.FileApi.createValidSendFileElement(msgContext, downloadResult.path, payload.name);
await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(await this.getPeer(payload), [sendFileEle], [], true); await this.obContext.apis.MsgApi.sendMsgWithOb11UniqueId(await this.getPeer(payload), [sendFileEle], [], true);
return null; return null;
} }

View File

@ -3,6 +3,7 @@ import {
OB11MessageDataType, OB11MessageDataType,
OB11MessageMixType, OB11MessageMixType,
OB11MessageNode, OB11MessageNode,
OB11PostContext,
OB11PostSendMsg, OB11PostSendMsg,
} from '@/onebot/types'; } from '@/onebot/types';
import { ActionName, BaseCheckResult } from '@/onebot/action/types'; import { ActionName, BaseCheckResult } from '@/onebot/action/types';
@ -30,7 +31,7 @@ export function normalize(message: OB11MessageMixType, autoEscape = false): OB11
) : Array.isArray(message) ? message : [message]; ) : Array.isArray(message) ? message : [message];
} }
export async function createContext(core: NapCatCore, payload: OB11PostSendMsg, contextMode: ContextMode): Promise<Peer> { export async function createContext(core: NapCatCore, payload: OB11PostContext, contextMode: ContextMode): Promise<Peer> {
// This function determines the type of message by the existence of user_id / group_id, // This function determines the type of message by the existence of user_id / group_id,
// not message_type. // not message_type.
// This redundant design of Ob11 here should be blamed. // This redundant design of Ob11 here should be blamed.

View File

@ -208,3 +208,8 @@ export interface OB11PostSendMsg {
messages?: OB11MessageMixType; // 兼容 go-cqhttp messages?: OB11MessageMixType; // 兼容 go-cqhttp
auto_escape?: boolean | string auto_escape?: boolean | string
} }
export interface OB11PostContext {
message_type?: 'private' | 'group'
user_id?: string,
group_id?: string,
}