🐛 change text proxy

pull/548/head
微凉 2021-11-15 19:06:10 +08:00
parent c0d1888e25
commit c03646dedf
2 changed files with 26 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import (
"github.com/Xhofe/alist/conf"
"github.com/Xhofe/alist/utils"
"github.com/gin-gonic/gin"
"github.com/go-resty/resty/v2"
log "github.com/sirupsen/logrus"
"net/http/httputil"
"net/url"
@ -65,6 +66,10 @@ func Proxy(c *gin.Context) {
c.File(link)
return
} else {
if utils.GetFileType(filepath.Ext(rawPath)) == conf.TEXT {
Text(c, link)
return
}
driver.Proxy(c)
r := c.Request
w := c.Writer
@ -84,3 +89,19 @@ func Proxy(c *gin.Context) {
proxy.ServeHTTP(w, r)
}
}
var client *resty.Client
func init() {
client = resty.New()
client.SetRetryCount(3)
}
func Text(c *gin.Context, link string) {
res, err := client.R().Get(link)
if err != nil {
ErrorResp(c,err,500)
return
}
c.String(200,res.String())
}

View File

@ -12,7 +12,11 @@ import (
func init() {
index, _ := public.Public.Open("index.html")
index, err := public.Public.Open("index.html")
if err != nil {
log.Errorf(err.Error())
return
}
data, _ := ioutil.ReadAll(index)
conf.RawIndexHtml = string(data)
}