From 443067b80f691269e72cd3fee1caf712dd2e7e34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=87=89?= <927625802@qq.com> Date: Sat, 6 Mar 2021 23:19:16 +0800 Subject: [PATCH] =?UTF-8?q?:construction:=20=E5=AF=86=E7=A0=81=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/models/create.go | 18 +++++++++++++++--- test/string_test.go | 8 ++++++++ test/utils_test.go | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/server/models/create.go b/server/models/create.go index bb4083b7..8cc3219b 100644 --- a/server/models/create.go +++ b/server/models/create.go @@ -6,6 +6,7 @@ import ( "github.com/Xhofe/alist/conf" log "github.com/sirupsen/logrus" "gorm.io/gorm" + "strings" ) // build tree @@ -20,19 +21,29 @@ func BuildTree() error { if err := tx.Error; err != nil { return err } - if err := BuildOne(conf.Conf.AliDrive.RootFolder, "/root/", tx); err != nil { + if err := BuildOne(conf.Conf.AliDrive.RootFolder, "/root/", tx, ""); err != nil { tx.Rollback() return err } return tx.Commit().Error } -func BuildOne(parent string, path string, tx *gorm.DB) error { +func BuildOne(parent string, path string, tx *gorm.DB, parentPassword string) error { files, err := alidrive.GetList(parent, conf.Conf.AliDrive.MaxFilesCount, "", "", "") if err != nil { return err } for _, file := range files.Items { + name := file.Name + if strings.HasSuffix(name, ".hide") { + continue + } + password := parentPassword + if strings.Contains(name, ".password-") { + index := strings.Index(name, ".password-") + name = file.Name[:index] + password = file.Name[index+10:] + } newFile := File{ ParentPath: path, FileExtension: file.FileExtension, @@ -43,13 +54,14 @@ func BuildOne(parent string, path string, tx *gorm.DB) error { Category: file.Category, ContentType: file.ContentType, Size: file.Size, + Password: password, } log.Debugf("插入file:%+v", newFile) if err := tx.Create(&newFile).Error; err != nil { return err } if file.Type == "folder" { - if err := BuildOne(file.FileId, fmt.Sprintf("%s%s/", path, file.Name), tx); err != nil { + if err := BuildOne(file.FileId, fmt.Sprintf("%s%s/", path, file.Name), tx, password); err != nil { return err } } diff --git a/test/string_test.go b/test/string_test.go index d8da6562..6538ee15 100644 --- a/test/string_test.go +++ b/test/string_test.go @@ -11,3 +11,11 @@ func TestSplit(t *testing.T) { strs := strings.Split(drive_id, "/") fmt.Println(strs) } + +func TestPassword(t *testing.T) { + fullName:="hello.password-xhf" + index:=strings.Index(fullName,".password-") + name:=fullName[:index] + password:=fullName[index+10:] + fmt.Printf("name:%s, password:%s\n",name,password) +} \ No newline at end of file diff --git a/test/utils_test.go b/test/utils_test.go index 02bc67d7..56059585 100644 --- a/test/utils_test.go +++ b/test/utils_test.go @@ -16,3 +16,4 @@ func TestWriteYml(t *testing.T) { alidrive.RefreshToken() utils.WriteToYml("../conf.yml", conf.Conf) } +