-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.go
128 lines (120 loc) · 3.07 KB
/
app.go
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package main
import (
"bufio"
"bytes"
"context"
"github.com/tidwall/gjson"
"github.com/wailsapp/wails/v2/pkg/runtime"
"io"
. "main/backend/src/init"
"net/http"
)
type App struct {
ctx context.Context
}
func NewApp() *App {
return &App{}
}
// startup is called when the app starts. The context is saved
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
}
func (a *App) DownloadByPid(text string) bool {
println(text)
Download_By_Pid(text)
return true
}
func (a *App) ReturnString() string {
return NowTaskMsg
}
func (a *App) Close(ctx context.Context) {
IsClosed = true
P.Wait()
defer func() {
P.Release()
TaskPool.Close()
SinglePool.Release()
}()
}
func (a *App) DownloadByAuthorId(text string) bool {
Download_By_Author(text, func(name string, data ...interface{}) {
runtime.EventsEmit(a.ctx, name, data)
})
return true
}
func (a *App) DownloadByRank(text, Type string) bool {
Download_By_Rank(text, Type, func(name string, data ...interface{}) {
runtime.EventsEmit(a.ctx, name, data)
})
return true
}
func (a *App) DownloadByFollowPage(page, Type string) bool {
Download_By_FollowPage(page, Type, func(name string, data ...interface{}) {
runtime.EventsEmit(a.ctx, name, data)
})
return true
}
func (a *App) PreloadRank(text, Type, page string) bool {
RankLoadingNow = true
DownloadRankMsg(text, Type, page, func(name string, data ...interface{}) {
runtime.EventsEmit(a.ctx, name, data)
})
return true
}
func (a *App) PreloadFollow(page, Type string) bool {
FollowLoadingNow = true
DownloadFollowMsg(page, Type, func(name string, data ...interface{}) {
runtime.EventsEmit(a.ctx, name, data)
})
return true
}
func (a *App) PopFollowPool() {
FollowLoadingNow = false
FollowLoadPool.Wait()
FollowLoadingNow = true
runtime.EventsEmit(a.ctx, "PopUp")
}
func (a *App) PopLoadPool() {
RankLoadingNow = false
RankloadPool.Wait()
RankLoadingNow = true
runtime.EventsEmit(a.ctx, "RankmsgPopUp")
}
func (a *App) CheckLogin() bool {
url, ref := CheckMode("", "", 0)
Request, err := http.NewRequest("GET", url, nil)
if err != nil {
DebugLog.Println("Error creating request", err)
runtime.EventsEmit(a.ctx, "login", "False")
return false
}
client := GetClient()
Request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36 Edg/120.0.0.0")
Request.Header.Set("referer", ref)
Cookie := &http.Cookie{
Name: "PHPSESSID",
Value: Setting.Cookie,
}
Request.AddCookie(Cookie)
Request.Header.Set("PHPSESSID", Setting.Cookie)
res, err := client.Do(Request)
if err != nil {
runtime.EventsEmit(a.ctx, "login", "False")
return false
}
var buffer bytes.Buffer
reader := bufio.NewReader(res.Body)
io.Copy(&buffer, reader)
data := buffer.Bytes()
Results := gjson.ParseBytes(data)
canbedownload := Results.Get("error").Bool()
println(canbedownload)
DebugLog.Println("Loading results:", canbedownload)
if canbedownload {
runtime.EventsEmit(a.ctx, "login", "False")
} else {
runtime.EventsEmit(a.ctx, "login", "True")
}
return true
}