mirror of
https://github.com/ikechan8370/chatgpt-plugin.git
synced 2025-12-17 05:47:11 +00:00
fix: azure下云转码适配
This commit is contained in:
parent
49af9dad80
commit
2cafdcaa82
2 changed files with 16 additions and 26 deletions
|
|
@ -577,7 +577,7 @@ export function supportGuoba () {
|
||||||
options: [
|
options: [
|
||||||
{ label: '文件', value: 'file' },
|
{ label: '文件', value: 'file' },
|
||||||
{ label: '链接', value: 'url' },
|
{ label: '链接', value: 'url' },
|
||||||
{ label: '数据', value: 'buffer' }
|
// { label: '数据', value: 'buffer' }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// import Contactable, { core } from 'oicq'
|
// import Contactable, { core } from 'oicq'
|
||||||
import querystring from 'querystring'
|
import querystring from 'querystring'
|
||||||
import fetch, { File } from 'node-fetch'
|
import fetch, { File, FormData } from 'node-fetch'
|
||||||
import fs from 'fs'
|
import fs from 'fs'
|
||||||
import os from 'os'
|
import os from 'os'
|
||||||
import util from 'util'
|
import util from 'util'
|
||||||
|
|
@ -37,16 +37,22 @@ async function uploadRecord (recordUrl) {
|
||||||
} else if (Config.cloudTranscode) {
|
} else if (Config.cloudTranscode) {
|
||||||
try {
|
try {
|
||||||
if (Config.cloudMode === 'buffer' || Config.cloudMode === 'file') {
|
if (Config.cloudMode === 'buffer' || Config.cloudMode === 'file') {
|
||||||
let response = await fetch(recordUrl, {
|
let buffer
|
||||||
method: 'GET',
|
if (!recordUrl.startsWith('http')) {
|
||||||
headers: {
|
// 本地文件
|
||||||
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; MI 9 Build/SKQ1.211230.001)'
|
buffer = fs.readFileSync(recordUrl)
|
||||||
}
|
} else {
|
||||||
})
|
let response = await fetch(recordUrl, {
|
||||||
if (Config.cloudMode === 'file') {
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 12; MI 9 Build/SKQ1.211230.001)'
|
||||||
|
}
|
||||||
|
})
|
||||||
const blob = await response.blob()
|
const blob = await response.blob()
|
||||||
const arrayBuffer = await blob.arrayBuffer()
|
const arrayBuffer = await blob.arrayBuffer()
|
||||||
const buffer = Buffer.from(arrayBuffer)
|
buffer = Buffer.from(arrayBuffer)
|
||||||
|
}
|
||||||
|
if (Config.cloudMode === 'file') {
|
||||||
const formData = new FormData()
|
const formData = new FormData()
|
||||||
formData.append('file', new File([buffer], 'audio.wav'))
|
formData.append('file', new File([buffer], 'audio.wav'))
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
||||||
|
|
@ -60,22 +66,6 @@ async function uploadRecord (recordUrl) {
|
||||||
logger.error(t)
|
logger.error(t)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
const buf = Buffer.from(await response.arrayBuffer())
|
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
|
||||||
'Content-Type': 'application/json'
|
|
||||||
},
|
|
||||||
body: JSON.stringify({ recordBuffer: buf })
|
|
||||||
})
|
|
||||||
let t = await resultres.text()
|
|
||||||
try {
|
|
||||||
result = JSON.parse(t)
|
|
||||||
} catch (e) {
|
|
||||||
logger.error(t)
|
|
||||||
throw e
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
const resultres = await fetch(`${Config.cloudTranscode}/audio`, {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue