mirror of https://github.com/Xhofe/alist
🐛 change text proxy
parent
c0d1888e25
commit
c03646dedf
|
@ -5,6 +5,7 @@ import (
|
||||||
"github.com/Xhofe/alist/conf"
|
"github.com/Xhofe/alist/conf"
|
||||||
"github.com/Xhofe/alist/utils"
|
"github.com/Xhofe/alist/utils"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/go-resty/resty/v2"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -65,6 +66,10 @@ func Proxy(c *gin.Context) {
|
||||||
c.File(link)
|
c.File(link)
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
|
if utils.GetFileType(filepath.Ext(rawPath)) == conf.TEXT {
|
||||||
|
Text(c, link)
|
||||||
|
return
|
||||||
|
}
|
||||||
driver.Proxy(c)
|
driver.Proxy(c)
|
||||||
r := c.Request
|
r := c.Request
|
||||||
w := c.Writer
|
w := c.Writer
|
||||||
|
@ -84,3 +89,19 @@ func Proxy(c *gin.Context) {
|
||||||
proxy.ServeHTTP(w, r)
|
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())
|
||||||
|
}
|
||||||
|
|
|
@ -12,7 +12,11 @@ import (
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
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)
|
data, _ := ioutil.ReadAll(index)
|
||||||
conf.RawIndexHtml = string(data)
|
conf.RawIndexHtml = string(data)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue