Commit 9b01570a authored by mingyard's avatar mingyard

feat:上传测试

parent 63b12533
...@@ -45,6 +45,10 @@ interface AppConfig { ...@@ -45,6 +45,10 @@ interface AppConfig {
obs: { obs: {
endpoint: string; endpoint: string;
}; };
chatServer: {
endpoint: string;
};
} }
const server = env.APP_SERVER ?? 'http://localhost:3000'; const server = env.APP_SERVER ?? 'http://localhost:3000';
...@@ -79,4 +83,8 @@ export const app: AppConfig = { ...@@ -79,4 +83,8 @@ export const app: AppConfig = {
obs: { obs: {
endpoint: env.APP_OBS_ENDPOINT ?? 'https://resources.laihua.com', endpoint: env.APP_OBS_ENDPOINT ?? 'https://resources.laihua.com',
}, },
chatServer: {
endpoint: env.APP_CHAT_SERVER ?? 'http://localhost:3000',
},
}; };
...@@ -200,12 +200,36 @@ export class TranslateService { ...@@ -200,12 +200,36 @@ export class TranslateService {
throw BadRequestError.default('下载翻译图片失败'); throw BadRequestError.default('下载翻译图片失败');
} }
// 设置响应头 // // 设置响应头
res.setHeader('Content-Type', 'image/jpeg'); // 根据实际文件类型设置 // res.setHeader('Content-Type', 'image/jpeg'); // 根据实际文件类型设置
res.setHeader('Content-Disposition', 'attachment; filename="image.jpg"'); // 设置下载文件名 // res.setHeader('Content-Disposition', 'attachment; filename="image.jpg"'); // 设置下载文件名
// 将文件流返回给前端 // // 将文件流返回给前端
response.data.pipe(res); // response.data.pipe(res);
// 上传图频到服务器
return await this.uploadStream(response.data);
}
async uploadStream(stream) {
const formData = new FormData();
formData.append('file', stream);
const response = await axios.post(
`${config.chatServer.endpoint}/upload/file`,
formData,
{
headers: {
'Content-Type': 'multipart/form-data',
},
},
);
console.log('Upload successful:', response.data);
if (response.status !== 200) {
throw BadRequestError.default('上传翻译图片失败');
}
return response.data;
} }
// tts 语音合成 // tts 语音合成
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment