mirror of
https://github.com/router-for-me/CLIProxyAPI.git
synced 2026-02-02 20:40:52 +08:00
Replace path with filepath for cross-platform compatibility
- Updated imports and function calls to use `filepath` across all token storage implementations and server entry point. - Ensured consistent handling of directory and file paths for improved portability.
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/luispater/CLIProxyAPI/internal/cmd"
|
"github.com/luispater/CLIProxyAPI/internal/cmd"
|
||||||
@@ -36,7 +36,7 @@ func (m *LogFormatter) Format(entry *log.Entry) ([]byte, error) {
|
|||||||
timestamp := entry.Time.Format("2006-01-02 15:04:05")
|
timestamp := entry.Time.Format("2006-01-02 15:04:05")
|
||||||
var newLog string
|
var newLog string
|
||||||
// Customize the log format to include timestamp, level, caller file/line, and message.
|
// Customize the log format to include timestamp, level, caller file/line, and message.
|
||||||
newLog = fmt.Sprintf("[%s] [%s] [%s:%d] %s\n", timestamp, entry.Level, path.Base(entry.Caller.File), entry.Caller.Line, entry.Message)
|
newLog = fmt.Sprintf("[%s] [%s] [%s:%d] %s\n", timestamp, entry.Level, filepath.Base(entry.Caller.File), entry.Caller.Line, entry.Message)
|
||||||
|
|
||||||
b.WriteString(newLog)
|
b.WriteString(newLog)
|
||||||
return b.Bytes(), nil
|
return b.Bytes(), nil
|
||||||
@@ -96,7 +96,7 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("failed to get working directory: %v", err)
|
log.Fatalf("failed to get working directory: %v", err)
|
||||||
}
|
}
|
||||||
configFilePath = path.Join(wd, "config.yaml")
|
configFilePath = filepath.Join(wd, "config.yaml")
|
||||||
cfg, err = config.LoadConfig(configFilePath)
|
cfg, err = config.LoadConfig(configFilePath)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -120,7 +120,7 @@ func main() {
|
|||||||
parts := strings.Split(cfg.AuthDir, string(os.PathSeparator))
|
parts := strings.Split(cfg.AuthDir, string(os.PathSeparator))
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
parts[0] = home
|
parts[0] = home
|
||||||
cfg.AuthDir = path.Join(parts...)
|
cfg.AuthDir = filepath.Join(parts...)
|
||||||
} else {
|
} else {
|
||||||
// If the path is just "~", set it to the home directory.
|
// If the path is just "~", set it to the home directory.
|
||||||
cfg.AuthDir = home
|
cfg.AuthDir = home
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ClaudeTokenStorage stores OAuth2 token information for Anthropic Claude API authentication.
|
// ClaudeTokenStorage stores OAuth2 token information for Anthropic Claude API authentication.
|
||||||
@@ -49,7 +49,7 @@ func (ts *ClaudeTokenStorage) SaveTokenToFile(authFilePath string) error {
|
|||||||
ts.Type = "claude"
|
ts.Type = "claude"
|
||||||
|
|
||||||
// Create directory structure if it doesn't exist
|
// Create directory structure if it doesn't exist
|
||||||
if err := os.MkdirAll(path.Dir(authFilePath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(authFilePath), 0700); err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %v", err)
|
return fmt.Errorf("failed to create directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CodexTokenStorage stores OAuth2 token information for OpenAI Codex API authentication.
|
// CodexTokenStorage stores OAuth2 token information for OpenAI Codex API authentication.
|
||||||
@@ -43,7 +43,7 @@ type CodexTokenStorage struct {
|
|||||||
// - error: An error if the operation fails, nil otherwise
|
// - error: An error if the operation fails, nil otherwise
|
||||||
func (ts *CodexTokenStorage) SaveTokenToFile(authFilePath string) error {
|
func (ts *CodexTokenStorage) SaveTokenToFile(authFilePath string) error {
|
||||||
ts.Type = "codex"
|
ts.Type = "codex"
|
||||||
if err := os.MkdirAll(path.Dir(authFilePath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(authFilePath), 0700); err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %v", err)
|
return fmt.Errorf("failed to create directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@@ -46,7 +46,7 @@ type GeminiTokenStorage struct {
|
|||||||
// - error: An error if the operation fails, nil otherwise
|
// - error: An error if the operation fails, nil otherwise
|
||||||
func (ts *GeminiTokenStorage) SaveTokenToFile(authFilePath string) error {
|
func (ts *GeminiTokenStorage) SaveTokenToFile(authFilePath string) error {
|
||||||
ts.Type = "gemini"
|
ts.Type = "gemini"
|
||||||
if err := os.MkdirAll(path.Dir(authFilePath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(authFilePath), 0700); err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %v", err)
|
return fmt.Errorf("failed to create directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path/filepath"
|
||||||
)
|
)
|
||||||
|
|
||||||
// QwenTokenStorage stores OAuth2 token information for Alibaba Qwen API authentication.
|
// QwenTokenStorage stores OAuth2 token information for Alibaba Qwen API authentication.
|
||||||
@@ -41,7 +41,7 @@ type QwenTokenStorage struct {
|
|||||||
// - error: An error if the operation fails, nil otherwise
|
// - error: An error if the operation fails, nil otherwise
|
||||||
func (ts *QwenTokenStorage) SaveTokenToFile(authFilePath string) error {
|
func (ts *QwenTokenStorage) SaveTokenToFile(authFilePath string) error {
|
||||||
ts.Type = "qwen"
|
ts.Type = "qwen"
|
||||||
if err := os.MkdirAll(path.Dir(authFilePath), 0700); err != nil {
|
if err := os.MkdirAll(filepath.Dir(authFilePath), 0700); err != nil {
|
||||||
return fmt.Errorf("failed to create directory: %v", err)
|
return fmt.Errorf("failed to create directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user