mirror of
https://github.com/OwO-Network/DeepLX.git
synced 2026-12-01 14:57:52 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ffdba23b03 | ||
|
|
a3778c05fb | ||
|
|
81c94afb55 | ||
|
|
48151fec8f | ||
|
|
154fb27895 | ||
|
|
08fd328e9d | ||
|
|
d8fbb7e07e | ||
|
|
d16d74b3e9 | ||
|
|
8b0953e9f7 | ||
|
|
43565812b5 | ||
|
|
f8a41debe6 | ||
|
|
e593bceb97 | ||
|
|
9e558516ef | ||
|
|
7aa936e888 |
+5
-11
@@ -3,7 +3,7 @@
|
||||
# @Author: Vincent Young
|
||||
# @Date: 2022-10-20 02:19:06
|
||||
# @LastEditors: Vincent Young
|
||||
# @LastEditTime: 2022-10-20 09:51:57
|
||||
# @LastEditTime: 2023-02-18 20:45:52
|
||||
# @FilePath: /DeepLX/.cross_compile.sh
|
||||
# @Telegram: https://t.me/missuo
|
||||
#
|
||||
@@ -29,16 +29,10 @@ for pl in ${PLATFORMS}; do
|
||||
|
||||
echo "build => ${TARGET}"
|
||||
if [ "${DEBUG_MODE}" == "debug" ]; then
|
||||
go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
|
||||
-ldflags "-X 'main.version=${BUILD_VERSION}' \
|
||||
-X 'main.buildDate=${BUILD_DATE}' \
|
||||
-X 'main.commitID=${COMMIT_SHA1}'\
|
||||
-w -s"
|
||||
CGO_ENABLED=0 go build -trimpath -gcflags "all=-N -l" -o ${TARGET} \
|
||||
-ldflags "-w -s" main.go
|
||||
else
|
||||
go build -trimpath -o ${TARGET} \
|
||||
-ldflags "-X 'main.version=${BUILD_VERSION}' \
|
||||
-X 'main.buildDate=${BUILD_DATE}' \
|
||||
-X 'main.commitID=${COMMIT_SHA1}'\
|
||||
-w -s"
|
||||
CGO_ENABLED=0 go build -trimpath -o ${TARGET} \
|
||||
-ldflags "-w -s" main.go
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -13,7 +13,7 @@ jobs:
|
||||
|
||||
- uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: "1.18"
|
||||
go-version: "1.19"
|
||||
|
||||
- run: bash .cross_compile.sh
|
||||
|
||||
@@ -22,18 +22,6 @@ jobs:
|
||||
with:
|
||||
draft: false
|
||||
files: |
|
||||
dist/deeplx_darwin_amd64
|
||||
dist/deeplx_darwin_arm64
|
||||
dist/deeplx_linux_386
|
||||
dist/deeplx_linux_amd64
|
||||
dist/deeplx_linux_arm64
|
||||
dist/deeplx_linux_armv7
|
||||
dist/deeplx_linux_mips
|
||||
dist/deeplx_openbsd_amd64
|
||||
dist/deeplx_openbsd_arm64
|
||||
dist/deeplx_freebsd_amd64
|
||||
dist/deeplx_freebsd_arm64
|
||||
dist/deeplx_windows_amd64.exe
|
||||
dist/deeplx_windows_386.exe
|
||||
dist/*
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GT_Token }}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: Vincent Young
|
||||
* @Date: 2022-10-18 07:32:29
|
||||
* @LastEditors: Vincent Young
|
||||
* @LastEditTime: 2023-02-18 19:46:10
|
||||
* @LastEditTime: 2023-02-24 21:36:36
|
||||
* @FilePath: /DeepLX/README.md
|
||||
* @Telegram: https://t.me/missuo
|
||||
*
|
||||
@@ -32,13 +32,19 @@ Permanently free DeepL API written in Golang
|
||||
}
|
||||
```
|
||||
|
||||
### Run on Linux Server
|
||||
```bash
|
||||
bash <(curl -Ls https://cpp.li/deeplx)
|
||||
```
|
||||
|
||||
### Run on Mac
|
||||
1. Download the latest release of DeepL X.
|
||||
```bash
|
||||
sudo mv deeplx_darwin_amd64 /usr/local/bin/deeplx
|
||||
sudo chmod +x /usr/local/bin/deeplx
|
||||
```
|
||||
|
||||
2. Download the `me.missuo.deeplx.plist` to `/Users/YOUR_USERNAME/Library/LaunchAgents`.
|
||||
2. Download the `me.missuo.deeplx.plist` to `~/Library/LaunchAgents`.
|
||||
```bash
|
||||
wget https://raw.githubusercontent.com/OwO-Network/DeepLX/main/me.missuo.deeplx.plist -O ~/Library/LaunchAgents/me.missuo.deeplx.plist
|
||||
```
|
||||
@@ -48,15 +54,29 @@ launchctl load ~/Library/LaunchAgents/me.missuo.deeplx.plist
|
||||
launchctl start ~/Library/LaunchAgents/me.missuo.deeplx.plist
|
||||
```
|
||||
|
||||
### Install from AUR
|
||||
```bash
|
||||
paru -S deeplx-bin
|
||||
```
|
||||
|
||||
After installation, start the daemon with the following command.
|
||||
|
||||
```bash
|
||||
systemctl daemon-reload
|
||||
systemctl enable deeplx
|
||||
|
||||
```
|
||||
## Setup on [Bob App](https://bobtranslate.com/)
|
||||
1. Install [bob-plugin-deeplx](https://github.com/clubxdev/bob-plugin-deeplx) on Bob.
|
||||
|
||||
2. Setup the API.
|
||||

|
||||

|
||||
|
||||
## Docker Backup for zu1k
|
||||
## Backup the Docker Image of zu1k
|
||||
```shell
|
||||
docker run -itd -p 7373:80 missuo/deeplx-bk
|
||||
docker run -itd -p 1188:80 missuo/deeplx-bk
|
||||
```
|
||||
**This docker image is not related to this project, as the original author deleted the image, it is only for backup.**
|
||||
|
||||
## Author
|
||||
**DeepL X** © [Vincent Young](https://github.com/missuo) & [Leo Shen](https://github.com/sjlleo), Released under the [MIT](./LICENSE) License.<br>
|
||||
|
||||
+3
-5
@@ -1,14 +1,12 @@
|
||||
[Unit]
|
||||
Description=DeepLX Service
|
||||
After=network.target nss-lookup.target
|
||||
Wants=network.target
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
User=root
|
||||
Group=root
|
||||
Type=simple
|
||||
Restart=always
|
||||
WorkingDirectory=/usr/bin/
|
||||
ExecStart=/usr/bin/deeplx
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
WantedBy=multi-user.target
|
||||
|
||||
+2
-1
@@ -22,6 +22,7 @@ install_deeplx(){
|
||||
wget -q -N --no-check-certificate -O /etc/systemd/system/deeplx.service https://raw.githubusercontent.com/OwO-Network/DeepLX/main/deeplx.service
|
||||
systemctl daemon-reload
|
||||
systemctl enable deeplx
|
||||
systemctl start deeplx
|
||||
echo -e "Installed successfully, listening at 0.0.0.0:1188"
|
||||
}
|
||||
install_deeplx
|
||||
install_deeplx
|
||||
|
||||
@@ -15,6 +15,10 @@ import (
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
func init() {
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
}
|
||||
|
||||
type Lang struct {
|
||||
SourceLangUserSelected string `json:"source_lang_user_selected"`
|
||||
TargetLang string `json:"target_lang"`
|
||||
@@ -46,15 +50,15 @@ type PostData struct {
|
||||
Params Params `json:"params"`
|
||||
}
|
||||
|
||||
func init_data(source_lang string, target_lang string) *PostData {
|
||||
func initData(sourceLang string, targetLang string) *PostData {
|
||||
return &PostData{
|
||||
Jsonrpc: "2.0",
|
||||
Method: "LMT_handle_texts",
|
||||
Params: Params{
|
||||
Splitting: "newlines",
|
||||
Lang: Lang{
|
||||
SourceLangUserSelected: source_lang,
|
||||
TargetLang: target_lang,
|
||||
SourceLangUserSelected: sourceLang,
|
||||
TargetLang: targetLang,
|
||||
},
|
||||
CommonJobParams: CommonJobParams{
|
||||
WasSpoken: false,
|
||||
@@ -65,8 +69,8 @@ func init_data(source_lang string, target_lang string) *PostData {
|
||||
}
|
||||
}
|
||||
|
||||
func get_i_count(translate_text string) int64 {
|
||||
return int64(strings.Count(translate_text, "i"))
|
||||
func getICount(translateText string) int64 {
|
||||
return int64(strings.Count(translateText, "i"))
|
||||
}
|
||||
|
||||
func getRandomNumber() int64 {
|
||||
@@ -75,21 +79,20 @@ func getRandomNumber() int64 {
|
||||
return num * 1000
|
||||
}
|
||||
|
||||
func getTimeStamp(i_count int64) int64 {
|
||||
func getTimeStamp(iCount int64) int64 {
|
||||
ts := time.Now().UnixMilli()
|
||||
if i_count != 0 {
|
||||
i_count = i_count + 1
|
||||
return ts - ts%i_count + i_count
|
||||
if iCount != 0 {
|
||||
iCount = iCount + 1
|
||||
return ts - ts%iCount + iCount
|
||||
} else {
|
||||
return ts
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type ResData struct {
|
||||
Trans_Text string `json:"text"`
|
||||
Source_Lang string `json:"source_lang"`
|
||||
Target_Lang string `json:"target_lang"`
|
||||
TransText string `json:"text"`
|
||||
SourceLang string `json:"source_lang"`
|
||||
TargetLang string `json:"target_lang"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
@@ -106,8 +109,8 @@ func main() {
|
||||
|
||||
r.GET("/", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 200,
|
||||
"msg": "DeepL API, Made by sjlleo and missuo. Go to /translate with POST.",
|
||||
"code": 200,
|
||||
"message": "DeepL Free API, Made by sjlleo and missuo. Go to /translate with POST. http://github.com/OwO-Network/DeepLX",
|
||||
})
|
||||
|
||||
})
|
||||
@@ -115,41 +118,47 @@ func main() {
|
||||
r.POST("/translate", func(c *gin.Context) {
|
||||
reqj := ResData{}
|
||||
c.BindJSON(&reqj)
|
||||
source_lang := reqj.Source_Lang
|
||||
target_lang := reqj.Target_Lang
|
||||
if source_lang == "" {
|
||||
source_lang = "ZH"
|
||||
|
||||
sourceLang := reqj.SourceLang
|
||||
targetLang := reqj.TargetLang
|
||||
if sourceLang == "" {
|
||||
sourceLang = "ZH"
|
||||
}
|
||||
if target_lang == "" {
|
||||
target_lang = "EN"
|
||||
if targetLang == "" {
|
||||
targetLang = "EN"
|
||||
}
|
||||
translate_text := reqj.Trans_Text
|
||||
// fmt.Printf("%v", translate_text)
|
||||
if translate_text != "" {
|
||||
translateText := reqj.TransText
|
||||
// fmt.Printf("%v", translateText)
|
||||
if translateText == "" {
|
||||
c.JSON(http.StatusNotFound, gin.H{
|
||||
"code": http.StatusNotFound,
|
||||
"message": "No Translate Text Found",
|
||||
})
|
||||
} else {
|
||||
url := "https://www2.deepl.com/jsonrpc"
|
||||
id = id + 1
|
||||
post_data := init_data(source_lang, target_lang)
|
||||
postData := initData(sourceLang, targetLang)
|
||||
text := Text{
|
||||
Text: translate_text,
|
||||
Text: translateText,
|
||||
RequestAlternatives: 3,
|
||||
}
|
||||
// set id
|
||||
post_data.ID = id
|
||||
postData.ID = id
|
||||
// set text
|
||||
post_data.Params.Texts = append(post_data.Params.Texts, text)
|
||||
postData.Params.Texts = append(postData.Params.Texts, text)
|
||||
// set timestamp
|
||||
post_data.Params.Timestamp = getTimeStamp(get_i_count(translate_text))
|
||||
post_byte, _ := json.Marshal(post_data)
|
||||
post_str := string(post_byte)
|
||||
postData.Params.Timestamp = getTimeStamp(getICount(translateText))
|
||||
post_byte, _ := json.Marshal(postData)
|
||||
postStr := string(post_byte)
|
||||
|
||||
// add space if necessary
|
||||
if (id+5)%29 == 0 || (id+3)%13 == 0 {
|
||||
post_str = strings.Replace(post_str, "\"method\":\"", "\"method\" : \"", -1)
|
||||
postStr = strings.Replace(postStr, "\"method\":\"", "\"method\" : \"", -1)
|
||||
} else {
|
||||
post_str = strings.Replace(post_str, "\"method\":\"", "\"method\": \"", -1)
|
||||
postStr = strings.Replace(postStr, "\"method\":\"", "\"method\": \"", -1)
|
||||
}
|
||||
|
||||
post_byte = []byte(post_str)
|
||||
post_byte = []byte(postStr)
|
||||
reader := bytes.NewReader(post_byte)
|
||||
request, err := http.NewRequest("POST", url, reader)
|
||||
if err != nil {
|
||||
@@ -177,38 +186,33 @@ func main() {
|
||||
return
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, _ := io.ReadAll(resp.Body)
|
||||
res := gjson.ParseBytes(body)
|
||||
// display response
|
||||
fmt.Println(res)
|
||||
// fmt.Println(res)
|
||||
if res.Get("error.code").String() == "-32600" {
|
||||
log.Println(res.Get("error").String())
|
||||
c.JSON(406, gin.H{
|
||||
"code": 406,
|
||||
"msg": "Invalid target_lang",
|
||||
c.JSON(http.StatusNotAcceptable, gin.H{
|
||||
"code": http.StatusNotAcceptable,
|
||||
"message": "Invalid targetLang",
|
||||
})
|
||||
return
|
||||
} else {
|
||||
if resp.StatusCode == 429 {
|
||||
c.JSON(429, gin.H{
|
||||
"code": 429,
|
||||
"message": "Too Many Requests",
|
||||
})
|
||||
} else {
|
||||
c.JSON(200, gin.H{
|
||||
"code": 200,
|
||||
"id": id,
|
||||
"data": res.Get("result.texts.0.text").String(),
|
||||
})
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.JSON(404, gin.H{
|
||||
"code": 404,
|
||||
"message": "No Text Found",
|
||||
})
|
||||
|
||||
if resp.StatusCode == http.StatusTooManyRequests {
|
||||
c.JSON(http.StatusTooManyRequests, gin.H{
|
||||
"code": http.StatusTooManyRequests,
|
||||
"message": "Too Many Requests",
|
||||
})
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"code": http.StatusOK,
|
||||
"id": id,
|
||||
"data": res.Get("result.texts.0.text").String(),
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
r.Run(":1188") // listen and serve on 0.0.0.0:1188
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user