diff --git a/core/plugins/plugin.qq.com.go b/core/plugins/plugin.qq.com.go index 394fdd7..77e5c1a 100644 --- a/core/plugins/plugin.qq.com.go +++ b/core/plugins/plugin.qq.com.go @@ -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 } diff --git a/core/resource.go b/core/resource.go index 1ea24ec..cbe115a 100644 --- a/core/resource.go +++ b/core/resource.go @@ -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]