Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
T
translation-server
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
qinmingyuan
translation-server
Commits
52fd8362
You need to sign in or sign up before continuing.
Commit
52fd8362
authored
Jan 24, 2025
by
mingyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:流文件上传obs
parent
dd15e79e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
18 deletions
+15
-18
app.ts
src/config/app.ts
+1
-1
translate.controller.ts
src/controller/translate/translate.controller.ts
+2
-5
translate.service.ts
src/controller/translate/translate.service.ts
+12
-12
No files found.
src/config/app.ts
View file @
52fd8362
...
...
@@ -85,6 +85,6 @@ export const app: AppConfig = {
},
chatServer
:
{
endpoint
:
env
.
APP_CHAT_SERVER
??
'http://localhost:3000'
,
endpoint
:
env
.
CHAT_SERVER_URL
??
'http://localhost:3000'
,
},
};
src/controller/translate/translate.controller.ts
View file @
52fd8362
...
...
@@ -169,11 +169,8 @@ export class TranslateController {
description
:
'成功返回翻译结果'
,
})
@
Auth
()
async
getResult
(
@
Query
()
dto
:
TranslateProgressReqDto
,
@
Res
()
res
:
Response
,
):
Promise
<
any
>
{
return
await
this
.
translateService
.
downloadImage
(
dto
.
taskId
,
res
);
async
getResult
(@
Query
()
dto
:
TranslateProgressReqDto
):
Promise
<
any
>
{
return
await
this
.
translateService
.
downloadImage
(
dto
.
taskId
);
}
// text合成语音
...
...
src/controller/translate/translate.service.ts
View file @
52fd8362
...
...
@@ -11,7 +11,6 @@ import { BadRequestError } from '@/common/exception/badRequest/BadRequestError';
import
*
as
crypto
from
'crypto'
;
import
*
as
FormData
from
'form-data'
;
import
{
TranslateImageReqDto
}
from
'./dto/req/translateImageReq.dto'
;
import
{
Response
}
from
'express'
;
import
axios
,
{
AxiosResponse
}
from
'axios'
;
import
{
TTSDto
}
from
'./dto/baseDto'
;
...
...
@@ -170,7 +169,7 @@ export class TranslateService {
}
// 下载翻译图片
async
downloadImage
(
taskId
:
string
,
res
:
Response
):
Promise
<
any
>
{
async
downloadImage
(
taskId
:
string
):
Promise
<
any
>
{
const
params
=
{
nonce_str
:
crypto
.
randomUUID
(),
tid
:
taskId
,
...
...
@@ -200,36 +199,37 @@ export class TranslateService {
throw
BadRequestError
.
default
(
'下载翻译图片失败'
);
}
// 设置响应头
res
.
setHeader
(
'Content-Type'
,
'image/jpeg'
);
// 根据实际文件类型设置
res
.
setHeader
(
'Content-Disposition'
,
'attachment; filename="image.jpg"'
);
// 设置下载文件名
//
//
设置响应头
//
res.setHeader('Content-Type', 'image/jpeg'); // 根据实际文件类型设置
//
res.setHeader('Content-Disposition', 'attachment; filename="image.jpg"'); // 设置下载文件名
// 将文件流返回给前端
response
.
data
.
pipe
(
res
);
//
//
将文件流返回给前端
//
response.data.pipe(res);
// 上传图频到服务器
// return await this.uploadStream(response.data);
const
result
=
await
this
.
uploadStream
(
response
.
data
);
return
{
url
:
`
${
config
.
obs
.
endpoint
}
/
${
result
.
filename
}
`
};
}
async
uploadStream
(
stream
)
{
const
formData
=
new
FormData
();
formData
.
append
(
'file'
,
stream
);
formData
.
append
(
'file'
,
stream
,
{
filename
:
'image.jpg'
}
);
const
response
=
await
axios
.
post
(
`
${
config
.
chatServer
.
endpoint
}
/upload/file`
,
formData
,
{
headers
:
{
'Content-Type'
:
'multipart/form-data'
,
...
formData
.
getHeaders
()
,
},
},
);
console
.
log
(
'Upload successful:'
,
response
.
data
);
if
(
response
.
status
!==
200
)
{
throw
BadRequestError
.
default
(
'上传翻译图片失败'
);
}
return
response
.
data
;
return
response
.
data
.
data
;
}
// tts 语音合成
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment