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
133fdb1d
Commit
133fdb1d
authored
Jan 14, 2025
by
mingyard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:限定翻译语言
parent
803b440a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
0 deletions
+39
-0
service.ts
src/config/service.ts
+8
-0
translateReq.dto.ts
src/controller/translate/dto/req/translateReq.dto.ts
+10
-0
translate.service.ts
src/controller/translate/translate.service.ts
+21
-0
No files found.
src/config/service.ts
View file @
133fdb1d
...
...
@@ -4,10 +4,18 @@ export interface ServiceConfig {
tts
:
{
txAsrTokenUrl
:
string
;
};
fanYiGou
:
{
endpoint
:
string
;
secret
:
string
;
};
}
export
const
service
:
ServiceConfig
=
{
tts
:
{
txAsrTokenUrl
:
env
.
TTS_TX_ASR_TOKEN_URL
??
''
,
},
fanYiGou
:
{
endpoint
:
env
.
FAN_YI_GOU_ENDPOINT
??
'https://www.fanyigou.com'
,
secret
:
env
.
FAN_YI_GOU_SECRET
??
''
,
},
};
src/controller/translate/dto/req/translateReq.dto.ts
View file @
133fdb1d
...
...
@@ -14,6 +14,16 @@ export class TranslateReqDto {
@
IsEnum
(
SupportLanguages
)
target
:
SupportLanguages
;
@
ApiProperty
({
description
:
'源语言'
,
enum
:
SupportLanguages
,
example
:
SupportLanguages
.
EN
,
})
@
Expose
()
@
IsNotEmpty
()
@
IsEnum
(
SupportLanguages
)
source
:
SupportLanguages
;
@
ApiProperty
({
description
:
'待翻译文本'
,
type
:
String
,
...
...
src/controller/translate/translate.service.ts
View file @
133fdb1d
...
...
@@ -8,6 +8,7 @@ import { TranslateResDto } from './dto/res/translateRes.dto';
import
{
axiosPostRequest
}
from
'@/common/utils/requests/request'
;
import
{
config
}
from
'@/config'
;
import
{
BadRequestError
}
from
'@/common/exception/badRequest/BadRequestError'
;
import
crypto
from
'crypto'
;
@
Injectable
()
export
class
TranslateService
{
...
...
@@ -29,6 +30,7 @@ export class TranslateService {
{
text
:
[
translateDto
.
text
],
target_lang
:
translateDto
.
target
,
source_lang
:
translateDto
.
source
,
},
{
headers
:
{
...
...
@@ -48,4 +50,23 @@ export class TranslateService {
return
{
source
,
text
};
}
// 获取翻译狗token
async
generateToken
(
params
,
privateKey
)
{
// 按照key=value的格式,并按照参数名ASCII字典序排序
const
sortedParams
=
Object
.
keys
(
params
)
.
sort
()
.
map
((
key
)
=>
`
${
key
}
=
${
params
[
key
]}
`
)
.
join
(
'&'
);
const
stringToHash
=
`
${
sortedParams
}
&privatekey=
${
privateKey
}
`
;
// 生成MD5哈希并转换为大写
const
token
=
crypto
.
createHash
(
'md5'
)
.
update
(
stringToHash
)
.
digest
(
'hex'
)
.
toUpperCase
();
return
token
;
}
}
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