Opt: use http serve content to add content length and content type

pull/150/head
zijiren233 10 months ago
parent 2d9f0f2b93
commit 6e80940d9e

@ -15,6 +15,7 @@ import (
"path/filepath" "path/filepath"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
@ -919,7 +920,7 @@ func proxyVendorMovie(ctx *gin.Context, movie *op.Movie) {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err)) ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
return return
} }
ctx.Data(http.StatusOK, "text/plain; charset=utf-8", srtData) http.ServeContent(ctx.Writer, ctx.Request, id, time.Now(), bytes.NewReader(srtData))
return return
} else { } else {
log.Errorf("proxy vendor movie error: %v", "subtitle not found") log.Errorf("proxy vendor movie error: %v", "subtitle not found")
@ -970,13 +971,13 @@ func proxyVendorMovie(ctx *gin.Context, movie *op.Movie) {
ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("id out of range")) ctx.AbortWithStatusJSON(http.StatusBadRequest, model.NewApiErrorStringResp("id out of range"))
return return
} }
data, err := data.Subtitles[id].Cache.Get(ctx) b, err := data.Subtitles[id].Cache.Get(ctx)
if err != nil { if err != nil {
log.Errorf("proxy vendor movie error: %v", err) log.Errorf("proxy vendor movie error: %v", err)
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err)) ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
return return
} }
ctx.Data(http.StatusOK, "text/plain; charset=utf-8", data) http.ServeContent(ctx.Writer, ctx.Request, data.Subtitles[id].Name, time.Now(), bytes.NewReader(b))
} }
case cache.AlistProvider115: case cache.AlistProvider115:
@ -994,7 +995,6 @@ func proxyVendorMovie(ctx *gin.Context, movie *op.Movie) {
} }
} }
return return
case dbModel.VendorEmby: case dbModel.VendorEmby:
@ -1091,7 +1091,7 @@ func proxyVendorMovie(ctx *gin.Context, movie *op.Movie) {
ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err)) ctx.AbortWithStatusJSON(http.StatusInternalServerError, model.NewApiErrorResp(err))
return return
} }
ctx.Data(http.StatusOK, "text/plain; charset=utf-8", data) http.ServeContent(ctx.Writer, ctx.Request, embyC.Sources[source].Subtitles[id].Name, time.Now(), bytes.NewReader(data))
return return
} }

Loading…
Cancel
Save