文件301直链与password文件隐藏

This commit is contained in:
微凉
2020-12-28 10:23:54 +08:00
parent 4af469efed
commit bacbf7bc1b
5 changed files with 38 additions and 2 deletions

View File

@ -106,8 +106,9 @@ type TokenResp struct {
func HasPassword(files *Files) string {
fileList := files.Items
for _, file := range fileList {
for i, file := range fileList {
if strings.HasPrefix(file.Name, ".password-") {
files.Items=fileList[:i+copy(fileList[i:],fileList[i+1:])]
return file.Name[10:]
}
}

View File

@ -5,6 +5,7 @@ import (
"github.com/Xhofe/alist/conf"
"github.com/gin-gonic/gin"
log "github.com/sirupsen/logrus"
"strings"
)
func Info(c *gin.Context) {
@ -102,3 +103,16 @@ func Search(c *gin.Context) {
}
c.JSON(200,dataResponse(files))
}
func Down(c *gin.Context) {
fileIdParam:=c.Param("file_id")
log.Debugf("down:%s",fileIdParam)
fileId:=strings.Split(fileIdParam,"/")[1]
file,err:=alidrive.GetFile(fileId)
if err != nil {
c.JSON(200,metaResponse(500,err.Error()))
return
}
c.Redirect(301,file.DownloadUrl)
return
}

View File

@ -25,4 +25,5 @@ func InitApiRouter(engine *gin.Engine) {
v2.POST("/list",List)
v2.POST("/search",Search)
}
engine.GET("/d/*file_id",Down)
}

View File

@ -5,10 +5,11 @@ import (
"github.com/Xhofe/alist/alidrive"
"github.com/Xhofe/alist/bootstrap"
"github.com/Xhofe/alist/conf"
"os"
"testing"
)
func init() {
func setup() {
bootstrap.InitLog()
bootstrap.ReadConf("../conf.yml")
bootstrap.InitClient()
@ -38,3 +39,9 @@ func TestGet(t *testing.T) {
fmt.Println(err)
fmt.Println(file)
}
func TestMain(m *testing.M) {
setup()
code:=m.Run()
os.Exit(code)
}

13
test/string_test.go Normal file
View File

@ -0,0 +1,13 @@
package test
import (
"fmt"
"strings"
"testing"
)
func TestSplit(t *testing.T) {
drive_id:="/123/456"
strs:=strings.Split(drive_id,"/")
fmt.Println(strs)
}