mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-09 06:46:37 +08:00
优化
优化
This commit is contained in:
@@ -26,6 +26,13 @@ func TestNormalizeCloudPlayTarget(t *testing.T) {
|
|||||||
t.Fatalf("ref round-trip failed: %q", parsed.Query().Get("ref"))
|
t.Fatalf("ref round-trip failed: %q", parsed.Query().Get("ref"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
strmStale := "http://bwg.linkmy.fun:1314/api/strm/play/cloud115/video.mkv?acct=abc&pickcode=123"
|
||||||
|
gotStrm := normalizeCloudPlayTarget(strmStale)
|
||||||
|
wantStrm := "/api/strm/play/cloud115/video.mkv?acct=abc&pickcode=123"
|
||||||
|
if gotStrm != wantStrm {
|
||||||
|
t.Fatalf("normalizeCloudPlayTarget(strm) = %q, want %q", gotStrm, wantStrm)
|
||||||
|
}
|
||||||
|
|
||||||
// 非云盘播放 URL 保持原样(WebDAV/直链等)。
|
// 非云盘播放 URL 保持原样(WebDAV/直链等)。
|
||||||
passthrough := "https://dav.example.com/media/file.mkv"
|
passthrough := "https://dav.example.com/media/file.mkv"
|
||||||
if got := normalizeCloudPlayTarget(passthrough); got != passthrough {
|
if got := normalizeCloudPlayTarget(passthrough); got != passthrough {
|
||||||
|
|||||||
@@ -15,12 +15,23 @@ import (
|
|||||||
// /api/cloud/play 路径,由 absoluteInternalRedirect 基于「当前请求」补全
|
// /api/cloud/play 路径,由 absoluteInternalRedirect 基于「当前请求」补全
|
||||||
// host,从而对历史脏数据免疫。
|
// host,从而对历史脏数据免疫。
|
||||||
func normalizeCloudPlayTarget(raw string) string {
|
func normalizeCloudPlayTarget(raw string) string {
|
||||||
typ, ref, ok := parseCloudMediaPlaybackURL(raw)
|
raw = strings.TrimSpace(raw)
|
||||||
if !ok {
|
if raw == "" {
|
||||||
return raw
|
return raw
|
||||||
}
|
}
|
||||||
|
if typ, ref, ok := parseCloudMediaPlaybackURL(raw); ok {
|
||||||
return BuildRelativeCloudPlayURL(typ, ref)
|
return BuildRelativeCloudPlayURL(typ, ref)
|
||||||
}
|
}
|
||||||
|
if u, err := url.Parse(raw); err == nil {
|
||||||
|
path := strings.ToLower(u.Path)
|
||||||
|
if strings.HasPrefix(path, "/api/strm/play/") || strings.HasPrefix(path, "/api/cloud/play/") || strings.HasPrefix(path, "/api/stream/") {
|
||||||
|
u.Scheme = ""
|
||||||
|
u.Host = ""
|
||||||
|
return u.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return raw
|
||||||
|
}
|
||||||
|
|
||||||
// BuildRelativeCloudPlayURL 构造相对的云盘播放 API 路径。
|
// BuildRelativeCloudPlayURL 构造相对的云盘播放 API 路径。
|
||||||
func BuildRelativeCloudPlayURL(typ, ref string) string {
|
func BuildRelativeCloudPlayURL(typ, ref string) string {
|
||||||
|
|||||||
Reference in New Issue
Block a user