Skip to content

Commit

Permalink
✨ 文件301直链与password文件隐藏
Browse files Browse the repository at this point in the history
  • Loading branch information
xhofe committed Dec 28, 2020
1 parent 4af469e commit bacbf7b
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion alidrive/resp_bean.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
}
}
Expand Down
14 changes: 14 additions & 0 deletions server/controllers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions server/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ func InitApiRouter(engine *gin.Engine) {
v2.POST("/list",List)
v2.POST("/search",Search)
}
engine.GET("/d/*file_id",Down)
}
9 changes: 8 additions & 1 deletion test/alidrive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
13 changes: 13 additions & 0 deletions test/string_test.go
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit bacbf7b

Please # to comment.