Skip to content

Commit 42fc841

Browse files
sevxn007jyxjjj
andauthored
feat(strm): custom path prefixes (#1697)
fix(strm): custom path prefixes Signed-off-by: ShenLin <773933146@qq.com> Co-authored-by: ShenLin <773933146@qq.com>
1 parent 4c0916b commit 42fc841

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

drivers/strm/driver.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (d *Strm) Init(ctx context.Context) error {
9696
}
9797
}
9898

99-
if d.Version != 4 {
99+
if d.Version != 5 {
100100
types := strings.Split("mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac", ",")
101101
for _, ext := range types {
102102
if _, ok := d.supportSuffix[ext]; !ok {
@@ -114,7 +114,8 @@ func (d *Strm) Init(ctx context.Context) error {
114114
}
115115
}
116116
d.DownloadFileTypes = strings.Join(downloadTypes, ",")
117-
d.Version = 4
117+
d.PathPrefix = "/d"
118+
d.Version = 5
118119
}
119120
return nil
120121
}

drivers/strm/meta.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
type Addition struct {
99
Paths string `json:"paths" required:"true" type:"text"`
1010
SiteUrl string `json:"siteUrl" type:"text" required:"false" help:"The prefix URL of the strm file"`
11+
PathPrefix string `json:"PathPrefix" type:"text" required:"false" default:"/d" help:"Path prefix"`
1112
DownloadFileTypes string `json:"downloadFileTypes" type:"text" default:"ass,srt,vtt,sub,strm" required:"false" help:"Files need to download with strm (usally subtitles)"`
1213
FilterFileTypes string `json:"filterFileTypes" type:"text" default:"mp4,mkv,flv,avi,wmv,ts,rmvb,webm,mp3,flac,aac,wav,ogg,m4a,wma,alac" required:"false" help:"Supports suffix name of strm file"`
1314
EncodePath bool `json:"encodePath" default:"true" required:"true" help:"encode the path in the strm file"`

drivers/strm/util.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ func (d *Strm) getLink(ctx context.Context, path string) string {
111111
signPath := sign.Sign(path)
112112
finalPath = fmt.Sprintf("%s?sign=%s", finalPath, signPath)
113113
}
114+
pathPrefix := d.PathPrefix
115+
if len(pathPrefix) > 0 {
116+
finalPath = stdpath.Join(pathPrefix, finalPath)
117+
}
118+
if !strings.HasPrefix(finalPath, "/") {
119+
finalPath = "/" + finalPath
120+
}
114121
if d.WithoutUrl {
115122
return finalPath
116123
}
@@ -120,10 +127,7 @@ func (d *Strm) getLink(ctx context.Context, path string) string {
120127
} else {
121128
apiUrl = common.GetApiUrl(ctx)
122129
}
123-
if !strings.HasPrefix(finalPath, "/") {
124-
finalPath = "/" + finalPath
125-
}
126-
return fmt.Sprintf("%s/d%s",
130+
return fmt.Sprintf("%s%s",
127131
apiUrl,
128132
finalPath)
129133
}

0 commit comments

Comments
 (0)