perf: optimization

This commit is contained in:
putyy
2025-05-27 17:20:01 +08:00
committed by putyy
parent bd2fa75cde
commit 7f3d63532c
5 changed files with 31 additions and 31 deletions

View File

@@ -14,6 +14,9 @@ import (
"strings"
)
var qqMediaRegex = regexp.MustCompile(`get\s*media\(\)\{`)
var qqCommentRegex = regexp.MustCompile(`async\s*finderGetCommentDetail\((\w+)\)\s*\{return(.*?)\s*}\s*async`)
type QqPlugin struct {
bridge *shared.Bridge
}
@@ -72,7 +75,7 @@ func (p *QqPlugin) OnResponse(resp *http.Response, ctx *goproxy.ProxyCtx) *http.
return respTemp
}
bodyStr := string(body)
newBody := regexp.MustCompile(`get\s*media\(\)\{`).
newBody := qqMediaRegex.
ReplaceAllString(bodyStr, `
get media(){
if(this.objectDesc){
@@ -85,7 +88,7 @@ func (p *QqPlugin) OnResponse(resp *http.Response, ctx *goproxy.ProxyCtx) *http.
`)
newBody = regexp.MustCompile(`async\s*finderGetCommentDetail\((\w+)\)\s*\{return(.*?)\s*}\s*async`).
newBody = qqCommentRegex.
ReplaceAllString(newBody, `
async finderGetCommentDetail($1) {
var res = await$2;

View File

@@ -28,23 +28,26 @@ type Resource struct {
func initResource() *Resource {
if resourceOnce == nil {
resourceOnce = &Resource{
resType: map[string]bool{
"all": true,
"image": true,
"audio": true,
"video": true,
"m3u8": true,
"live": true,
"xls": true,
"doc": true,
"pdf": true,
},
}
resourceOnce = &Resource{}
resourceOnce.resType = resourceOnce.buildResType(globalConfig.MimeMap)
}
return resourceOnce
}
func (r *Resource) buildResType(mime map[string]MimeInfo) map[string]bool {
t := map[string]bool{
"all": true,
}
for _, item := range mime {
if _, ok := t[item.Type]; !ok {
t[item.Type] = true
}
}
return t
}
func (r *Resource) mediaIsMarked(key string) bool {
_, loaded := r.mediaMark.Load(key)
return loaded
@@ -63,22 +66,16 @@ func (r *Resource) getResType(key string) (bool, bool) {
func (r *Resource) setResType(n []string) {
r.resTypeMux.Lock()
defer r.resTypeMux.Unlock()
r.resType = map[string]bool{
"all": false,
"image": false,
"audio": false,
"video": false,
"m3u8": false,
"live": false,
"xls": false,
"doc": false,
"pdf": false,
for key := range r.resType {
r.resType[key] = false
}
for _, value := range n {
r.resType[value] = true
if _, ok := r.resType[value]; ok {
r.resType[value] = true
}
}
r.resTypeMux.Unlock()
}
func (r *Resource) clear() {