mirror of
https://github.com/putyy/res-downloader.git
synced 2026-01-12 06:04:55 +08:00
perf: optimization type support
This commit is contained in:
@@ -161,6 +161,7 @@ func getDefaultMimeMap() map[string]MimeInfo {
|
||||
"application/vnd.apple.mpegurl": {Type: "m3u8", Suffix: ".m3u8"},
|
||||
"application/x-mpegurl": {Type: "m3u8", Suffix: ".m3u8"},
|
||||
"application/x-mpeg": {Type: "m3u8", Suffix: ".m3u8"},
|
||||
"audio/x-mpegurl": {Type: "m3u8", Suffix: ".m3u8"},
|
||||
"application/pdf": {Type: "pdf", Suffix: ".pdf"},
|
||||
"application/vnd.ms-powerpoint": {Type: "ppt", Suffix: ".ppt"},
|
||||
"application/vnd.openxmlformats-officedocument.presentationml.presentation": {Type: "ppt", Suffix: ".pptx"},
|
||||
@@ -172,7 +173,8 @@ func getDefaultMimeMap() map[string]MimeInfo {
|
||||
"text/rtf": {Type: "doc", Suffix: ".rtf"},
|
||||
"application/vnd.oasis.opendocument.text": {Type: "doc", Suffix: ".odt"},
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": {Type: "doc", Suffix: ".docx"},
|
||||
"font/woff": {Type: "font", Suffix: ".woff"},
|
||||
"font/woff": {Type: "font", Suffix: ".woff"},
|
||||
"application/octet-stream": {Type: "stream", Suffix: "default"},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,10 @@ import (
|
||||
"github.com/elazarl/goproxy"
|
||||
gonanoid "github.com/matoous/go-nanoid/v2"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"res-downloader/core/shared"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type DefaultPlugin struct {
|
||||
@@ -26,7 +28,7 @@ func (p *DefaultPlugin) OnRequest(r *http.Request, ctx *goproxy.ProxyCtx) (*http
|
||||
}
|
||||
|
||||
func (p *DefaultPlugin) OnResponse(resp *http.Response, ctx *goproxy.ProxyCtx) *http.Response {
|
||||
if resp == nil || resp.Request == nil || (resp.StatusCode != 200 && resp.StatusCode != 206) {
|
||||
if resp == nil || resp.Request == nil || (resp.StatusCode != 200 && resp.StatusCode != 206 && resp.StatusCode != 304) {
|
||||
return resp
|
||||
}
|
||||
|
||||
@@ -39,6 +41,13 @@ func (p *DefaultPlugin) OnResponse(resp *http.Response, ctx *goproxy.ProxyCtx) *
|
||||
isAll, _ := p.bridge.GetResType("all")
|
||||
isClassify, _ := p.bridge.GetResType(classify)
|
||||
|
||||
if suffix == "default" {
|
||||
ext := filepath.Ext(filepath.Base(strings.Split(strings.Split(rawUrl, "?")[0], "#")[0]))
|
||||
if ext != "" {
|
||||
suffix = ext
|
||||
}
|
||||
}
|
||||
|
||||
urlSign := shared.Md5(rawUrl)
|
||||
if ok := p.bridge.MediaIsMarked(urlSign); !ok && (isAll || isClassify) {
|
||||
value, _ := strconv.ParseFloat(resp.Header.Get("content-length"), 64)
|
||||
|
||||
Reference in New Issue
Block a user