blob: d04a8aad36c895c4b2fbe6d3e0412a813a6ab421 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package config
import (
"encoding/base64"
"fmt"
"os"
)
var (
AppName = "yato"
PrettyAppName = "Yato"
Version = "0.1.0"
MALOAuthBaseURL = "https://myanimelist.net/v1/oauth2/authorize"
MALClientID string
MALClientSecret string
MALRedirectURI = "http://localhost:42069/authenticate"
MALAPIBaseURL = "https://api.myanimelist.net/v2"
JikanAPIBaseURL = "https://api.jikan.moe/v4"
ConfigDir, _ = os.UserConfigDir()
)
// These variables will be set by the linker during build
var (
encodedClientID string
encodedClientSecret string
)
func init() {
var err error
// Try to decode from build flags first
MALClientID, err = decodeSecret(encodedClientID)
if err != nil || MALClientID == "" {
// Fallback to environment variable
MALClientID = os.Getenv("MAL_CLIENT_ID")
}
MALClientSecret, err = decodeSecret(encodedClientSecret)
if err != nil || MALClientSecret == "" {
// Fallback to environment variable
MALClientSecret = os.Getenv("MAL_CLIENT_SECRET")
}
if MALClientID == "" || MALClientSecret == "" {
fmt.Println("Warning: Client ID or Secret not set. Please set MAL_CLIENT_ID and MAL_CLIENT_SECRET environment variables or use the build script.")
}
}
func decodeSecret(encoded string) (string, error) {
if encoded == "" {
return "", fmt.Errorf("encoded string is empty")
}
decoded, err := base64.StdEncoding.DecodeString(encoded)
if err != nil {
return "", err
}
return string(decoded), nil
}
// GetMALClientID returns the MAL Client ID
func GetMALClientID() string {
return MALClientID
}
// GetMALClientSecret returns the MAL Client Secret
func GetMALClientSecret() string {
return MALClientSecret
}
|