diff --git a/alidrive/resp_bean.go b/alidrive/resp_bean.go index ae26517c77a..ea4fb3ac1c6 100644 --- a/alidrive/resp_bean.go +++ b/alidrive/resp_bean.go @@ -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:] } } diff --git a/server/controllers.go b/server/controllers.go index d3a1b819609..89a13e0f44c 100644 --- a/server/controllers.go +++ b/server/controllers.go @@ -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) { @@ -101,4 +102,17 @@ func Search(c *gin.Context) { return } 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 } \ No newline at end of file diff --git a/server/router.go b/server/router.go index da0031ae578..215d381980e 100644 --- a/server/router.go +++ b/server/router.go @@ -25,4 +25,5 @@ func InitApiRouter(engine *gin.Engine) { v2.POST("/list",List) v2.POST("/search",Search) } + engine.GET("/d/*file_id",Down) } \ No newline at end of file diff --git a/test/alidrive_test.go b/test/alidrive_test.go index 3c2b0ef86e2..64c1b29bffd 100644 --- a/test/alidrive_test.go +++ b/test/alidrive_test.go @@ -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() @@ -37,4 +38,10 @@ func TestGet(t *testing.T) { file,err:=alidrive.GetFile("5fb7c80e85e4f335cd344008be1b1b5349f74414") fmt.Println(err) fmt.Println(file) +} + +func TestMain(m *testing.M) { + setup() + code:=m.Run() + os.Exit(code) } \ No newline at end of file diff --git a/test/string_test.go b/test/string_test.go new file mode 100644 index 00000000000..26e50116dd3 --- /dev/null +++ b/test/string_test.go @@ -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) +} \ No newline at end of file