perf: optimization

This commit is contained in:
putyy
2025-05-27 17:20:01 +08:00
parent f28cb69826
commit 5a92d7beb7
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() {

View File

@@ -98,7 +98,7 @@
"connections_tip": "Keep default if unsure, usually CPU cores * 2, for faster downloads",
"use_headers_tip": "Define headers for downloads, comma separated",
"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": {
"title": "About Us",

View File

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

View File

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