代码提交
This commit is contained in:
@@ -35,39 +35,41 @@ type fileHandler func(ctx *gin.Context) (contentLength int64, contentType string
|
||||
|
||||
func Enkey(ctx *gin.Context) {
|
||||
fn := func(c *gin.Context) (contentLength int64, contentType string, reader io.Reader, extraHeaders map[string]string, err error) {
|
||||
idStr := c.Query("id")
|
||||
tStr := c.Query("t")
|
||||
ticket := c.Query("ticket")
|
||||
// 已取消 /enkey 的 ticket 校验,直接返回加密 key
|
||||
// idStr := c.Query("id")
|
||||
// tStr := c.Query("t")
|
||||
// ticket := c.Query("ticket")
|
||||
//
|
||||
// if idStr == "" || tStr == "" || ticket == "" {
|
||||
// err = errors.New("unauthorized")
|
||||
// return
|
||||
// }
|
||||
// videoId, parseErr := strconv.ParseInt(idStr, 10, 64)
|
||||
// if parseErr != nil {
|
||||
// err = errors.New("invalid id")
|
||||
// return
|
||||
// }
|
||||
// tVal, parseErr := strconv.ParseInt(tStr, 10, 64)
|
||||
// if parseErr != nil {
|
||||
// err = errors.New("invalid t")
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// ip := ipaddr.ResolveClientIP(c)
|
||||
// ticketInfo, ticketOK := CheckH5M3U8TicketForEnkey(videoId, tVal, ip, ticket)
|
||||
// if !ticketOK || ticketInfo.UseNewKey {
|
||||
// log.Warn("Enkey: ticket invalid", log.Any("ip", ip), log.Any("videoId", videoId))
|
||||
// err = errors.New("ticket check failed")
|
||||
// return
|
||||
// }
|
||||
// if ticketInfo.OfficialPlayletID > 0 && !officialChapterAllowed(c, ticketInfo.OfficialPlayletID, videoId) {
|
||||
// err = errors.New("本集暂未在官网开放")
|
||||
// return
|
||||
// }
|
||||
|
||||
if idStr == "" || tStr == "" || ticket == "" {
|
||||
err = errors.New("unauthorized")
|
||||
return
|
||||
}
|
||||
videoId, parseErr := strconv.ParseInt(idStr, 10, 64)
|
||||
if parseErr != nil {
|
||||
err = errors.New("invalid id")
|
||||
return
|
||||
}
|
||||
tVal, parseErr := strconv.ParseInt(tStr, 10, 64)
|
||||
if parseErr != nil {
|
||||
err = errors.New("invalid t")
|
||||
return
|
||||
}
|
||||
|
||||
ip := ipaddr.ResolveClientIP(c)
|
||||
ticketInfo, ticketOK := CheckH5M3U8TicketForEnkey(videoId, tVal, ip, ticket)
|
||||
if !ticketOK || ticketInfo.UseNewKey {
|
||||
log.Warn("Enkey: ticket invalid", log.Any("ip", ip), log.Any("videoId", videoId))
|
||||
err = errors.New("ticket check failed")
|
||||
return
|
||||
}
|
||||
if ticketInfo.OfficialPlayletID > 0 && !officialChapterAllowed(c, ticketInfo.OfficialPlayletID, videoId) {
|
||||
err = errors.New("本集暂未在官网开放")
|
||||
return
|
||||
}
|
||||
|
||||
buffer, err := m3u8.Enkey(c)
|
||||
if err != nil {
|
||||
buffer, bErr := m3u8.Enkey(c)
|
||||
if bErr != nil {
|
||||
err = bErr
|
||||
return
|
||||
}
|
||||
contentLength = int64(buffer.Len())
|
||||
|
||||
Reference in New Issue
Block a user