Skip to content

Commit b7673fe

Browse files
author
pikachuren
committed
feat(media): allow signing arbitrary media path for local player
1 parent 00ee7f5 commit b7673fe

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

‎server/handles/media_extra.go‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,53 @@ func GenerateMediaStrm(c *gin.Context) {
152152
common.SuccessResp(c, gin.H{"written": n, "path": opts.OutputPath})
153153
}
154154

155+
// GetMediaStreamURL 返回条目(或其中一集)的签名直链,供本地播放器/外链使用
156+
func GetMediaStreamURL(c *gin.Context) {
157+
// 直接按路径取签名链接(用于选集等场景)
158+
if rawPath := c.Query("path"); rawPath != "" {
159+
if !CanUserAccessPath(mediaUser(c), rawPath) {
160+
common.ErrorStrResp(c, "资源不存在", 404)
161+
return
162+
}
163+
common.SuccessResp(c, gin.H{
164+
"url": SignedStreamURL(c, rawPath),
165+
"path": rawPath,
166+
"name": stdpath.Base(rawPath),
167+
"proxied": SignedProxyURL(c, rawPath),
168+
})
169+
return
170+
}
171+
id, err := strconv.ParseUint(c.Query("id"), 10, 64)
172+
if err != nil {
173+
common.ErrorStrResp(c, "无效的ID", 400)
174+
return
175+
}
176+
item, err := db.GetMediaItemByID(uint(id))
177+
if err != nil || !CanUserAccessItem(mediaUser(c), item) {
178+
common.ErrorStrResp(c, "资源不存在", 404)
179+
return
180+
}
181+
episodeIndex, _ := strconv.Atoi(c.DefaultQuery("episode", "0"))
182+
rawPath := MediaItemFilePath(item)
183+
if episodeIndex > 0 {
184+
var eps []model.EpisodeInfo
185+
if err := json.Unmarshal([]byte(item.Episodes), &eps); err == nil {
186+
for i := range eps {
187+
if eps[i].Index == episodeIndex || i+1 == episodeIndex {
188+
rawPath = MediaEpisodeFilePath(item, &eps[i])
189+
break
190+
}
191+
}
192+
}
193+
}
194+
common.SuccessResp(c, gin.H{
195+
"url": SignedStreamURL(c, rawPath),
196+
"path": rawPath,
197+
"name": stdpath.Base(rawPath),
198+
"proxied": SignedProxyURL(c, rawPath),
199+
})
200+
}
201+
155202
// GetMediaStrm 动态生成单个条目的 .strm 内容(详情页下载)
156203
func GetMediaStrm(c *gin.Context) {
157204
id, err := strconv.ParseUint(c.Query("id"), 10, 64)

0 commit comments

Comments
 (0)