File tree Expand file tree Collapse file tree 3 files changed +27
-31
lines changed
Expand file tree Collapse file tree 3 files changed +27
-31
lines changed Original file line number Diff line number Diff line change 55 "path/filepath"
66)
77
8- // Path - create path if not exists
8+ // Path - create file path if not exists
99func Path (path string ) bool {
1010
1111 _ , err := os .Stat (path )
@@ -26,28 +26,18 @@ func Path(path string) bool {
2626 return true
2727}
2828
29- // Exists - check is file exists
30- func Exists (path string ) bool {
29+ // Dir - create dir path if not exists
30+ func Dir (path string ) bool {
3131
3232 _ , err := os .Stat (path )
3333
3434 if path != "" && err != nil {
3535
36+ err = os .MkdirAll (path , os .ModePerm )
37+ IfError (err )
38+
3639 return false
3740 }
3841
3942 return true
4043}
41-
42- // IsYaml - check if file got .yaml or .yml extension
43- func IsYaml (path string ) bool {
44-
45- if Exists (path ) {
46- ext := filepath .Ext (path )
47- if ext == ".yaml" || ext == ".yml" {
48- return true
49- }
50- }
51-
52- return false
53- }
Original file line number Diff line number Diff line change @@ -25,23 +25,29 @@ func apiHandler(c *gin.Context) {
2525
2626func apiGetTr (c * gin.Context ) {
2727 var result string
28- treq := struct {
29- Text string
30- Alt string
31- }{"" , "" }
3228
33- treqStr := c .PostForm ("treq" )
34- err := json .Unmarshal ([]byte (treqStr ), & treq )
35- check .IfError (err )
36-
37- if treq .Text == "" {
38- result = ""
29+ if appConfig .LtrPath == "" {
30+ result = "LibreTranslate path is empty"
31+ log .Println ("ERROR:" , result )
3932 } else {
40- result = translate .Libre (treq .Text , appConfig , treq .Alt )
41- }
33+ treq := struct {
34+ Text string
35+ Alt string
36+ }{"" , "" }
37+
38+ treqStr := c .PostForm ("treq" )
39+ err := json .Unmarshal ([]byte (treqStr ), & treq )
40+ check .IfError (err )
41+
42+ if treq .Text == "" {
43+ result = ""
44+ } else {
45+ result = translate .Libre (treq .Text , appConfig , treq .Alt )
46+ }
4247
43- log .Println ("INFO: text:" , treq .Text )
44- log .Println ("INFO: result:" , result )
48+ log .Println ("INFO: text:" , treq .Text )
49+ log .Println ("INFO: result:" , result )
50+ }
4551
4652 c .IndentedJSON (http .StatusOK , result )
4753}
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ func Gui(dirPath, nodePath string) {
3737 if nodePath != "" {
3838 appConfig .NodePath = nodePath
3939 }
40- check .Path (appConfig .DirPath + "/saved/" )
40+ check .Dir (appConfig .DirPath + "/saved/" )
4141
4242 log .Println ("INFO: starting web gui with config" , appConfig .ConfPath )
4343
You can’t perform that action at this time.
0 commit comments