Skip to content

Commit

Permalink
fix: remove authkey
Browse files Browse the repository at this point in the history
  • Loading branch information
missuo committed Sep 16, 2024
1 parent dce5ccd commit 29ac0e1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 24 deletions.
8 changes: 0 additions & 8 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ func initConfig() *Config {
}
}

// DeepL Official Authentication key flag
flag.StringVar(&cfg.AuthKey, "authkey", "", "The authentication key for DeepL API")
if cfg.AuthKey == "" {
if authKey, ok := os.LookupEnv("AUTHKEY"); ok {
cfg.AuthKey = authKey
}
}

// HTTP Proxy flag
flag.StringVar(&cfg.Proxy, "proxy", "", "set the proxy URL for HTTP requests")
if cfg.Proxy == "" {
Expand Down
19 changes: 3 additions & 16 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @Author: Vincent Yang
* @Date: 2023-07-01 21:45:34
* @LastEditors: Vincent Young
* @LastEditTime: 2024-09-16 12:07:15
* @LastEditTime: 2024-09-16 12:12:35
* @FilePath: /DeepLX/main.go
* @Telegram: https://t.me/missuo
* @GitHub: https://github.com/missuo
Expand Down Expand Up @@ -97,9 +97,6 @@ func main() {
if cfg.Token != "" {
fmt.Println("Access token is set.")
}
if cfg.AuthKey != "" {
fmt.Println("DeepL Official Authentication key is set.")
}

// Setting the application to release mode
gin.SetMode(gin.ReleaseMode)
Expand All @@ -124,7 +121,6 @@ func main() {
translateText := req.TransText
tagHandling := req.TagHandling

authKey := cfg.AuthKey
proxyURL := cfg.Proxy

if tagHandling != "" && tagHandling != "html" && tagHandling != "xml" {
Expand All @@ -135,7 +131,7 @@ func main() {
return
}

result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, authKey, proxyURL)
result, err := translate.TranslateByDeepLX(sourceLang, targetLang, translateText, tagHandling, proxyURL)
if err != nil {
log.Fatalf("Translation failed: %s", err)
}
Expand Down Expand Up @@ -225,17 +221,8 @@ func main() {

// Free API endpoint, Consistent with the official API format
r.POST("/v2/translate", authMiddleware(cfg), func(c *gin.Context) {
authorizationHeader := c.GetHeader("Authorization")
var authKey string
proxyURL := cfg.Proxy

if strings.HasPrefix(authorizationHeader, "DeepL-Auth-Key") {
parts := strings.Split(authorizationHeader, " ")
if len(parts) >= 2 && strings.HasSuffix(parts[len(parts)-1], ":fx") {
authKey = parts[len(parts)-1]
}
}

var translateText string
var targetLang string

Expand All @@ -260,7 +247,7 @@ func main() {
targetLang = jsonData.TargetLang
}

result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", authKey, proxyURL)
result, err := translate.TranslateByDeepLX("", targetLang, translateText, "", proxyURL)
if err != nil {
log.Fatalf("Translation failed: %s", err)
}
Expand Down

0 comments on commit 29ac0e1

Please sign in to comment.