panic(e)
}
+ var (
+ readTimeout = 3
+ readHeaderTimeout = 3
+ idleTimeout = 3
+ )
+
+ if v, ok := t.K_v.LoadV("Web服务超时配置").(map[string]any); ok {
+ if v1, ok := v["ReadTimeout"].(float64); ok && v1 > 3 {
+ readTimeout = int(v1)
+ }
+ if v1, ok := v["ReadHeaderTimeout"].(float64); ok && v1 > 3 {
+ readHeaderTimeout = int(v1)
+ }
+ if v1, ok := v["IdleTimeout"].(float64); ok && v1 > 3 {
+ idleTimeout = int(v1)
+ }
+ }
+
web.NewSyncMap(&http.Server{
- Addr: serUrl.Host,
+ Addr: serUrl.Host,
+ ReadTimeout: time.Duration(int(time.Second) * readTimeout),
+ ReadHeaderTimeout: time.Duration(int(time.Second) * readHeaderTimeout),
+ IdleTimeout: time.Duration(int(time.Second) * idleTimeout),
}, t.SerF)
if limits, ok := t.K_v.LoadV(`Web服务连接限制`).([]any); ok {
if val, ok := t.K_v.LoadV("性能路径").(string); ok && val != "" {
var cache web.Cache
t.SerF.Store(val, func(w http.ResponseWriter, r *http.Request) {
- //limit
- if t.SerLimit.AddCount(r) {
- web.WithStatusCode(w, http.StatusTooManyRequests)
+ if DefaultHttpCheck(t, w, r, http.MethodGet) {
return
}
_, _ = w.Write(data)
return data
}
+
+func DefaultHttpCheck(c *Common, w http.ResponseWriter, r *http.Request, method ...string) bool {
+ //method
+ if !web.IsMethod(r, method...) {
+ web.WithStatusCode(w, http.StatusMethodNotAllowed)
+ return true
+ }
+ //limit
+ if c.SerLimit.AddCount(r) {
+ web.WithStatusCode(w, http.StatusTooManyRequests)
+ return true
+ }
+ return false
+}
limit "github.com/qydysky/part/limit"
reqf "github.com/qydysky/part/reqf"
psync "github.com/qydysky/part/sync"
- web "github.com/qydysky/part/web"
"github.com/mdp/qrterminal/v3"
qr "github.com/skip2/go-qrcode"
}
// 扫码登录
-func (c *GetFunc) Get_cookie() (missKey []string) {
+func (t *GetFunc) Get_cookie() (missKey []string) {
apilog := apilog.Base_add(`获取Cookie`)
//获取其他Cookie
- defer c.Get_other_cookie()
+ defer t.Get_other_cookie()
if p.Checkfile().IsExist("cookie.txt") { //读取cookie文件
if cookieString := string(CookieGet()); cookieString != `` {
for k, v := range reqf.Cookies_String_2_Map(cookieString) { //cookie存入全局变量syncmap
- c.Cookie.Store(k, v)
+ t.Cookie.Store(k, v)
}
if miss := CookieCheck([]string{
`bili_jct`,
`DedeUserID`,
}); len(miss) == 0 {
- if v, e := c.GetNav(); e != nil {
+ if v, e := t.GetNav(); e != nil {
apilog.L(`E: `, e)
} else if v.Data.IsLogin {
apilog.L(`I: `, `已登录`)
}
}
- if v, ok := c.K_v.LoadV(`扫码登录`).(bool); !ok || !v {
+ if v, ok := t.K_v.LoadV(`扫码登录`).(bool); !ok || !v {
apilog.L(`W: `, `配置文件已禁止扫码登录,如需登录,修改配置文件"扫码登录"为true`)
return
}
var img_url string
var oauth string
{ //获取二维码
- r := c.ReqPool.Get()
- defer c.ReqPool.Put(r)
+ r := t.ReqPool.Get()
+ defer t.ReqPool.Put(r)
if e := r.Reqf(reqf.Rval{
Url: `https://passport.bilibili.com/qrcode/getLoginUrl`,
- Proxy: c.Proxy,
+ Proxy: t.Proxy,
Timeout: 10 * 1000,
Retry: 2,
}); e != nil {
}
defer os.RemoveAll(`qr.png`)
//启动web
- if scanPath, ok := c.K_v.LoadV("扫码登录路径").(string); ok && scanPath != "" {
- c.SerF.Store(scanPath, func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.SerLimit.AddCount(r) {
- web.WithStatusCode(w, http.StatusTooManyRequests)
+ if scanPath, ok := t.K_v.LoadV("扫码登录路径").(string); ok && scanPath != "" {
+ t.SerF.Store(scanPath, func(w http.ResponseWriter, r *http.Request) {
+ if c.DefaultHttpCheck(t.Common, w, r, http.MethodGet) {
return
}
_ = file.New("qr.png", 0, true).CopyToIoWriter(w, humanize.MByte, true)
})
- if c.K_v.LoadV(`扫码登录自动打开标签页`).(bool) {
- _ = open.Run(`http://127.0.0.1:` + c.Stream_url.Port() + scanPath)
+ if t.K_v.LoadV(`扫码登录自动打开标签页`).(bool) {
+ _ = open.Run(`http://127.0.0.1:` + t.Stream_url.Port() + scanPath)
}
- apilog.L(`W: `, `或打开链接扫码登录:`+c.Stream_url.String()+scanPath)
+ apilog.L(`W: `, `或打开链接扫码登录:`+t.Stream_url.String()+scanPath)
}
apilog.Block(1000)
{ //循环查看是否通过
Cookie := make(map[string]string)
- c.Cookie.Range(func(k, v interface{}) bool {
+ t.Cookie.Range(func(k, v interface{}) bool {
Cookie[k.(string)] = v.(string)
return true
})
return
}
- r := c.ReqPool.Get()
- defer c.ReqPool.Put(r)
+ r := t.ReqPool.Get()
+ defer t.ReqPool.Put(r)
if e := r.Reqf(reqf.Rval{
Url: `https://passport.bilibili.com/qrcode/getLoginInfo`,
PostStr: `oauthKey=` + oauth,
`Referer`: `https://passport.bilibili.com/login`,
`Cookie`: reqf.Map_2_Cookies_String(Cookie),
},
- Proxy: c.Proxy,
+ Proxy: t.Proxy,
Timeout: 10 * 1000,
Retry: 2,
}); e != nil {
// debug模式
if de, ok := c.C.K_v.LoadV(`debug模式`).(bool); ok && de {
c.C.SerF.Store("/debug/pprof/", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
pprof.Index(w, r)
})
c.C.SerF.Store("/debug/pprof/cmdline", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
pprof.Cmdline(w, r)
})
c.C.SerF.Store("/debug/pprof/profile", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
pprof.Profile(w, r)
})
c.C.SerF.Store("/debug/pprof/symbol", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
pprof.Symbol(w, r)
})
c.C.SerF.Store("/debug/pprof/trace", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
pprof.Trace(w, r)
// 直播流主页
c.C.SerF.Store(path, func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
// 直播流文件列表api
c.C.SerF.Store(path+"filePath", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
// 直播流播放器
c.C.SerF.Store(path+"player/", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
// 流地址
c.C.SerF.Store(path+"stream", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
// 弹幕回放
c.C.SerF.Store(path+"player/ws", func(w http.ResponseWriter, r *http.Request) {
- //limit
- if c.C.SerLimit.AddCount(r) {
- pweb.WithStatusCode(w, http.StatusTooManyRequests)
+ if c.DefaultHttpCheck(c.C, w, r, http.MethodGet) {
return
}
"max":-1
}
],
+ "Web服务超时配置-help":"单位秒,最小值3",
+ "Web服务超时配置": {
+ "ReadTimeout":3,
+ "ReadHeaderTimeout":3,
+ "IdleTimeout":3
+ },
"直播Web服务路径":"/web/",
"直播Web可以发送弹幕":true,
"弹幕回放-help": "仅保存当前直播间流为true时才有效",
require (
github.com/gotk3/gotk3 v0.6.2
github.com/mdp/qrterminal/v3 v3.0.0
- github.com/qydysky/part v0.27.17
+ github.com/qydysky/part v0.28.1-0.20230529171227-d4a6f98e0263
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966
golang.org/x/text v0.9.0
github.com/miekg/dns v1.1.54 h1:5jon9mWcb0sFJGpnI99tOMhCPyJ+RPVz5b63MQG0VWI=
github.com/miekg/dns v1.1.54/go.mod h1:uInx36IzPl7FYnDcMeVWxj9byh7DutNykX4G9Sj60FY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/qydysky/part v0.27.17 h1:hYSOjnkV0jIf/tSLBmqEAXfkprEhwySQrVWRtrZxuXE=
-github.com/qydysky/part v0.27.17/go.mod h1:IEMpGB0NBl6MklZmoenSpS5ChhaIL79JYFo6mF1UkAU=
+github.com/qydysky/part v0.28.1-0.20230529171227-d4a6f98e0263 h1:kkumZFaAahNhSFjeY1VCihzG/DOATDtXLAyhsh9R2AE=
+github.com/qydysky/part v0.28.1-0.20230529171227-d4a6f98e0263/go.mod h1:IEMpGB0NBl6MklZmoenSpS5ChhaIL79JYFo6mF1UkAU=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=