-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinit.go
More file actions
66 lines (57 loc) · 1.38 KB
/
init.go
File metadata and controls
66 lines (57 loc) · 1.38 KB
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
package main
import (
tls_client "github.com/bogdanfinn/tls-client"
"github.com/bogdanfinn/tls-client/profiles"
"net/http"
"suno-api/common"
"time"
)
func InitService() {
common.InitTemplate()
initTlsHTTPClient()
if common.SessionID == "" {
panic("suno account session_id not set")
}
if common.COOKIE == "" {
panic("suno account cookie not set")
}
AccountInst = &Account{
Certificate: SunoCert{
SessionID: common.SessionID,
Cookie: common.COOKIE,
},
}
startTaskWorker()
common.SafeGoroutine(func() {
for {
time.Sleep(5 * time.Second)
err := startAllKeepAlive()
if err != nil {
common.Logger.Error("Suno Keep-alive failed: " + err.Error())
}
}
})
common.SafeGoroutine(func() { // recover task
recoverTasks()
})
}
var TlsHTTPClient tls_client.HttpClient
var HTTPClient *http.Client
func initTlsHTTPClient() {
jar := tls_client.NewCookieJar()
options := []tls_client.HttpClientOption{
tls_client.WithTimeoutSeconds(360),
tls_client.WithClientProfile(profiles.Chrome_120),
tls_client.WithNotFollowRedirects(),
tls_client.WithCookieJar(jar), // create cookieJar instance and pass it as argument
}
client, _ := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)
TlsHTTPClient = client
if common.Proxy != "" {
err := TlsHTTPClient.SetProxy(common.Proxy)
if err != nil {
panic(err)
}
}
HTTPClient = &http.Client{}
}