Skip to content

Commit 06f42b7

Browse files
committed
Simplify workflows and add configurable log support
Refactored button workflows to streamline checks and improve logic, replacing redundant workflows with concise policies. Introduced configurable log file support by adding `logfile` field to the configuration and enabling log redirection to specified files. Updated `.gitignore` to exclude log files.
1 parent 9d40c06 commit 06f42b7

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ user-data/
99
docs/
1010
chromium/
1111
cert/ca.crt
12-
cert/ca.key
12+
cert/ca.key
13+
*.log

internal/config/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type AppConfig struct {
1313
Headless bool `yaml:"headless"`
1414
ApiPort string `yaml:"api-port"`
1515
Instance []AppConfigInstance `yaml:"instance"`
16+
LogFile string `yaml:"logfile"`
1617
}
1718

1819
type AppConfigBrowser struct {

internal/method/aistudio.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ func (m *Method) ChooseModelByName(name, modelNameSelector string, modelCategory
2525
chromedp.MouseClickNode(containerNode),
2626
)
2727
cancelClick() // Always call cancel
28-
log.Info(err)
2928
if err == nil {
3029
// After clicking the container, model names might appear or update
3130
modelNameElements, errGetElements := m.GetElements(modelNameSelector) // This now returns []*cdp.Node

main.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"bytes"
55
"context"
6+
"crypto/md5"
67
"encoding/json"
78
"fmt"
89
"github.com/chromedp/cdproto/cdp"
@@ -54,6 +55,14 @@ func main() {
5455
log.Fatalf("Load configuare error: %v", err)
5556
return
5657
}
58+
if cfg.LogFile != "" {
59+
f, errOpenFile := os.OpenFile(cfg.LogFile, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
60+
if errOpenFile != nil {
61+
log.Fatalf("Failed to open log file: %v", errOpenFile)
62+
return
63+
}
64+
log.SetOutput(f)
65+
}
5766
if !cfg.Debug {
5867
log.SetLevel(log.InfoLevel)
5968
}
@@ -228,6 +237,18 @@ func main() {
228237
}
229238
}
230239

240+
if _, errStat := os.Stat(mapCfg[instanceName].Auth.File); !os.IsNotExist(errStat) {
241+
authData, errReadFile := os.ReadFile(mapCfg[instanceName].Auth.File)
242+
if errReadFile != nil {
243+
log.Debugf("Error reading auth info to file %s for instance %s: %v", mapCfg[instanceName].Auth.File, instanceName, errReadFile)
244+
continue
245+
}
246+
if md5.Sum(authData) == md5.Sum(jsonData) {
247+
log.Debugf("Auth info for instance %s is up to date, skipping write", instanceName)
248+
continue
249+
}
250+
}
251+
231252
errWriteFile := os.WriteFile(mapCfg[instanceName].Auth.File, jsonData, 0644)
232253
if errWriteFile != nil {
233254
log.Debugf("Error writing auth info to file %s for instance %s: %v", mapCfg[instanceName].Auth.File, instanceName, errWriteFile)

0 commit comments

Comments
 (0)