mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
commit
fc0881eccc
@ -45,5 +45,6 @@ export interface FileCache {
|
||||
fileUuid?: string
|
||||
url?: string
|
||||
msgId?: string
|
||||
elementId: string
|
||||
downloadFunc?: () => Promise<void>
|
||||
}
|
||||
|
@ -21,13 +21,12 @@ export interface GetFileResponse {
|
||||
}
|
||||
|
||||
export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
private getElement(msg: RawMessage): { id: string; element: VideoElement | FileElement } {
|
||||
let element = msg.elements.find((e) => e.fileElement)
|
||||
private getElement(msg: RawMessage, elementId: string): VideoElement | FileElement {
|
||||
let element = msg.elements.find((e) => e.elementId === elementId)
|
||||
if (!element) {
|
||||
element = msg.elements.find((e) => e.videoElement)
|
||||
return { id: element.elementId, element: element.videoElement }
|
||||
throw new Error('element not found')
|
||||
}
|
||||
return { id: element.elementId, element: element.fileElement }
|
||||
return element.fileElement
|
||||
}
|
||||
private async download(cache: FileCache, file: string) {
|
||||
log('需要调用 NTQQ 下载文件api')
|
||||
@ -35,14 +34,14 @@ export class GetFileBase extends BaseAction<GetFilePayload, GetFileResponse> {
|
||||
let msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||
if (msg) {
|
||||
log('找到了文件 msg', msg)
|
||||
let element = this.getElement(msg)
|
||||
let element = this.getElement(msg, cache.elementId)
|
||||
log('找到了文件 element', element)
|
||||
// 构建下载函数
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, element.id, '', '', true)
|
||||
await sleep(1000)
|
||||
await NTQQFileApi.downloadMedia(msg.msgId, msg.chatType, msg.peerUid, cache.elementId, '', '', true)
|
||||
await sleep(1000) // 这里延时是为何?
|
||||
msg = await dbUtil.getMsgByLongId(cache.msgId)
|
||||
log('下载完成后的msg', msg)
|
||||
cache.filePath = this.getElement(msg).element.filePath
|
||||
cache.filePath = this.getElement(msg, cache.elementId).filePath
|
||||
dbUtil.addFileCache(file, cache).then()
|
||||
}
|
||||
}
|
||||
|
@ -170,6 +170,7 @@ export class OB11Constructor {
|
||||
dbUtil
|
||||
.addFileCache(fileName, {
|
||||
fileName,
|
||||
elementId: element.elementId,
|
||||
filePath: sourcePath,
|
||||
fileSize: element.picElement.fileSize.toString(),
|
||||
url: message_data['data']['url'],
|
||||
@ -198,6 +199,7 @@ export class OB11Constructor {
|
||||
dbUtil
|
||||
.addFileCache(videoOrFileElement.fileUuid, {
|
||||
msgId: msg.msgId,
|
||||
elementId: element.elementId,
|
||||
fileName: videoOrFileElement.fileName,
|
||||
filePath: videoOrFileElement.filePath,
|
||||
fileSize: videoOrFileElement.fileSize,
|
||||
@ -225,6 +227,7 @@ export class OB11Constructor {
|
||||
message_data['data']['file_size'] = element.pttElement.fileSize
|
||||
dbUtil
|
||||
.addFileCache(element.pttElement.fileName, {
|
||||
elementId: element.elementId,
|
||||
fileName: element.pttElement.fileName,
|
||||
filePath: element.pttElement.filePath,
|
||||
fileSize: element.pttElement.fileSize,
|
||||
|
@ -1,19 +1,12 @@
|
||||
import { OB11Message, OB11MessageAt, OB11MessageData } from '../types'
|
||||
import { getFriend, getGroup, getUidByUin, selfInfo } from '../../common/data'
|
||||
import { OB11Message } from '../types'
|
||||
import { selfInfo } from '@/common/data'
|
||||
import { OB11BaseMetaEvent } from '../event/meta/OB11BaseMetaEvent'
|
||||
import { OB11BaseNoticeEvent } from '../event/notice/OB11BaseNoticeEvent'
|
||||
import { WebSocket as WebSocketClass } from 'ws'
|
||||
import { wsReply } from './ws/reply'
|
||||
import { log } from '../../common/utils/log'
|
||||
import { getConfigUtil } from '../../common/config'
|
||||
import { log } from '@/common/utils'
|
||||
import { getConfigUtil } from '@/common/config'
|
||||
import crypto from 'crypto'
|
||||
import { NTQQFriendApi, NTQQGroupApi, NTQQMsgApi, Peer } from '../../ntqqapi/api'
|
||||
import { ChatType, Group, GroupRequestOperateTypes } from '../../ntqqapi/types'
|
||||
import { convertMessage2List, createSendElements, sendMsg } from '../action/msg/SendMsg'
|
||||
import { dbUtil } from '../../common/db'
|
||||
import { OB11FriendRequestEvent } from '../event/request/OB11FriendRequest'
|
||||
import { OB11GroupRequestEvent } from '../event/request/OB11GroupRequest'
|
||||
import { isNull } from '../../common/utils'
|
||||
import { handleQuickOperation, QuickOperationEvent } from './quick-operation'
|
||||
|
||||
export type PostEventType = OB11Message | OB11BaseMetaEvent | OB11BaseNoticeEvent
|
||||
|
Loading…
x
Reference in New Issue
Block a user