mirror of
https://github.com/putyy/res-downloader.git
synced 2026-01-12 06:04:55 +08:00
perf: intercept optimization
This commit is contained in:
@@ -122,13 +122,6 @@ func (p *QqPlugin) handleWechatRequest(r *http.Request, ctx *goproxy.ProxyCtx) (
|
||||
return r, p.buildEmptyResponse(r)
|
||||
}
|
||||
|
||||
isAll, _ := p.bridge.GetResType("all")
|
||||
isClassify, _ := p.bridge.GetResType("video")
|
||||
|
||||
if !isAll && !isClassify {
|
||||
return r, p.buildEmptyResponse(r)
|
||||
}
|
||||
|
||||
go p.handleMedia(body)
|
||||
|
||||
return r, p.buildEmptyResponse(r)
|
||||
@@ -188,6 +181,17 @@ func (p *QqPlugin) handleMedia(body []byte) {
|
||||
res.ContentType = "image/png"
|
||||
}
|
||||
|
||||
isAll, _ := p.bridge.GetResType("all")
|
||||
isImage, _ := p.bridge.GetResType("image")
|
||||
if res.Classify == "image" && !isImage && !isAll {
|
||||
return
|
||||
}
|
||||
|
||||
isVideo, _ := p.bridge.GetResType("video")
|
||||
if res.Classify == "video" && !isVideo && !isAll {
|
||||
return
|
||||
}
|
||||
|
||||
if urlToken, ok := firstMedia["urlToken"].(string); ok {
|
||||
res.Url += urlToken
|
||||
}
|
||||
|
||||
@@ -59,8 +59,8 @@ func (r *Resource) markMedia(key string) {
|
||||
|
||||
func (r *Resource) getResType(key string) (bool, bool) {
|
||||
r.resTypeMux.RLock()
|
||||
defer r.resTypeMux.RUnlock()
|
||||
value, ok := r.resType[key]
|
||||
r.resTypeMux.RUnlock()
|
||||
return value, ok
|
||||
}
|
||||
|
||||
@@ -233,10 +233,15 @@ func (r *Resource) decodeWxFile(fileName, decodeStr string) error {
|
||||
|
||||
byteCount := len(decodedBytes)
|
||||
fileBytes := make([]byte, byteCount)
|
||||
_, err = file.Read(fileBytes)
|
||||
n, err := file.Read(fileBytes)
|
||||
if err != nil && err != io.EOF {
|
||||
return err
|
||||
}
|
||||
|
||||
if n < byteCount {
|
||||
byteCount = n
|
||||
}
|
||||
|
||||
xorResult := make([]byte, byteCount)
|
||||
for i := 0; i < byteCount; i++ {
|
||||
xorResult[i] = decodedBytes[i] ^ fileBytes[i]
|
||||
|
||||
Reference in New Issue
Block a user