mirror of
https://github.com/LLOneBot/LLOneBot.git
synced 2024-11-22 01:56:33 +00:00
26 lines
895 B
TypeScript
26 lines
895 B
TypeScript
import { GetFileBase, GetFilePayload, GetFileResponse } from './GetFile'
|
|
import { ActionName } from '../types'
|
|
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 {
|
|
out_format: 'mp3' | 'amr' | 'wma' | 'm4a' | 'spx' | 'ogg' | 'wav' | 'flac'
|
|
}
|
|
|
|
export default class GetRecord extends GetFileBase {
|
|
actionName = ActionName.GetRecord
|
|
|
|
protected async _handle(payload: Payload): Promise<GetFileResponse> {
|
|
let res = await super._handle(payload)
|
|
res.file = await decodeSilk(res.file, payload.out_format)
|
|
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
|
|
}
|
|
}
|