mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 23:07:51 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
181db37210 | ||
|
|
5c6b8802e4 | ||
|
|
fb0dac1889 | ||
|
|
781467bb69 |
@@ -9,7 +9,7 @@ jobs:
|
|||||||
|
|
||||||
Build:
|
Build:
|
||||||
if: startsWith(github.ref, 'refs/tags/v')
|
if: startsWith(github.ref, 'refs/tags/v')
|
||||||
runs-on: ubuntu-latest
|
runs-on: self-hosted
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ env:
|
|||||||
GHCR_IMAGE_NAME: ${{ github.repository }}
|
GHCR_IMAGE_NAME: ${{ github.repository }}
|
||||||
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}
|
||||||
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }}
|
||||||
GHCR_TOKEN: ${{ secrets.GT_Token }}
|
GHCR_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
GHCR_USERNAME: ${{ github.repository_owner }}
|
GHCR_USERNAME: ${{ github.repository_owner }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: Vincent Young
|
* @Author: Vincent Young
|
||||||
* @Date: 2022-10-18 07:32:29
|
* @Date: 2022-10-18 07:32:29
|
||||||
* @LastEditors: Vincent Young
|
* @LastEditors: Vincent Young
|
||||||
* @LastEditTime: 2023-09-14 13:58:57
|
* @LastEditTime: 2023-10-28 22:45:58
|
||||||
* @FilePath: /DeepLX/README.md
|
* @FilePath: /DeepLX/README.md
|
||||||
* @Telegram: https://t.me/missuo
|
* @Telegram: https://t.me/missuo
|
||||||
*
|
*
|
||||||
@@ -55,12 +55,29 @@
|
|||||||
"target_lang": "EN"
|
"target_lang": "EN"
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
### Specify the port
|
### Specify the port (Optional)
|
||||||
**Thanks to [cijiugechu](https://github.com/cijiugechu) for [his contribution](https://github.com/OwO-Network/DeepLX/commit/4a0920579ea868b0f05ccdff6bceae316bfd5dc8) to make this feature possible for this project!**
|
**Thanks to [cijiugechu](https://github.com/cijiugechu) for [his contribution](https://github.com/OwO-Network/DeepLX/commit/4a0920579ea868b0f05ccdff6bceae316bfd5dc8) to make this feature possible for this project!**
|
||||||
```bash
|
```bash
|
||||||
./deeplx -p 3333
|
./deeplx -p 3333
|
||||||
# or
|
# or
|
||||||
./deeplx -port 3333
|
./deeplx -port 3333
|
||||||
|
```
|
||||||
|
### Set access password (Optional)
|
||||||
|
**To prevent abuse of your public API, you can use a token to restrict translation requests.**
|
||||||
|
```bash
|
||||||
|
./deeplx -token hellodeeplx
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
curl -X POST http://localhost:1188/translate \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer your_access_token" \
|
||||||
|
-d '{
|
||||||
|
"text": "Hello, world!",
|
||||||
|
"source_lang": "EN",
|
||||||
|
"target_lang": "DE"
|
||||||
|
}'
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Run with Docker
|
### Run with Docker
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
* @Author: Vincent Young
|
* @Author: Vincent Young
|
||||||
* @Date: 2023-07-01 21:45:34
|
* @Date: 2023-07-01 21:45:34
|
||||||
* @LastEditors: Vincent Young
|
* @LastEditors: Vincent Young
|
||||||
* @LastEditTime: 2023-09-14 13:34:42
|
* @LastEditTime: 2023-10-28 22:42:08
|
||||||
* @FilePath: /DeepLX/main.go
|
* @FilePath: /DeepLX/main.go
|
||||||
* @Telegram: https://t.me/missuo
|
* @Telegram: https://t.me/missuo
|
||||||
*
|
*
|
||||||
@@ -32,6 +32,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var port int
|
var port int
|
||||||
|
var token string
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
const (
|
const (
|
||||||
@@ -41,6 +42,7 @@ func init() {
|
|||||||
|
|
||||||
flag.IntVar(&port, "port", defaultPort, usage)
|
flag.IntVar(&port, "port", defaultPort, usage)
|
||||||
flag.IntVar(&port, "p", defaultPort, usage)
|
flag.IntVar(&port, "p", defaultPort, usage)
|
||||||
|
flag.StringVar(&token, "token", "", "set the access token for /translate endpoint")
|
||||||
|
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
}
|
}
|
||||||
@@ -129,6 +131,21 @@ func main() {
|
|||||||
fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", port)
|
fmt.Printf("DeepL X has been successfully launched! Listening on 0.0.0.0:%v\n", port)
|
||||||
fmt.Println("Developed by sjlleo <i@leo.moe> and missuo <me@missuo.me>.")
|
fmt.Println("Developed by sjlleo <i@leo.moe> and missuo <me@missuo.me>.")
|
||||||
|
|
||||||
|
// Check if the token is set in the environment variable
|
||||||
|
if token == "" {
|
||||||
|
envToken, ok := os.LookupEnv("TOKEN")
|
||||||
|
if ok {
|
||||||
|
token = envToken
|
||||||
|
fmt.Println("Access token is set from the environment variable.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if token == "" {
|
||||||
|
fmt.Println("Access token is not set. You can set it using the -token flag or the TOKEN environment variable.")
|
||||||
|
} else {
|
||||||
|
fmt.Println("Access token is set. Use the Authorization: Bearer <token> header to access /translate.")
|
||||||
|
}
|
||||||
|
|
||||||
// Generating a random ID
|
// Generating a random ID
|
||||||
id := getRandomNumber()
|
id := getRandomNumber()
|
||||||
|
|
||||||
@@ -150,6 +167,17 @@ func main() {
|
|||||||
reqj := ResData{}
|
reqj := ResData{}
|
||||||
c.BindJSON(&reqj)
|
c.BindJSON(&reqj)
|
||||||
|
|
||||||
|
if token != "" {
|
||||||
|
providedToken := c.GetHeader("Authorization")
|
||||||
|
if providedToken != "Bearer "+token {
|
||||||
|
c.JSON(http.StatusUnauthorized, gin.H{
|
||||||
|
"code": http.StatusUnauthorized,
|
||||||
|
"message": "Invalid access token",
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Extracting details from the request JSON
|
// Extracting details from the request JSON
|
||||||
sourceLang := reqj.SourceLang
|
sourceLang := reqj.SourceLang
|
||||||
targetLang := reqj.TargetLang
|
targetLang := reqj.TargetLang
|
||||||
|
|||||||
Reference in New Issue
Block a user