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

View File

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

View File

@@ -98,7 +98,7 @@
"connections_tip": "Keep default if unsure, usually CPU cores * 2, for faster downloads", "connections_tip": "Keep default if unsure, usually CPU cores * 2, for faster downloads",
"use_headers_tip": "Define headers for downloads, comma separated", "use_headers_tip": "Define headers for downloads, comma separated",
"mime_map": "Intercept Rules", "mime_map": "Intercept Rules",
"mime_map_tip": "JSON format, keep default if unsure" "mime_map_tip": "JSON format, keep default if unsure, please restart software after modification"
}, },
"footer": { "footer": {
"title": "About Us", "title": "About Us",

View File

@@ -83,7 +83,7 @@
"filename_rules": "文件命名", "filename_rules": "文件命名",
"filename_rules_tip": "输入框控制文件命名的长度(不含时间、0为无效此选项有描述信息时有效),开关控制文件末尾是否添加时间标识", "filename_rules_tip": "输入框控制文件命名的长度(不含时间、0为无效此选项有描述信息时有效),开关控制文件末尾是否添加时间标识",
"auto_proxy": "自动拦截", "auto_proxy": "自动拦截",
"auto_proxy_tip": "打开软件时动启用拦截", "auto_proxy_tip": "打开软件时动启用拦截",
"quality": "清晰度", "quality": "清晰度",
"quality_value": "默认(推荐),超清,高画质,中画质,低画质", "quality_value": "默认(推荐),超清,高画质,中画质,低画质",
"quality_tip": "视频号有效", "quality_tip": "视频号有效",
@@ -98,7 +98,7 @@
"connections_tip": "如不清楚请保持默认通常CPU核心数*2用于加速下载", "connections_tip": "如不清楚请保持默认通常CPU核心数*2用于加速下载",
"use_headers_tip": "定义下载时可使用的header参数逗号分割", "use_headers_tip": "定义下载时可使用的header参数逗号分割",
"mime_map": "拦截规则", "mime_map": "拦截规则",
"mime_map_tip": "json格式如果不清楚保持默认就行" "mime_map_tip": "json格式如果不清楚保持默认就行,修改后请重启软件"
}, },
"footer": { "footer": {
"title": "关于我们", "title": "关于我们",

View File

@@ -84,7 +84,7 @@ const classifyAlias: { [key: string]: any } = {
m3u8: computed(() => t("index.m3u8")), m3u8: computed(() => t("index.m3u8")),
live: computed(() => t("index.live")), live: computed(() => t("index.live")),
xls: computed(() => t("index.xls")), xls: computed(() => t("index.xls")),
doc: computed(() => t("index.pdf")), doc: computed(() => t("index.doc")),
pdf: computed(() => t("index.pdf")), pdf: computed(() => t("index.pdf")),
font: computed(() => t("index.font")) font: computed(() => t("index.font"))
} }