Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alist-org
GitHub Repository: alist-org/alist
Path: blob/main/cmd/user.go
1541 views
1
package cmd
2
3
import (
4
"crypto/tls"
5
"fmt"
6
"time"
7
8
"github.com/alist-org/alist/v3/internal/conf"
9
"github.com/alist-org/alist/v3/internal/op"
10
"github.com/alist-org/alist/v3/internal/setting"
11
"github.com/alist-org/alist/v3/pkg/utils"
12
"github.com/go-resty/resty/v2"
13
)
14
15
func DelAdminCacheOnline() {
16
admin, err := op.GetAdmin()
17
if err != nil {
18
utils.Log.Errorf("[del_admin_cache] get admin error: %+v", err)
19
return
20
}
21
DelUserCacheOnline(admin.Username)
22
}
23
24
func DelUserCacheOnline(username string) {
25
client := resty.New().SetTimeout(1 * time.Second).SetTLSClientConfig(&tls.Config{InsecureSkipVerify: conf.Conf.TlsInsecureSkipVerify})
26
token := setting.GetStr(conf.Token)
27
port := conf.Conf.Scheme.HttpPort
28
u := fmt.Sprintf("http://localhost:%d/api/admin/user/del_cache", port)
29
if port == -1 {
30
if conf.Conf.Scheme.HttpsPort == -1 {
31
utils.Log.Warnf("[del_user_cache] no open port")
32
return
33
}
34
u = fmt.Sprintf("https://localhost:%d/api/admin/user/del_cache", conf.Conf.Scheme.HttpsPort)
35
}
36
res, err := client.R().SetHeader("Authorization", token).SetQueryParam("username", username).Post(u)
37
if err != nil {
38
utils.Log.Warnf("[del_user_cache_online] failed: %+v", err)
39
return
40
}
41
if res.StatusCode() != 200 {
42
utils.Log.Warnf("[del_user_cache_online] failed: %+v", res.String())
43
return
44
}
45
code := utils.Json.Get(res.Body(), "code").ToInt()
46
msg := utils.Json.Get(res.Body(), "message").ToString()
47
if code != 200 {
48
utils.Log.Errorf("[del_user_cache_online] error: %s", msg)
49
return
50
}
51
utils.Log.Debugf("[del_user_cache_online] del user [%s] cache success", username)
52
}
53
54