mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
fix: get_file cache not found
This commit is contained in:
parent
52850d172e
commit
781c3311ae
@ -134,7 +134,7 @@ export async function encodeSilk(filePath: string) {
|
|||||||
export async function decodeSilk(inputFilePath: string, outFormat: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac' = 'mp3') {
|
export async function decodeSilk(inputFilePath: string, outFormat: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac' = 'mp3') {
|
||||||
const silkArrayBuffer = await fsAsync.readFile(inputFilePath)
|
const silkArrayBuffer = await fsAsync.readFile(inputFilePath)
|
||||||
const data = (await decode(silkArrayBuffer, 24000)).data
|
const data = (await decode(silkArrayBuffer, 24000)).data
|
||||||
const fileName = path.join(TEMP_DIR, uuidv4())
|
const fileName = path.join(TEMP_DIR, path.basename(inputFilePath))
|
||||||
const outPCMPath = fileName + '.pcm'
|
const outPCMPath = fileName + '.pcm'
|
||||||
const outFilePath = fileName + '.' + outFormat
|
const outFilePath = fileName + '.' + outFormat
|
||||||
await fsAsync.writeFile(outPCMPath, data)
|
await fsAsync.writeFile(outPCMPath, data)
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile'
|
import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile'
|
||||||
import { ActionName } from '../types'
|
import { ActionName } from '../types'
|
||||||
import {decodeSilk} from "@/common/utils/audio";
|
import {decodeSilk} from "@/common/utils/audio";
|
||||||
|
import { getConfigUtil } from '@/common/config'
|
||||||
|
import path from 'node:path'
|
||||||
|
import fs from 'node:fs'
|
||||||
|
|
||||||
interface Payload extends GetFilePayload {
|
interface Payload extends GetFilePayload {
|
||||||
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
||||||
@ -9,9 +12,14 @@ interface Payload extends GetFilePayload {
|
|||||||
export default class GetRecord extends GetFileBase {
|
export default class GetRecord extends GetFileBase {
|
||||||
actionName = ActionName.GetRecord
|
actionName = ActionName.GetRecord
|
||||||
|
|
||||||
protected async _handle(payload: Payload): Promise<{file: string}> {
|
protected async _handle(payload: Payload): Promise<GetFileResponse> {
|
||||||
let res = await super._handle(payload)
|
let res = await super._handle(payload)
|
||||||
res.file = await decodeSilk(res.file, payload.out_format)
|
res.file = await decodeSilk(res.file, payload.out_format)
|
||||||
return {file: res.file}
|
res.file_name = path.basename(res.file)
|
||||||
|
res.file_size = fs.statSync(res.file).size.toString()
|
||||||
|
if (getConfigUtil().getConfig().enableLocalFile2Url){
|
||||||
|
res.base64 = fs.readFileSync(res.file, 'base64')
|
||||||
|
}
|
||||||
|
return res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -171,7 +171,7 @@ export class OB11Constructor {
|
|||||||
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement, msg.chatType)
|
message_data['data']['url'] = await NTQQFileApi.getImageUrl(element.picElement, msg.chatType)
|
||||||
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
// message_data["data"]["file_id"] = element.picElement.fileUuid
|
||||||
message_data['data']['file_size'] = element.picElement.fileSize
|
message_data['data']['file_size'] = element.picElement.fileSize
|
||||||
dbUtil
|
await dbUtil
|
||||||
.addFileCache(fileName, {
|
.addFileCache(fileName, {
|
||||||
fileName,
|
fileName,
|
||||||
elementId: element.elementId,
|
elementId: element.elementId,
|
||||||
@ -189,7 +189,6 @@ export class OB11Constructor {
|
|||||||
)
|
)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then()
|
|
||||||
// 不在自动下载图片
|
// 不在自动下载图片
|
||||||
}
|
}
|
||||||
else if (element.videoElement || element.fileElement) {
|
else if (element.videoElement || element.fileElement) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user